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

[sqlparse] fix sqlparse bug #5703

Merged
merged 2 commits into from
Aug 23, 2018
Merged

Conversation

timifasubaa
Copy link
Contributor

@timifasubaa timifasubaa commented Aug 22, 2018

superset's sql_parse implementation fails when there are more than two tables in a join.
This causes problems when we use this method to extract tables to determine if a user can access all the tables in a sqllab query.

This PR addresses the issue by preventing it from stopping early. I also added a test.

@john-bodley @mistercrunch

@timifasubaa timifasubaa changed the title [WIP] fix sqlparse bug [sqlparse] fix sqlparse bug Aug 22, 2018
@timifasubaa timifasubaa force-pushed the fix_sqlparse_bug branch 5 times, most recently from a5690f9 to aaf5899 Compare August 22, 2018 22:34
@codecov-io
Copy link

codecov-io commented Aug 22, 2018

Codecov Report

Merging #5703 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5703      +/-   ##
==========================================
+ Coverage   63.45%   63.45%   +<.01%     
==========================================
  Files         361      361              
  Lines       22972    22973       +1     
  Branches     2557     2557              
==========================================
+ Hits        14576    14577       +1     
  Misses       8381     8381              
  Partials       15       15
Impacted Files Coverage Δ
superset/sql_parse.py 99.17% <100%> (ø) ⬆️

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 8992755...fcc1c17. Read the comment docs.

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.

Should this logic belong in a function other than __extract_from_token?

@@ -128,7 +129,8 @@ def __extract_from_token(self, token):
continue

if item.ttype in Keyword:
if self.__is_result_operation(item.value):
if (self.__is_result_operation(item.value) or
item.value.upper() == ON_KEYWORD):
Copy link
Member

@john-bodley john-bodley Aug 22, 2018

Choose a reason for hiding this comment

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

It seems like line #134 is (and was) obsolete and that this check simply ensures one doesn't break. Would it make more sense if one simply removed the break logic? According to line #136 (# FROM clause is over) one would speculate that this portion of the code simply processes a FROM clause rather than a JOIN clause.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tested using continue instead of the break statement and it broke in some cases because it included the group by column in the table names.

@@ -310,3 +310,23 @@ def test_explain(self):
self.assertEquals(True, sql.is_explain())
self.assertEquals(False, sql.is_select())
self.assertEquals(True, sql.is_readonly())

def test_complex_extract_tables(self):
Copy link
Member

Choose a reason for hiding this comment

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

can we add another test that does not use ON? Something like

SELECT * 
FROM table_a AS a, table_b AS b
WHERE a.id = b.id

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@john-bodley
Copy link
Member

john-bodley commented Aug 23, 2018

@timifasubaa pending the flake8 fix, this LGTM.

@timifasubaa timifasubaa merged commit 5c49514 into apache:master Aug 23, 2018
john-bodley pushed a commit to john-bodley/superset that referenced this pull request Aug 23, 2018
* fix sqlparse bug

* add one more test case

(cherry picked from commit 5c49514)
john-bodley added a commit to airbnb/superset-fork that referenced this pull request Aug 23, 2018
mistercrunch pushed a commit to lyft/incubator-superset that referenced this pull request Sep 21, 2018
* fix sqlparse bug

* add one more test case

(cherry picked from commit 5c49514)
mistercrunch pushed a commit to lyft/incubator-superset that referenced this pull request Sep 21, 2018
* fix sqlparse bug

* add one more test case

(cherry picked from commit 5c49514)
mistercrunch pushed a commit to lyft/incubator-superset that referenced this pull request Sep 21, 2018
* fix sqlparse bug

* add one more test case

(cherry picked from commit 5c49514)
mistercrunch pushed a commit to lyft/incubator-superset that referenced this pull request Sep 21, 2018
* fix sqlparse bug

* add one more test case

(cherry picked from commit 5c49514)
mistercrunch pushed a commit to lyft/incubator-superset that referenced this pull request Sep 21, 2018
* fix sqlparse bug

* add one more test case

(cherry picked from commit 5c49514)
mistercrunch pushed a commit to lyft/incubator-superset that referenced this pull request Sep 21, 2018
* fix sqlparse bug

* add one more test case

(cherry picked from commit 5c49514)
mistercrunch pushed a commit to lyft/incubator-superset that referenced this pull request Sep 21, 2018
* fix sqlparse bug

* add one more test case

(cherry picked from commit 5c49514)
mistercrunch pushed a commit to lyft/incubator-superset that referenced this pull request Sep 21, 2018
* fix sqlparse bug

* add one more test case

(cherry picked from commit 5c49514)
mistercrunch pushed a commit to lyft/incubator-superset that referenced this pull request Sep 21, 2018
* fix sqlparse bug

* add one more test case

(cherry picked from commit 5c49514)
mistercrunch pushed a commit to lyft/incubator-superset that referenced this pull request Sep 21, 2018
* fix sqlparse bug

* add one more test case

(cherry picked from commit 5c49514)
mistercrunch pushed a commit to lyft/incubator-superset that referenced this pull request Sep 21, 2018
* fix sqlparse bug

* add one more test case

(cherry picked from commit 5c49514)
betodealmeida pushed a commit to lyft/incubator-superset that referenced this pull request Oct 11, 2018
* fix sqlparse bug

* add one more test case

(cherry picked from commit 5c49514)
betodealmeida pushed a commit to lyft/incubator-superset that referenced this pull request Oct 11, 2018
* fix sqlparse bug

* add one more test case

(cherry picked from commit 5c49514)
betodealmeida pushed a commit to lyft/incubator-superset that referenced this pull request Oct 11, 2018
* fix sqlparse bug

* add one more test case

(cherry picked from commit 5c49514)
betodealmeida pushed a commit to lyft/incubator-superset that referenced this pull request Oct 12, 2018
* fix sqlparse bug

* add one more test case
betodealmeida pushed a commit to lyft/incubator-superset that referenced this pull request Oct 12, 2018
* fix sqlparse bug

* add one more test case

(cherry picked from commit 5c49514)
betodealmeida pushed a commit to lyft/incubator-superset that referenced this pull request Oct 12, 2018
* fix sqlparse bug

* add one more test case

(cherry picked from commit 5c49514)
youngyjd pushed a commit to lyft/incubator-superset that referenced this pull request Oct 17, 2018
* fix sqlparse bug

* add one more test case

(cherry picked from commit 5c49514)
youngyjd pushed a commit to lyft/incubator-superset that referenced this pull request Oct 17, 2018
* fix sqlparse bug

* add one more test case

(cherry picked from commit 5c49514)
youngyjd pushed a commit to lyft/incubator-superset that referenced this pull request Oct 17, 2018
* fix sqlparse bug

* add one more test case

(cherry picked from commit 5c49514)
youngyjd pushed a commit to lyft/incubator-superset that referenced this pull request Oct 17, 2018
* fix sqlparse bug

* add one more test case

(cherry picked from commit 5c49514)
youngyjd pushed a commit to lyft/incubator-superset that referenced this pull request Oct 17, 2018
* fix sqlparse bug

* add one more test case

(cherry picked from commit 5c49514)
mistercrunch pushed a commit to lyft/incubator-superset that referenced this pull request Oct 29, 2018
* fix sqlparse bug

* add one more test case

(cherry picked from commit 5c49514)
betodealmeida pushed a commit to lyft/incubator-superset that referenced this pull request Oct 30, 2018
* fix sqlparse bug

* add one more test case

(cherry picked from commit 5c49514)
betodealmeida pushed a commit to lyft/incubator-superset that referenced this pull request Oct 30, 2018
* fix sqlparse bug

* add one more test case

(cherry picked from commit 5c49514)
betodealmeida pushed a commit to lyft/incubator-superset that referenced this pull request Oct 30, 2018
* fix sqlparse bug

* add one more test case

(cherry picked from commit 5c49514)
betodealmeida pushed a commit to lyft/incubator-superset that referenced this pull request Oct 30, 2018
* fix sqlparse bug

* add one more test case

(cherry picked from commit 5c49514)
betodealmeida pushed a commit to lyft/incubator-superset that referenced this pull request Oct 30, 2018
* fix sqlparse bug

* add one more test case

(cherry picked from commit 5c49514)
youngyjd pushed a commit to lyft/incubator-superset that referenced this pull request Nov 2, 2018
* fix sqlparse bug

* add one more test case

(cherry picked from commit 5c49514)
youngyjd pushed a commit to lyft/incubator-superset that referenced this pull request Nov 2, 2018
* fix sqlparse bug

* add one more test case

(cherry picked from commit 5c49514)
wenchma pushed a commit to wenchma/incubator-superset that referenced this pull request Nov 16, 2018
* fix sqlparse bug

* add one more test case
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.28.0 labels Feb 27, 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 🚢 0.28.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants