Repository navigation
fix: parse a bracketed operand at the start of a PARTITION BY list - #2878
Merged
manticore-projects merged 1 commit intoOct 31, 2026
Conversation
`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.
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 "!".
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SELECT SUM(x) OVER (PARTITION BY (1 + a) / 2) FROM tdoes not parse on master: aParseExceptionat the/. Any window partition, named window,WITHIN GROUP … OVERor ExasolPREFERRING … PARTITION BYwhose first expression begins with a bracketed operand of a larger expression fails the same way.Each of the four
PARTITION BYsites chose betweenLOOKAHEAD(3) ComplexExpressionList()and"(" ComplexExpressionList() ")". The probe scans intoExpression(), 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 onlyORDER 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 oneParenthesedExpressionList, 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 thepartitionByBracketslocals are gone.PartitionByClause.isBrackets()stays as it is; callers can still set it.AnalyticExpressionTest.testPartitionByBracketedOperandfails on master and passes here. Its cases cover theOVER (…), namedWINDOW,WITHIN GROUP … OVERandPREFERRINGsites, plusPARTITION BY (a, b), c, which pins that a leading(alone must not select a bracketed list.