fix(sql): handle backtick-quoted identifiers with base dialect#36545
Merged
Conversation
When using the "Other" database type (or unknown engines), SQL parsing would fail if the query contained backtick-quoted identifiers like `SELECT * FROM database.`6``. The base sqlglot dialect doesn't support backticks, but MySQL dialect does. This change adds a fallback mechanism: when parsing fails with the base dialect (or no dialect for unknown engines) and the SQL contains backticks, we retry with MySQL dialect. Fixes #31853 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes SQL parsing failures for backtick-quoted identifiers when using the "Other" database type or engines with unknown dialects. The fix implements a fallback mechanism that retries parsing with MySQL dialect when the base dialect fails and backticks are detected in the SQL.
Key changes:
- Added backtick fallback logic in
SQLStatement._parse()method - Comprehensive test coverage for various backtick-quoted identifier scenarios
- Maintains backward compatibility with normal SQL parsing
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| superset/sql/parse.py | Implements MySQL dialect fallback for backtick-quoted identifiers in base dialect parsing |
| tests/unit_tests/sql/parse_tests.py | Adds comprehensive test cases covering backtick-quoted identifiers with various SQL patterns |
sadpandajoe
pushed a commit
that referenced
this pull request
Dec 16, 2025
Co-authored-by: Claude <noreply@anthropic.com> (cherry picked from commit c7a4d4f)
betodealmeida
pushed a commit
that referenced
this pull request
Dec 19, 2025
Co-authored-by: Claude <noreply@anthropic.com>
isaac-jaynes-imperva
pushed a commit
to isaac-jaynes-imperva/superset
that referenced
this pull request
Mar 3, 2026
qfcwell
pushed a commit
to qfcwell/superset
that referenced
this pull request
May 12, 2026
…e#36545) Co-authored-by: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SUMMARY
When using the "Other" database type (or unknown engines), SQL parsing would fail if the query contained backtick-quoted identifiers like
SELECT * FROM database.6``.Root Cause: The base sqlglot dialect (
Dialects.DIALECT) doesn't support backtick-quoted identifiers, but some databases (particularly MySQL-compatible ones like the sqlalchemy-mongobi connector mentioned in the issue) use backticks for quoting table/column names.Solution: This change adds a fallback mechanism in the
_parsemethod: when parsing fails with the base dialect (or no dialect for unknown engines) and the SQL contains backticks, we retry parsing with the MySQL dialect which supports backticks natively.The fallback only triggers when:
If the MySQL dialect also fails to parse the SQL, the original error is raised to maintain proper error messaging.
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Before: Queries with backtick-quoted identifiers fail with:
After: Queries parse successfully, allowing datasets to be created and SQL Lab queries to run.
TESTING INSTRUCTIONS
SELECT * FROM database.6``SELECT * FROMmy_table``SELECTcol1,col2FROMschema.table``pytest tests/unit_tests/sql/parse_tests.py -k "backtick" -vADDITIONAL INFORMATION
🤖 Generated with Claude Code