fix(sql): preserve quoted-identifier casing for the HANA dialect (#39328) (#42731)

Co-authored-by: Claude Code <noreply@anthropic.com>
This commit is contained in:
Evan Rusackas
2026-08-04 20:39:35 -07:00
committed by GitHub
co-authored by Claude Code
parent 5720e9c7fd
commit 2f9bde5579
5 changed files with 131 additions and 2 deletions
+44
View File
@@ -503,6 +503,50 @@ def test_format_oracle_group_by_keeps_explicit_expressions_subquery() -> None:
assert not any(item.isdigit() for item in group_by_items)
def test_format_hana_preserves_quoted_identifier_casing() -> None:
"""
Regression test for https://github.com/apache/superset/issues/39328.
HANA is mapped to the Postgres sqlglot dialect (there's no dedicated HANA
dialect upstream). HANA calculation-view invocations address the view as
a quoted, case-sensitive identifier followed by a PLACEHOLDER parameter
list, e.g. ``"zbw.10_001/INVENTORY"('PLACEHOLDER' = (...))`` -- sqlglot's
parser treats that shape as a function call, so Postgres's inherited
function-name normalization (``NORMALIZE_FUNCTIONS = "upper"``) re-cased
the quoted identifier to ``"ZBW.10_001/INVENTORY"``. HANA resolves
calculation-view names case-sensitively, so the re-cased identifier no
longer exists and SQL Lab fails with ``invalid table name`` even though
the user's original query was valid.
"""
sql = (
'SELECT * FROM _sys_bic."zbw.10_001/INVENTORY"\n'
"(\n"
" 'PLACEHOLDER' = ('$$IP_DATE_TO$$', ''),\n"
" 'PLACEHOLDER' = ('$$IP_DATE_FROM$$', '')\n"
")"
)
formatted = SQLStatement(sql, engine="hana").format()
assert '"zbw.10_001/INVENTORY"' in formatted
assert "$$IP_DATE_TO$$" in formatted
assert "$$IP_DATE_FROM$$" in formatted
def test_format_hana_custom_function_call_untouched() -> None:
"""
The HANA dialect disables function-name normalization entirely (see
``test_format_hana_preserves_quoted_identifier_casing``), which only
affects functions sqlglot doesn't recognize (parsed as
``exp.Anonymous`` -- built-ins like ``COUNT`` have their own dedicated
AST node and always generate with a fixed canonical casing regardless).
An unrecognized, mixed-case function call must round-trip with its
original casing intact rather than being forced to uppercase.
"""
formatted = SQLStatement("SELECT MyCustomFunc(col) FROM t", engine="hana").format()
assert "MyCustomFunc(col)" in formatted
def test_split_no_dialect() -> None:
"""
Test the statement split when the engine has no corresponding dialect.