Repository navigation
Parse a parenthesed LATERAL FROM item - #2887
Open
edeadington wants to merge 1 commit into
Open
edeadington wants to merge 1 commit into
edeadington wants to merge 1 commit into
Conversation
isParenthesedFromItemAhead() declines ParenthesedFromItem when the token
after "(" is LATERAL, on the basis that LateralSubSelect handles it.
LateralSubSelect begins at <K_LATERAL>, so it can never match input that
begins at "(", and no later alternative accepts it either. Every
parenthesed LATERAL item therefore fails at the opening parenthesis with
"Encountered: <OPENING_BRACKET>".
Remove the guard so ParenthesedFromItem is tried, as it was before
2d2ee4b replaced the syntactic LOOKAHEAD(ParenthesedFromItem()) with
this two-token predicate.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
edeadington
marked this pull request as ready for review
November 2, 2026 14:26
This branch has not been deployed
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.
Current problem
A
LATERALFROM item no longer parses when it is wrapped in parentheses:It is the parenthesis that fails rather than anything inside it, so this is not specific to Snowflake's
FLATTEN—(LATERAL (SELECT 1 FROM b)) ffails at the same position. UnparenthesedLATERALis unaffected, as are other parenthesed FROM items such as(a JOIN b ON a.id = b.id)and(SELECT 1 FROM b) x.FromItem()reachesParenthesedFromItem()throughLOOKAHEAD({ isParenthesedFromItemAhead() }), and that predicate declines whenever the token after(isLATERAL. No other alternative accepts the input, so the parse fails at the opening parenthesis.When it was introduced
In 5.4. 2d2ee4b replaced the syntactic
LOOKAHEAD(ParenthesedFromItem())with this two-token predicate as part of the lookahead performance work. The syntactic lookahead attempted the parse and succeeded; the predicate has to decide from two tokens, and decides wrongly here. 5.0 through 5.3 parse all of the above.The comment's premise does not hold. Its single alternative begins at
K_LATERAL, so it can never match input beginning at(— it cannot be the handler the comment defers to. It is also the only branch of the predicate naming a rule that cannot start with(:ParenthesedSelect, the( TABLE ... )query form andSubImportall genuinely do, so those lines stay as they are.With the line removed,
ParenthesedFromItem()is tried, consumes the(, and the innerLATERALitem is parsed by the ordinaryFromItem()recursion — which is whereLateralSubSelectdoes apply. That is the pre-5.4 behaviour.testParenthesedLateralFlatandtestParenthesedLateralcover the table-function and subselect forms, both round-tripped through the deparser. The full suite passes and JavaCC reports the same warning count as master.