Open kevinjqliu opened 7 months ago
Thank you for filing this @kevinjqliu !
DBeaver has a similar problem. I expect multiple clients will fall over this problem since they assume ; to be the end of a statement..
For functions however it would be the END or the function for inline function (see your example
or for CREATE FUNCTION usage the END;
If anyone needs help with this logic.. ping me
Btw here is the logic to figure out the details from the Trino CLI https://github.com/trinodb/trino/blob/master/client/trino-cli/src/main/java/io/trino/cli/lexer/StatementSplitter.java
@betodealmeida do you think the sqlglot migration would help at all with this sort of issue?
Seems like sqlglot can help solve this issue.
It doesn't work out of the box though.
from sqlglot import parse
sql = """FUNCTION simple_case(a bigint)
RETURNS varchar
BEGIN
CASE a
WHEN 0 THEN RETURN 'zero';
WHEN 1 THEN RETURN 'one';
ELSE RETURN 'more than one or negative';
END CASE;
RETURN NULL;
END
"""
parse(sql, dialect='trino')
Returns an error
sqlglot.errors.ParseError: Invalid expression / Unexpected token. Line 1, Col: 21.
FUNCTION simple_case(a bigint)
RETURNS varchar
BEGIN
CASE a
WHEN 0 THEN RETURN 'zero';
WHEN 1 THEN RE
Even if this is not supported by sqlglot it should work in Superset as is — at least if DML is enabled. Let me take a look.
Superset SQL Lab Editor cannot run Trino SQL routines which have multiple
;
statements.How to reproduce the bug
;
characters, such as this one from example docsExpected results
SQL Routine to run successfully and return
0
Actual results
Website error message:
Superset Error message:
Screenshots
Environment
(please complete the following information):
Chrome Version 119.0.6045.159 (Official Build) (arm64)
3.0.1
Python 3.9.18
Checklist
Make sure to follow these steps before submitting your issue - thank you!
Additional context
I was able to track this down to the SQL statement parsing logic. Specifically, the
db_engine_spec.run_multiple_statements_as_one
variable is used to determine whether to parse SQL with;
characters into multiple SQL statements. TheTrinoEngineSpec
andPrestoBaseEngineSpec
both do not include this variable. Sorun_multiple_statements_as_one
is set toFalse
by theBaseEngineSpec
.I was able to set
run_multiple_statements_as_one
toTrue
inTrinoEngineSpec
and got the SQL above to work. However, this changes the default behavior of SQL Lab for Trino which allows running multiple SQL statements separated by;
.