feat(parser,ast): preserve parenthesized expressions (fix #519) - #532
Open
basili4-1982 wants to merge 1 commit into
Open
feat(parser,ast): preserve parenthesized expressions (fix #519)#532basili4-1982 wants to merge 1 commit into
basili4-1982 wants to merge 1 commit into
Conversation
…atap0#519) Add a ParenthesizedExpression AST node so grouped predicates round-trip unchanged. Previously parentheses were dropped during parsing, silently changing AND/OR precedence: (a OR b) AND c re-rendered as a OR b AND c. - ast_expressions.go: new ParenthesizedExpression node (Expr, Pos) - ast/sql.go: SQL() emits (...) - expressions_literal.go: wrap single parenthesized primary expressions - pool_expression_release.go: release child expr; node needs no pool - roundtrip_test.go: grouped OR and nested-parens cases - parenthesized_expression_test.go: regression tests (CH dialect)
|
@basili4-1982 is attempting to deploy a commit to the coolajitpratapsingh0-9932's projects Team on Vercel. A member of the Team first needs to authorize it. |
Author
|
Проверено, готово к мержу.
Прошу ревью/мерж. Фикс закрывает #519 (скобки в WHERE не теряются). |
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.
Fixes #519.
Summary
Parenthesized expressions in
WHERE(and anywhere an expression appears) weresilently dropped during parsing, so group-precedence was lost on re-render:
This silently changes the meaning of the predicate.
Root cause
parsePrimaryExpressionparsed(expr)and returned the bareexpr, discardingthe grouping. There was no AST node to represent parentheses, so round-trip
could not preserve them.
Changes
pkg/sql/ast/ast_expressions.go: newParenthesizedExpressionnode(
Expr,Pos).pkg/sql/ast/sql.go:(*ParenthesizedExpression).SQL()emits(...).pkg/sql/parser/expressions_literal.go: single parenthesized primaryexpressions now wrap in a
ParenthesizedExpression(tuple(a, b, c)and subquery
(SELECT ...)paths unchanged).pkg/sql/ast/pool_expression_release.go: release child expr; the node itselfneeds no dedicated pool.
pkg/sql/ast/roundtrip_test.go: grouped-OR and nested-parens cases.pkg/sql/parser/parenthesized_expression_test.go: regression tests.Test plan
TestParenthesizedExpressionRoundtrippassgo test -short ./pkg/sql/ast/ ./pkg/sql/parser/ ./pkg/gosqlx/ ./pkg/formatter/greengosqlx.Format(...)preserves parentheses((a AND b) OR c) AND dround-trip unchangedNote:
TestPerformanceRegressionfails in this environment against itsbaseline (5 cases) — unrelated to this change, reproduced on unmodified main.