From 9ec049b88adbb3aa60b2ee30e4a1f92f880d9ddd Mon Sep 17 00:00:00 2001 From: Evan Date: Tue, 21 Jul 2026 01:09:08 -0700 Subject: [PATCH] test(trino): cover remaining branches in inline UDF parsing Adds cases for nested parens inside an `IF (...)` condition, a scalar function literally named `function` outside a routine specification, and an unbalanced `IF` condition, restoring 100% coverage on superset/sql/dialects/trino.py required by unit-tests-required. Co-Authored-By: Claude Opus 4.8 --- tests/unit_tests/sql/dialects/trino_tests.py | 43 ++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/tests/unit_tests/sql/dialects/trino_tests.py b/tests/unit_tests/sql/dialects/trino_tests.py index b5b963baf47..7e28d720485 100644 --- a/tests/unit_tests/sql/dialects/trino_tests.py +++ b/tests/unit_tests/sql/dialects/trino_tests.py @@ -285,6 +285,49 @@ def test_sqlstatement_regular_queries_unaffected() -> None: SQLStatement("SELECT * FROM", "trino") +def test_inline_udf_nested_parens_in_condition() -> None: + """ + A parenthesized ``IF`` condition containing its own nested parens must + still be recognized as a block opener, not a scalar function call. + """ + sql = """ +WITH FUNCTION classify(a bigint, b bigint) + RETURNS varchar + BEGIN + IF ((a > 100) AND (b > 100)) THEN + RETURN 'big'; + END IF; + RETURN 'small'; + END +SELECT classify(x, y) FROM some_table + """.strip() + statements = sqlglot.parse(sql, dialect=Trino) + assert len(statements) == 1 + + +def test_scalar_function_named_function() -> None: + """ + A regular scalar function call literally named ``function`` (outside a + ``CREATE``/``WITH`` routine specification) must parse normally. + """ + sql = "SELECT function(x) FROM t" + statements = sqlglot.parse(sql, dialect=Trino) + assert len(statements) == 1 + + +def test_unclosed_if_condition_raises() -> None: + """ + An ``IF`` condition with an unbalanced opening paren should fail to + parse rather than being silently misread as a block. + """ + sql = ( + "WITH FUNCTION f() RETURNS int BEGIN " + "IF (a > 1 THEN RETURN 1; END IF; RETURN 2; END SELECT 1" + ) + with pytest.raises(sqlglot.errors.ParseError): + sqlglot.parse(sql, dialect=Trino) + + def test_create_function_not_split() -> None: """ ``CREATE FUNCTION`` bodies should not be split on semicolons either.