Disambiguate SETTINGS placement around paren-wrapped set-op legs#3
Merged
Conversation
Track paren-wrapping on SelectQuery directly so the four placements of SETTINGS around a paren-bounded set-op leg become distinct, round-trippable AST shapes. SELECT 1 UNION ALL (SELECT 2 SETTINGS x=1) (per-leg) and SELECT 1 UNION ALL (SELECT 2) SETTINGS x=1 (chain-level on the leg) previously collapsed to byte-identical ASTs; chain-level SETTINGS on a paren-wrapped chain (e.g. (SELECT 1 UNION ALL SELECT 2) SETTINGS x=1) failed to parse at all. After this change each form parses to a distinct shape and re-formats to itself byte-for-byte. SelectQuery gains two additive fields — HasParen bool and OuterSettings *SettingsClause — populated by parseSelectQuery when it itself consumes the wrapping parens. The dispatcher now routes a leading `(` to parseSelectQuery so top-level wrapped chains parse end-to-end. parseCTEStmt is updated to consume the CTE-body parens at its own layer (mirroring parseSubQuery), so inner CTE SelectQueries keep HasParen=false and every pre-existing format/beautify golden stays byte-identical. Test suite gains TestParser_With_ChainSettingsDisambiguation plus four new fixtures (output/format/beautify goldens each) covering the four placements. JSON goldens regenerate uniformly with two added lines per SelectQuery rendering; format and beautify goldens are unchanged on every pre-existing fixture. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
45b475a to
4e145f7
Compare
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.
Track paren-wrapping on SelectQuery directly so the four placements of
SETTINGS around a paren-bounded set-op leg become distinct, round-trippable
AST shapes. SELECT 1 UNION ALL (SELECT 2 SETTINGS x=1) (per-leg) and
SELECT 1 UNION ALL (SELECT 2) SETTINGS x=1 (chain-level on the leg)
previously collapsed to byte-identical ASTs; chain-level SETTINGS on a
paren-wrapped chain (e.g. (SELECT 1 UNION ALL SELECT 2) SETTINGS x=1)
failed to parse at all. After this change each form parses to a distinct
shape and re-formats to itself byte-for-byte.
SelectQuery gains two additive fields — HasParen bool and
OuterSettings *SettingsClause — populated by parseSelectQuery when it
itself consumes the wrapping parens. The dispatcher now routes a leading
(to parseSelectQuery so top-level wrapped chains parse end-to-end.parseCTEStmt is updated to consume the CTE-body parens at its own layer
(mirroring parseSubQuery), so inner CTE SelectQueries keep HasParen=false
and every pre-existing format/beautify golden stays byte-identical.
Test suite gains TestParser_With_ChainSettingsDisambiguation plus four
new fixtures (output/format/beautify goldens each) covering the four
placements. JSON goldens regenerate uniformly with two added lines per
SelectQuery rendering; format and beautify goldens are unchanged on
every pre-existing fixture.