Skip to content
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

Merged

Conversation

dai-chen
Copy link
Collaborator

@dai-chen dai-chen commented Dec 14, 2022

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 inside mathOperator 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

  • New functionality includes testing.
    • All tests pass, including unit test, integration test and doctest
  • New functionality has been documented.
    • New functionality has javadoc added
    • New functionality has user manual doc added
  • Commits are signed per the DCO using --signoff

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.

@dai-chen dai-chen added the bug Something isn't working label Dec 14, 2022
@dai-chen dai-chen self-assigned this Dec 14, 2022
@codecov-commenter
Copy link

codecov-commenter commented Dec 14, 2022

Codecov Report

Merging #1172 (bac6f3a) into main (034027c) will decrease coverage by 0.00%.
The diff coverage is 100.00%.

@@             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              
Flag Coverage Δ
query-workbench 62.76% <ø> (ø)
sql-engine 98.31% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...pensearch/sql/ppl/parser/AstExpressionBuilder.java 100.00% <100.00%> (ø)
...pensearch/sql/sql/parser/AstExpressionBuilder.java 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@dai-chen dai-chen marked this pull request as ready for review December 14, 2022 18:07
@dai-chen dai-chen requested a review from a team as a code owner December 14, 2022 18:07
Copy link
Collaborator

@Yury-Fridlyand Yury-Fridlyand left a 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      |
+--------+

@dai-chen
Copy link
Collaborator Author

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]>
@dai-chen
Copy link
Collaborator Author

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.

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!

@dai-chen dai-chen merged commit ab46fdd into opensearch-project:main Dec 16, 2022
opensearch-trigger-bot bot pushed a commit that referenced this pull request Dec 16, 2022
* 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)
@dai-chen dai-chen deleted the fix-arthmetic-operator-precedence branch December 16, 2022 18:41
dai-chen added a commit that referenced this pull request Dec 16, 2022
* 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.x bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants