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

SQL parser incorrectly identifies SQL reserved keywords as table names #12677

Open
3 tasks done
john-bodley opened this issue Jan 22, 2021 · 7 comments
Open
3 tasks done
Labels
!deprecated-label:bug Deprecated label - Use #bug instead sqllab Namespace | Anything related to the SQL Lab

Comments

@john-bodley
Copy link
Member

john-bodley commented Jan 22, 2021

There's a few examples we've seen where the SQL parser incorrectly identifies SQL reserved keywords as tables when parsing the query. Note I've worked with sqlparse in another project and I sense we probably may need to complete rewrite Superset's parser in order for accurately extracting the table names leveraging more of the core sqlparse's functionality.

Expected results

The SQL parser should identify all data warehouse tables/views with no false positives.

Actual results

The SQL parser misidentifies (under certain circumstances) SQL reserved keywords as table names.

How to reproduce the bug

>>> from superset.sql_parse import ParsedQuery
>>> ParsedQuery(sql_statement="SELECT * FROM foo bar TABLESAMPLE BERNOULLI(50);").tables
{Table(table='TABLESAMPLE', schema=None, catalog=None), Table(table='foo', schema=None, catalog=None)}

Note adding the AS keyword results in a different result:

>>> from superset.sql_parse import ParsedQuery
>>> ParsedQuery(sql_statement="SELECT * FROM foo AS bar TABLESAMPLE BERNOULLI(50);").tables
{Table(table='foo', schema=None, catalog=None)}

Environment

(please complete the following information):

  • superset version: superset version
  • python version: python --version
  • node.js version: node -v

Checklist

Make sure to follow these steps before submitting your issue - thank you!

  • I have checked the superset logs for python stacktraces and included it here as text if there are any.
  • I have reproduced the issue with at least the latest released version of superset.
  • I have checked the issue tracker for the same issue and I haven't found one similar.
@john-bodley john-bodley added the #bug Bug report label Jan 22, 2021
@john-bodley
Copy link
Member Author

@bkyryliuk and @villebro et al. any thoughts on this? Has Dropbox or Preset run into this issue?

@john-bodley
Copy link
Member Author

@villebro or @dpgaspar has Preset experienced this issue?

@dpgaspar
Copy link
Member

dpgaspar commented Mar 3, 2021

Not that I'm aware of. probably these keywords are not on sqlparse, not too familiar with it, would it make sense or solve the issue to extend those keywords?

@villebro
Copy link
Member

villebro commented Mar 3, 2021

@john-bodley I'm surprised adding that AS there makes a difference, I would have assumed it easily infers that's an alias in the first example. I assume this is a bug on sqlparse, maybe we should open a ticket there? I also haven't heard of anyone having this problem on Preset.

@zuzana-vej zuzana-vej added !deprecated-label:bug Deprecated label - Use #bug instead sqllab Namespace | Anything related to the SQL Lab and removed #bug Bug report labels Apr 20, 2021
@stale
Copy link

stale bot commented May 2, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. For admin, please label this issue .pinned to prevent stale bot from closing the issue.

@stale stale bot added the inactive Inactive for >= 30 days label May 2, 2022
@rusackas
Copy link
Member

rusackas commented Feb 5, 2024

@john-bodley Your call to keep or close this one... it's gotten pretty old :)

@stale stale bot removed the inactive Inactive for >= 30 days label Feb 5, 2024
@john-bodley
Copy link
Member Author

@rusackas, hopefully this issue will be resolved via @betodealmeida SIP-117.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
!deprecated-label:bug Deprecated label - Use #bug instead sqllab Namespace | Anything related to the SQL Lab
Projects
None yet
Development

No branches or pull requests

5 participants