From d86607a875613f9e8eda16fdcf4a1cfa65e9fa51 Mon Sep 17 00:00:00 2001 From: sadpandajoe Date: Wed, 19 Aug 2026 21:25:12 +0000 Subject: [PATCH] test(sql): cover new schema/catalog quoting and SHOW helpers superset/sql/parse.py added has_quoted_table_location() and is_show_statement()/has_show_statement() in a32225646c but the coverage gate for tests/unit_tests/sql/ requires 100%; add direct unit tests for the base-class defaults and the SQLStatement/SQLScript overrides. Co-Authored-By: Claude Sonnet 5 --- tests/unit_tests/sql/parse_tests.py | 60 +++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/tests/unit_tests/sql/parse_tests.py b/tests/unit_tests/sql/parse_tests.py index 3a8370ace7b..b6f9876da59 100644 --- a/tests/unit_tests/sql/parse_tests.py +++ b/tests/unit_tests/sql/parse_tests.py @@ -4825,6 +4825,66 @@ def test_changes_default_schema(sql: str, engine: str, expected: bool) -> None: assert SQLScript(sql, engine).changes_default_schema() == expected +@pytest.mark.parametrize( + "sql, engine, expected", + [ + # A quoted catalog identifier is case-sensitive and may not match + # after the engine's default case folding. + ('SELECT * FROM "c1".s.t1', "snowflake", True), + # A quoted schema (``db``) identifier is equally unsafe. + ('SELECT * FROM c1."s".t1', "snowflake", True), + # An unquoted location can be safely folded to the engine's default + # case. + ("SELECT * FROM c1.s.t1", "snowflake", False), + # Quoting the table name itself doesn't affect catalog/schema safety. + ('SELECT * FROM "t1"', "snowflake", False), + ], +) +def test_has_quoted_table_location(sql: str, engine: str, expected: bool) -> None: + """ + `has_quoted_table_location` flags queries whose catalog or schema is + quoted, so the SQL Lab dataset-creation flow keeps the dropdown schema + instead of deriving a location that may not match after case folding. + """ + assert SQLStatement(sql, engine).has_quoted_table_location() == expected + assert SQLScript(sql, engine).has_quoted_table_location() == expected + + +def test_has_quoted_table_location_unsupported_dialect() -> None: + """ + Engines without a sqlglot AST (e.g. Kusto KQL) report no quoted table + location instead of raising, matching the ``BaseSQLStatement`` default. + """ + statement = KustoKQLStatement("foo | take 100", "kustokql") + assert statement.has_quoted_table_location() is False + + +@pytest.mark.parametrize( + "sql, engine, expected", + [ + ("show columns from foo from bar", "mysql", True), + ("SELECT * FROM t1", "mysql", False), + ], +) +def test_is_show_statement(sql: str, engine: str, expected: bool) -> None: + """ + `is_show_statement`/`has_show_statement` identify metadata statements so + the SQL Lab dataset-creation flow keeps the dropdown schema rather than + deriving one from a query with no meaningful result set. + """ + assert SQLStatement(sql, engine).is_show_statement() == expected + assert SQLScript(sql, engine).has_show_statement() == expected + + +def test_is_show_statement_unsupported_dialect() -> None: + """ + Engines without a sqlglot AST are never treated as SHOW statements, + matching the ``BaseSQLStatement`` default. + """ + statement = KustoKQLStatement("foo | take 100", "kustokql") + assert statement.is_show_statement() is False + + @pytest.mark.parametrize( "sql, denylist, expected", [