etr2460 opened a new pull request #13602:
URL: https://github.com/apache/superset/pull/13602


   ### SUMMARY
   I found that aliased subselects would break the logic to extract table names 
from a query. When using sqlparse, it seemed like the query got expanded more 
than expected when the alias was added:
   ```
   >>> import sqlparse
   >>> sqlparse.parse("SELECT f1, (SELECT count(1) FROM t2) FROM 
t1")[0]._pprint_tree()
   |- 0 DML 'SELECT'
   |- 1 Whitespace ' '
   |- 2 Identifier 'f1'
   |  `- 0 Name 'f1'
   |- 3 Punctuation ','
   |- 4 Whitespace ' '
   |- 5 Parenthesis '(SELEC...'
   |  |- 0 Punctuation '('
   |  |- 1 DML 'SELECT'
   |  |- 2 Whitespace ' '
   |  |- 3 Function 'count(...'
   |  |  |- 0 Identifier 'count'
   |  |  |  `- 0 Name 'count'
   |  |  `- 1 Parenthesis '(1)'
   |  |     |- 0 Punctuation '('
   |  |     |- 1 Integer '1'
   |  |     `- 2 Punctuation ')'
   |  |- 4 Whitespace ' '
   |  |- 5 Keyword 'FROM'
   |  |- 6 Whitespace ' '
   |  |- 7 Identifier 't2'
   |  |  `- 0 Name 't2'
   |  `- 8 Punctuation ')'
   |- 6 Whitespace ' '
   |- 7 Keyword 'FROM'
   |- 8 Whitespace ' '
   `- 9 Identifier 't1'
      `- 0 Name 't1'
   >>> sqlparse.parse("SELECT f1, (SELECT count(1) FROM t2) as f2 FROM 
t1")[0]._pprint_tree()
   |- 0 DML 'SELECT'
   |- 1 Whitespace ' '
   |- 2 IdentifierList 'f1, (S...'
   |  |- 0 Identifier 'f1'
   |  |  `- 0 Name 'f1'
   |  |- 1 Punctuation ','
   |  |- 2 Whitespace ' '
   |  `- 3 Identifier '(SELEC...'
   |     |- 0 Parenthesis '(SELEC...'
   |     |  |- 0 Punctuation '('
   |     |  |- 1 DML 'SELECT'
   |     |  |- 2 Whitespace ' '
   |     |  |- 3 Function 'count(...'
   |     |  |  |- 0 Identifier 'count'
   |     |  |  |  `- 0 Name 'count'
   |     |  |  `- 1 Parenthesis '(1)'
   |     |  |     |- 0 Punctuation '('
   |     |  |     |- 1 Integer '1'
   |     |  |     `- 2 Punctuation ')'
   |     |  |- 4 Whitespace ' '
   |     |  |- 5 Keyword 'FROM'
   |     |  |- 6 Whitespace ' '
   |     |  |- 7 Identifier 't2'
   |     |  |  `- 0 Name 't2'
   |     |  `- 8 Punctuation ')'
   |     |- 1 Whitespace ' '
   |     |- 2 Keyword 'as'
   |     |- 3 Whitespace ' '
   |     `- 4 Identifier 'f2'
   |        `- 0 Name 'f2'
   |- 3 Whitespace ' '
   |- 4 Keyword 'FROM'
   |- 5 Whitespace ' '
   `- 6 Identifier 't1'
      `- 0 Name 't1'
   ```
   
   This adds logic to recursively explore sections wrapped in parens, which 
seems safe and didn't break any of the existing tests while allowing mine to 
pass. That said, would love any thoughts on a better way to do this too
   
   ### TEST PLAN
   CI
   
   to: @villebro @lilykuang @serenajiang @bkyryliuk 


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to