[bugfix] fix(sql): strip trailing -- comments before OPTIONS regex match#18425
Open
tarun11Mavani wants to merge 1 commit intoapache:masterfrom
Open
[bugfix] fix(sql): strip trailing -- comments before OPTIONS regex match#18425tarun11Mavani wants to merge 1 commit intoapache:masterfrom
tarun11Mavani wants to merge 1 commit intoapache:masterfrom
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #18425 +/- ##
=============================================
+ Coverage 34.91% 63.60% +28.69%
- Complexity 857 1717 +860
=============================================
Files 3252 3252
Lines 199132 199182 +50
Branches 30875 30889 +14
=============================================
+ Hits 69528 126694 +57166
+ Misses 123518 62408 -61110
- Partials 6086 10080 +3994
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
689b698 to
118f78d
Compare
118f78d to
63d1600
Compare
The legacy OPTIONS regex (e.g. `option(skipUpsert=true)`) is applied to the raw SQL string before it is passed to the Calcite parser. Because `sanitizeSql` only stripped trailing whitespace, a query ending with a single-line comment such as SELECT col1 FROM foo -- option(skipUpsert=true) would be mistakenly treated as if `skipUpsert=true` were a real query option, since the regex anchors at end-of-string (\Z). Fix: scan only the last line of the sanitized SQL for an unquoted `--` sequence and remove it (plus any resulting trailing whitespace) before the OPTIONS regex is applied. Block comments (`/* ... */`) are not affected because they shift the `option(...)` text away from the end-of-string anchor and therefore never triggered the bug. Added two regression test cases to `CalciteSqlCompilerTest#testQueryOptions`: - `-- option(skipUpsert=true)` trailing comment must not set query options - `/* option(skipUpsert=true) */` block comment must not set query options
63d1600 to
1873fbb
Compare
Contributor
Author
|
@Jackie-Jiang @xiangfu0 Can you take a look? |
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.
The legacy OPTIONS regex (e.g.
option(skipUpsert=true)) is applied to the raw SQL string before it is passed to the Calcite parser. BecausesanitizeSqlonly stripped trailing whitespace, a query ending with a single-line comment such asSELECT col1 FROM foo -- option(skipUpsert=true)
would be mistakenly treated as if
skipUpsert=truewere a real query option, since the regex anchors at end-of-string (\Z).Fix: scan only the last line of the sanitized SQL for an unquoted
--sequence and remove it (plus any resulting trailing whitespace) before the OPTIONS regex is applied. Block comments (/* ... */) are not affected because they shift theoption(...)text away from the end-of-string anchor and therefore never triggered the bug.Added two regression test cases to
CalciteSqlCompilerTest#testQueryOptions:-- option(skipUpsert=true)trailing comment must not set query options/* option(skipUpsert=true) */block comment must not set query optionsBug reproduced in cluster:
Without skipUpsert=true:

With skipUpsert=true

With skipUpsert=true but in comments. -> This is incorrect.
