-
Notifications
You must be signed in to change notification settings - Fork 141
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
Fix arithmetic operator precedence #1172
Fix arithmetic operator precedence #1172
Conversation
Signed-off-by: Chen Dai <[email protected]>
Codecov Report
@@ Coverage Diff @@
## main #1172 +/- ##
============================================
- Coverage 95.81% 95.81% -0.01%
Complexity 3521 3521
============================================
Files 352 352
Lines 9359 9357 -2
Branches 673 673
============================================
- Hits 8967 8965 -2
Misses 334 334
Partials 58 58
Flags with carried forward coverage won't be shown. Click here to find out more.
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
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.
Please fix this for PPL too:
opensearchsql> source=people | eval test = 1 + 2 * 3 | fields `test`;
fetched rows / total rows = 1/1
+--------+
| test |
|--------|
| 9 |
+--------+
I missed it. Let me check. |
Signed-off-by: Chen Dai <[email protected]>
Fixed in bac6f3a. I found that PPL expression doesn't support parentheses. I'm not sure if this is by design for other expressions like logical and comparison. I fixed this for arithmetic expression which is required by this precedence fix. Thanks! |
* Fix precedence by reordering grammar rule Signed-off-by: Chen Dai <[email protected]> * Fix precedence in PPL Signed-off-by: Chen Dai <[email protected]> Signed-off-by: Chen Dai <[email protected]> (cherry picked from commit ab46fdd)
* Fix precedence by reordering grammar rule Signed-off-by: Chen Dai <[email protected]> * Fix precedence in PPL Signed-off-by: Chen Dai <[email protected]> Signed-off-by: Chen Dai <[email protected]> (cherry picked from commit ab46fdd) Co-authored-by: Chen Dai <[email protected]>
Description
This PR fixed arithmetic operator precedence reported in the issue below. I tried to reorder operator in
mathOperator
rule (Reference: https://github.com/antlr/grammars-v4/blob/master/sql/mysql/Positive-Technologies/MySqlParser.g4#L2598). However, reordering operator insidemathOperator
rule didn't work at all.Finally, I split the
mathExpressionAtom
rule and order them by precedence (Reference: https://github.com/crate/crate/blob/master/libs/sql-parser/src/main/antlr/SqlBaseParser.g4#L299).Issues Resolved
#293
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.