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

Fixed Parser Where Queries Improperly Parsed As Alias #128

Closed
wants to merge 6 commits into from

Conversation

GabeFernandez310
Copy link

@GabeFernandez310 GabeFernandez310 commented Oct 4, 2022

Signed-off-by: GabeFernandez310 gabrielf@bitquilltech.com

Description

Multiplication in queries were treated as an alias if there is no space between * and the value.
E.g. 'SELECT 2*6'
See result of 2 with alias *6

Expected Behavior:
The result should be 12

Implemented Fix:
Removed * from ID_LITERAL fragment in lexer to fix math statement being treated as an alias, and separated rules used for tokenizing table names from other identifiers.

  • Accomplished by adding a new lexical mode FROM_CLAUSE. This defines a separate rule set used to properly tokenize table names which contain * because it is required in OpenSearch, but otherwise should not exist because it introduces ambiguity when tokenizing a SQL query and because it should not exist in MySQL.

Issues Resolved

#265

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.

@GabeFernandez310 GabeFernandez310 requested a review from a team October 4, 2022 00:08
@codecov
Copy link

codecov bot commented Oct 4, 2022

Codecov Report

Merging #128 (b5683c2) into integ-fix-alias-issue (b244f2e) will decrease coverage by 0.04%.
The diff coverage is 100.00%.

@@                     Coverage Diff                     @@
##             integ-fix-alias-issue     #128      +/-   ##
===========================================================
- Coverage                    95.01%   94.96%   -0.05%     
+ Complexity                    3020     3018       -2     
===========================================================
  Files                          294      294              
  Lines                         8083     8083              
  Branches                       594      594              
===========================================================
- Hits                          7680     7676       -4     
- Misses                         349      352       +3     
- Partials                        54       55       +1     
Flag Coverage Δ
query-workbench 62.76% <ø> (ø)
sql-engine 97.81% <100.00%> (-0.06%) ⬇️

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

Impacted Files Coverage Δ
...pensearch/sql/sql/parser/AstExpressionBuilder.java 100.00% <100.00%> (ø)
...java/org/opensearch/sql/sql/parser/AstBuilder.java 95.23% <0.00%> (-4.77%) ⬇️
...rch/sql/sql/parser/context/QuerySpecification.java 98.21% <0.00%> (-1.79%) ⬇️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@GumpacG
Copy link

GumpacG commented Oct 6, 2022

Does this also fix opensearch-project#720? If so, it might be worth mentioning this issue so it can also be marked as resolved.

@GabeFernandez310 GabeFernandez310 force-pushed the dev-fix-alias-issue branch 2 times, most recently from 65e21c8 to 8c5b0e6 Compare October 6, 2022 23:46
@acarbonetto
Copy link

Does this also fix opensearch-project#720? If so, it might be worth mentioning this issue so it can also be marked as resolved.

It doesn't, since it's a separate grammar file. However, the PPL grammar has the same grammar ambiguity, and if its the same fix, we could propose the change (as a separate PR).

cc: @GabeFernandez310

Signed-off-by: GabeFernandez310 <gabrielf@bitquilltech.com>
Signed-off-by: GabeFernandez310 <gabrielf@bitquilltech.com>
 In FROM_CLAUSE Mode For Error Recognition

Signed-off-by: GabeFernandez310 <gabrielf@bitquilltech.com>
@GabeFernandez310 GabeFernandez310 marked this pull request as draft October 18, 2022 15:54
Signed-off-by: GabeFernandez310 <gabrielf@bitquilltech.com>
Signed-off-by: GabeFernandez310 <gabrielf@bitquilltech.com>
Signed-off-by: GabeFernandez310 <gabrielf@bitquilltech.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants