-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#7714 ignore query options in commented out queries #7894
#7714 ignore query options in commented out queries #7894
Conversation
Codecov Report
@@ Coverage Diff @@
## master #7894 +/- ##
============================================
+ Coverage 71.28% 71.38% +0.09%
- Complexity 4091 4193 +102
============================================
Files 1587 1594 +7
Lines 82059 82562 +503
Branches 12264 12321 +57
============================================
+ Hits 58498 58935 +437
- Misses 19596 19641 +45
- Partials 3965 3986 +21
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
@Jackie-Jiang carrying review forward from PR: #7869 The way I have resolved the issue you have mentioned: I am using This will not work for queries which have query options specified and are using the
will be parsed as
This can be mitigated by differentiating regex pattern between query comment and string literal/identifier. I did check if we could use the default MySQL dialect to pass query options (using
Please let me know if I am missing something here ^^ |
@kriti-sc |
@@ -95,7 +95,7 @@ private CalciteSqlParser() { | |||
// `OPTION (<k1> = <v1>) OPTION (<k2> = <v2>) OPTION (<k3> = <v3>)` | |||
private static final Pattern OPTIONS_REGEX_PATTEN = | |||
Pattern.compile("option\\s*\\(([^\\)]+)\\)", Pattern.CASE_INSENSITIVE); | |||
|
|||
private static final Pattern COMMENTED_QUERY_PATTERN = Pattern.compile("-{2,}"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can use simply search for "--" instead of using regex match? Substring search is much cheaper comparing to regex match
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is done – our original problem with using --
pattern as signpost remains.
@@ -122,6 +122,7 @@ public static PinotQuery compileToPinotQuery(String sql) | |||
|
|||
// Extract OPTION statements from sql as Calcite Parser doesn't parse it. | |||
List<String> options = extractOptionsFromSql(sql); | |||
sql = removeCommentedOptionsFromSql(sql); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to remove the commented options again here?
I feel a simpler and more readable way to support this is to first remove the commented part from the sql, then extract the options
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not wise to remove the commented part from the sql because it may distort the query. Ex:
SELECT * FROM tableA where colA LIKE '%--%'
becomes SELECT * FROM tableA where colA LIKE '%%'
But this is the change I have made – The first thing that will happen is the removal of commented options. After this, query parsing will proceed like before.
Fixes #7714
Description
Since query option is processed as a regex, options are being picked up from commented-out queries. E.g.
This change ensures that options in commented-out query are ignored.