mirror of
https://github.com/apache/superset.git
synced 2026-07-26 16:42:32 +00:00
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 <noreply@anthropic.com>
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user