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

[sqllab] Fix limit parsing bug when using limit-offset comma notation #7912

Merged
merged 3 commits into from
Jul 24, 2019
Merged

[sqllab] Fix limit parsing bug when using limit-offset comma notation #7912

merged 3 commits into from
Jul 24, 2019

Conversation

villebro
Copy link
Member

CATEGORY

Choose one

  • Bug Fix
  • Enhancement (new features, refinement)
  • Refactor
  • Add tests
  • Build / Development Environment
  • Documentation

SUMMARY

Currently parsing of limit from query with limit-offset comma notation (LIMIT <offset>, <limit>) incorrectly assumes reversed order (LIMIT <limit>, <offset>). This fixes the parsing logic and accompanying unit tests.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TEST PLAN

  • Test in SqlLab
  • CI/Unit tests

REVIEWERS

@john-bodley (I checked git blame and saw that you had worked on this recently)

Copy link
Member

@john-bodley john-bodley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this. One small comment but otherwise LGTM.

@@ -182,7 +182,7 @@ def _extract_limit_from_query(self, statement):
_, token = statement.token_next(idx=idx)
if token:
if isinstance(token, IdentifierList):
_, token = token.token_next(idx=-1)
token = token.tokens[-1]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use token_next(..., reverse=True). This skips comments, whitespace etc. and thus is probably more robust.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree using the native methods would be preferable, and I actually tried to go down that path, but it seems the reverse argument is in fact private (_reverse), and didn't seem to work similar to sorted(..., reverse=True). Will see if I can come up with a more robust solution.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you check my new proposal @john-bodley ?

@codecov-io
Copy link

Codecov Report

Merging #7912 into master will decrease coverage by 7.76%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #7912      +/-   ##
==========================================
- Coverage   73.67%   65.91%   -7.77%     
==========================================
  Files         111      465     +354     
  Lines       11695    22257   +10562     
  Branches        0     2425    +2425     
==========================================
+ Hits         8616    14670    +6054     
- Misses       3079     7466    +4387     
- Partials        0      121     +121
Impacted Files Coverage Δ
superset/sql_parse.py 99.2% <100%> (ø) ⬆️
superset/connectors/druid/models.py 82.2% <0%> (ø) ⬆️
superset/viz.py 71.77% <0%> (ø) ⬆️
superset/assets/src/components/Checkbox.jsx 100% <0%> (ø)
...ations/deckgl/layers/Polygon/PolygonChartPlugin.js 0% <0%> (ø)
...ets/src/dashboard/components/dnd/DragDroppable.jsx 94.59% <0%> (ø)
...c/visualizations/deckgl/layers/Polygon/Polygon.jsx 0% <0%> (ø)
superset/assets/src/components/EditableTitle.jsx 81.53% <0%> (ø)
superset/assets/src/setup/setupPlugins.js 0% <0%> (ø)
...t/assets/src/components/InfoTooltipWithTrigger.jsx 41.66% <0%> (ø)
... and 352 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2221445...4ad9ae1. Read the comment docs.

@@ -182,7 +182,10 @@ def _extract_limit_from_query(self, statement):
_, token = statement.token_next(idx=idx)
if token:
if isinstance(token, IdentifierList):
_, token = token.token_next(idx=-1)
# In case of "LIMIT <offset>, <limit>", find comma and extract
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@villebro this seems good. I just checked the source code to verify that the IdentifierList contains the , punctuation and thus idx will not be None.

@villebro villebro merged commit 72d1011 into apache:master Jul 24, 2019
alex-mark pushed a commit to alex-mark/incubator-superset that referenced this pull request Jul 29, 2019
…apache#7912)

* Fix limit parsing bug when using limit-offset comma notation

* Use native sqlparse semantics to find limit

* black
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.34.0 labels Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels size/XS 🚢 0.34.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants