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

Unable to parse escaped tables #30551

Closed
3 tasks done
michael-s-molina opened this issue Oct 8, 2024 · 7 comments · Fixed by #30560
Closed
3 tasks done

Unable to parse escaped tables #30551

michael-s-molina opened this issue Oct 8, 2024 · 7 comments · Fixed by #30560
Assignees
Labels
sqllab Namespace | Anything related to the SQL Lab

Comments

@michael-s-molina
Copy link
Member

Bug description

The following query throws This database does not allow for DDL/DML, and the query could not be parsed to confirm it is a read-only query. Please contact your administrator for more assistance.

select *
from `birth_names`

The ability to escape table names is essential given that we might have names that conflict with reserved keywords.

This bug was introduced in #30417.

Screenshots/recordings

Screenshot 2024-10-08 at 11 29 55

Superset version

master / latest-dev

Python version

3.9

Node version

16

Browser

Chrome

Additional context

No response

Checklist

  • I have searched Superset docs and Slack and didn't find a solution to my problem.
  • I have searched the GitHub issue tracker and didn't find a similar bug report.
  • I have checked Superset's logs for errors and if I found a relevant Python stacktrace, I included it here as text in the "additional context" section.
@michael-s-molina michael-s-molina moved this to Release Blockers in Apache Superset 4.1 Oct 8, 2024
@dosubot dosubot bot added the sqllab Namespace | Anything related to the SQL Lab label Oct 8, 2024
@betodealmeida
Copy link
Member

@michael-s-molina backticks are not valid Postgres quoting identifiers, you should use double quotes instead: https://www.postgresql.org/docs/17/sql-syntax-lexical.html

superset=# SELECT * FROM `birth_names`;
ERROR:  syntax error at or near "`"
LINE 1: SELECT * FROM `birth_names`;

@michael-s-molina
Copy link
Member Author

michael-s-molina commented Oct 8, 2024

@betodealmeida backticks are valid quoting identifiers for other databases such as Trino and MySQL. I just used the Postgres database as an example. We have many queries that use them.

@betodealmeida
Copy link
Member

@michael-s-molina the parsing is now engine dependent, so if the database uses backticks for quoting then it should work. For MySQL, eg:

Screenshot 2024-10-08 at 12-25-09 Preset

@betodealmeida
Copy link
Member

If you have a database where this fails but the SQL is actually valid let me know.

@sadpandajoe
Copy link
Member

It could also be using a default dialect if there isn't one in sqlglot, right @betodealmeida? If that's the case we'll probably need to just add a dialect file with sqlglot?

@betodealmeida
Copy link
Member

@sadpandajoe right, if this is happening on a database that doesn't have a sqlglot dialect it would fallback to the generic dialect, which probably uses double quotes since that's the ANSI SQL standard.

@michael-s-molina
Copy link
Member Author

michael-s-molina commented Oct 8, 2024

@betodealmeida @sadpandajoe I was able to confirm that the root cause for the error is because we have custom database engine spec which does not map to any SQLGlot dialect in SQLGLOT_DIALECTS and end up using the default dialect which does not support backticks. I think the dialect should come from the database engine spec instead of a static map. I'll work on a fix for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sqllab Namespace | Anything related to the SQL Lab
Projects
No open projects
Status: Cherried
Development

Successfully merging a pull request may close this issue.

3 participants