Skip to content

Fix Presto LOG(b, x) argument order on round-trip [CLAUDE]#7905

Closed
chuenchen309 wants to merge 1 commit into
tobymao:mainfrom
chuenchen309:fix/presto-log-base-order
Closed

Fix Presto LOG(b, x) argument order on round-trip [CLAUDE]#7905
chuenchen309 wants to merge 1 commit into
tobymao:mainfrom
chuenchen309:fix/presto-log-base-order

Conversation

@chuenchen309

Copy link
Copy Markdown
Contributor

Presto's LOG(b, x) is the logarithm of x to base b, but round-tripping it through the Presto dialect silently swaps the two arguments: LOG(3, 9) (log base 3 of 9, = 2) comes back out as LOG(9, 3) (= 0.5). The SQL still looks valid, so the wrong value is easy to miss.

The cause is an inconsistency around the tri-state LOG_BASE_FIRST flag. Presto leaves it None; the parser treated None as falsy and swapped the arguments, while the generator only swaps when the flag is explicitly False. Changing the parser's check to is False matches the generator, so None dialects no longer swap. Base-first (True) and value-first (False) dialects are unaffected, and LOG2/LOG10 still transpile as before.

Verified against the full unit suite (1243 tests pass) and added a Presto round-trip test that fails without the change.

Disclosure: this change was found, fixed, tested and described by an AI agent (Claude Code) running on this account. The account holder reviews every change and is accountable for it.

Presto's LOG(b, x) is log base b of x, but round-tripping through the Presto
dialect swapped the two arguments, turning LOG(3, 9) into LOG(9, 3). The parser
treated a None LOG_BASE_FIRST as falsy and swapped, while the generator only
swaps when the flag is explicitly False; aligning the parser to `is False`
fixes it and leaves base-first (True) and value-first (False) dialects unchanged.

Co-authored-by AI: Claude (Claude Code). [CLAUDE]
Comment on lines +719 to +720
self.validate_identity("SELECT LOG(x, y)")
self.validate_identity("SELECT LOG(3, 9)")

@geooo109 geooo109 Jul 20, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is invalid in presto:

presto> SELECT LOG(2,8);

Query 20260720_104252_00010_i6tgb, FAILED, 0 nodes
Splits: 0 total, 0 done (0.00%)
[Latency: client-side: 16ms, server-side: 2ms] [0 rows, 0B] [0 rows/s, 0B/s]

Query 20260720_104252_00010_i6tgb failed: line 1:8: Function log not registered
SELECT LOG(2,8)

In trino (it's supported + the roundtrip is correct):

INPUT:
SELECT LOG(b, x)

AST:
Select(
  expressions=[
    Log(
      this=Column(
        this=Identifier(this=b, quoted=False)),
      expression=Column(
        this=Identifier(this=x, quoted=False)))])
SELECT LOG(b, x)

On the engine (trino):
trino> SELECT LOG(2,8);
 _col0 
-------
   3.0 
(1 row)

Query 20260720_104653_00001_q59b3, FINISHED, 1 node
Splits: 1 total, 1 done (100.00%)
0.13 [0 rows, 0B] [0 rows/s, 0B/s]

@geooo109 geooo109 closed this Jul 20, 2026
@georgesittas

Copy link
Copy Markdown
Collaborator

Assuming garbage in -> garbage out, this PR changes nothing:

  1. The branch in build_logarithm only runs when a 2-arg LOG is parsed in a LOG_BASE_FIRST = None dialect.
  2. The only None dialects are Presto and ClickHouse, and both engines reject 2-arg LOG

Therefore, every input whose behavior the PR changes is garbage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants