Repository navigation
fix(sql): preserve optimizer hints when formatting semicolon-terminated statements with trailing comments - #43565
Conversation
…ed statements with trailing comments
Code Review Agent Run #056cc0Actionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
|
The flagged issue is correct. The current implementation of To resolve this, update the # superset/sql/parse.py
for clause_name in (
"options",
"settings",
"format",
"locks",
"offset",
"limit",
"sort",
"cluster",
"distribute",
"order",
"windows", # Updated from "window"
"qualify",
"having",
"group",
"where",
"joins",
"laterals",
"from",
"into",
"expressions",
):There are no other review comments on this PR. superset/sql/parse.py |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #43565 +/- ##
=======================================
Coverage 79.10% 79.10%
=======================================
Files 2878 2878
Lines 165634 165659 +25
Branches 38294 38305 +11
=======================================
+ Hits 131023 131050 +27
Misses 32123 32123
+ Partials 2488 2486 -2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Code Review Agent Run #36e83fActionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
Code Review Agent Run #3b182aActionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
SUMMARY
Fixes #38189
In
SQLStatement._parse, when a SQL script contained statements terminated by a semicolon followed by trailing--comments (whichsqlglotparses as a trailingexp.Semicolonstatement), the comment relocation logic iterated over all AST nodes using.walk().Because
.walk()traverses AST subtrees in internal dictionary order rather than reverse SQL document rendering order,targetwas erroneously set to leaf nodes inside optimizer hint blocks (e.g.exp.Hint->Identifier("query_timeout")), causing trailing comments to be injected directly inside optimizer hints (e.g./*+ SET_VAR(query_timeout /* comment */ = 3000) */).This PR fixes this by introducing
_find_last_token_node(node), which:offset,limit,order,window,where,from,expressions, etc.).exp.Hint/ non-trailing nodes so that comments are safely attached to the final token/clause of the statement.@pytest.mark.xfailmarker fromtest_sqlscript_format_preserves_optimizer_hint_block_with_semicolonintests/unit_tests/sql/parse_tests.pyand adds tests covering CTEs and optimizer hints.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A (SQL Parsing & formatting fix)
TESTING INSTRUCTIONS
/*+ ... */hint block.ADDITIONAL INFORMATION
--comments inside optimizer hint blocks (/*+ SET_VAR */), breaking StarRocks syntax #38189SUGGESTED LABELS
#bug:regression,data:sqllab,sql,validation:validated,P2