Pewarta Proxy

📋 Server Request & Proxy Logs

Loading active proxy settings...
Developed by Khairul Adha (adhexa.id)
Mengambil log server...

⚙️ Pengaturan Proxy Target

Skip to content

fix: parse a bracketed operand at the start of a PARTITION BY list - #2878

Merged
manticore-projects merged 1 commit into
JSQLParser:masterfrom
knutwannheden:fix/partition-by-bracketed-operand
Oct 31, 2026
Merged

manticore-projects merged 1 commit into
JSQLParser:masterfrom
knutwannheden:fix/partition-by-bracketed-operand

Conversation

@knutwannheden

Copy link
Copy Markdown
Contributor

SELECT SUM(x) OVER (PARTITION BY (1 + a) / 2) FROM t does not parse on master: a ParseException at the /. Any window partition, named window, WITHIN GROUP … OVER or Exasol PREFERRING … PARTITION BY whose first expression begins with a bracketed operand of a larger expression fails the same way.

ParseException: Encountered: <OP_SLASH> / "/", at line 1, column 42, in lexical state DEFAULT.
Was expecting one of these terminals within expansion starting at 14762:5:
    <K_GROUPS> (inside 14756:5) ...
    <K_RANGE> (inside 14756:5) ...
    <K_ROWS> (inside 14756:5) ...
    <K_ORDER> (inside 14755:5) ...

Each of the four PARTITION BY sites chose between LOOKAHEAD(3) ComplexExpressionList() and "(" ComplexExpressionList() ")". The probe scans into Expression(), whose binary operators live in a Java loop the scan cannot see, so on ( 1 + it fails at the +. The bracketed alternative then wins, parses (1 + a) as the whole list, and meets / where only ORDER BY, a window frame or ) may follow.

ca2b3d7 removed the same probe shape from ExpressionList() for the same reason.

The bracketed alternative has no observable effect on anything that parses today. PARTITION BY (a, b) passes the probe, so the complex alternative wins and the list holds one ParenthesedExpressionList, which prints its own parentheses. The alternative could only win when the probe failed, and in every such case the parse then failed too.

All four sites now call ComplexExpressionList() directly, and the partitionByBrackets locals are gone. PartitionByClause.isBrackets() stays as it is; callers can still set it.

AnalyticExpressionTest.testPartitionByBracketedOperand fails on master and passes here. Its cases cover the OVER (…), named WINDOW, WITHIN GROUP … OVER and PREFERRING sites, plus PARTITION BY (a, b), c, which pins that a leading ( alone must not select a bracketed list.

`SELECT SUM(x) OVER (PARTITION BY (1 + a) / 2) FROM t` failed with a
ParseException at the `/`. The four PARTITION BY sites chose between
`LOOKAHEAD(3) ComplexExpressionList()` and a bracketed list
`"(" ComplexExpressionList() ")"`. The probe scans into `Expression()`,
whose binary operators live in a Java loop the scan cannot see, so it
failed on `( 1 +`, the bracketed alternative won, parsed `(1 + a)` as the
whole list and then met `/`.

The bracketed alternative only won when the probe failed, and the parse
then failed too, so dropping it changes nothing that parsed before. All
four sites now call `ComplexExpressionList()` directly.
@manticore-projects
manticore-projects merged commit 9703ff4 into JSQLParser:master Oct 31, 2026
10 checks passed
@manticore-projects

Copy link
Copy Markdown
Contributor

Thank you much!

knutwannheden added a commit to knutwannheden/JSqlParser that referenced this pull request Oct 31, 2026
Conflicts in JSqlParserCC.jjt, resolved by keeping master's logic and
re-adding the node links on top:

- PARTITION BY (JSQLParser#2878): the four sites call ComplexExpressionList()
  directly and still link the PARTITION BY node.
- PrimaryExpression (JSQLParser#2874): innerSigns is null without an inner sign,
  so the loop that wraps and links signed values is guarded.
- Condition (JSQLParser#2874): one lazily created deque of NOT tokens carries both
  the token for the node and whether it was spelled "!".
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.

2 participants