mirror of
https://github.com/apache/superset.git
synced 2026-04-16 06:34:52 +00:00
fix(sql): handle backtick-quoted identifiers with base dialect (#36545)
Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -556,11 +556,28 @@ class SQLStatement(BaseSQLStatement[exp.Expression]):
|
||||
def _parse(cls, script: str, engine: str) -> list[exp.Expression]:
|
||||
"""
|
||||
Parse helper.
|
||||
|
||||
When the base dialect (engine="base" or unknown engines) fails to parse SQL
|
||||
containing backtick-quoted identifiers, we fall back to MySQL dialect which
|
||||
supports backticks natively. This handles cases like "Other" database type
|
||||
where users may have MySQL-compatible syntax with backtick-quoted table names.
|
||||
"""
|
||||
dialect = SQLGLOT_DIALECTS.get(engine)
|
||||
try:
|
||||
statements = sqlglot.parse(script, dialect=dialect)
|
||||
except sqlglot.errors.ParseError as ex:
|
||||
# If parsing fails with base dialect (or no dialect for unknown engines)
|
||||
# and the script contains backticks, retry with MySQL dialect which
|
||||
# supports backtick-quoted identifiers
|
||||
if (dialect is None or dialect == Dialects.DIALECT) and "`" in script:
|
||||
try:
|
||||
statements = sqlglot.parse(script, dialect=Dialects.MYSQL)
|
||||
except sqlglot.errors.ParseError:
|
||||
# If MySQL dialect also fails, raise the original error
|
||||
pass
|
||||
else:
|
||||
return statements
|
||||
|
||||
kwargs = (
|
||||
{
|
||||
"highlight": ex.errors[0]["highlight"],
|
||||
|
||||
Reference in New Issue
Block a user