Add support for EXECUTE IMMEDIATE statement#17341
Conversation
|
I posed some syntax comments in the issue: #17353 |
core/trino-main/src/main/java/io/trino/execution/QueryPreparer.java
Outdated
Show resolved
Hide resolved
core/trino-main/src/main/java/io/trino/execution/QueryPreparer.java
Outdated
Show resolved
Hide resolved
...ng/trino-product-tests/src/main/java/io/trino/tests/product/jdbc/TestPreparedStatements.java
Outdated
Show resolved
Hide resolved
core/trino-parser/src/main/java/io/trino/sql/tree/ExecuteImmediate.java
Outdated
Show resolved
Hide resolved
core/trino-main/src/main/java/io/trino/execution/QueryPreparer.java
Outdated
Show resolved
Hide resolved
6d80305 to
f1e0f26
Compare
There was a problem hiding this comment.
No need for a separate variable for this. Inline it below.
There was a problem hiding this comment.
Also, this won't work for a test such as this, as it only handles parsing errors:
assertTrinoExceptionThrownBy(() -> assertions.query("EXECUTE IMMEDIATE 'SELECT * FROM tiny.tpch.orders'"))
.hasMessageMatching("line 1:34: Catalog 'tiny' does not exist");
There was a problem hiding this comment.
If the SqlParser could take a "relative start position", it would solve both issues:
- parsing exceptions would have the correct location,
- the created AST would have the correct locations, so the Analyzer errors would be positioned correctly, too.
There was a problem hiding this comment.
Also, this won't work for a test such as this, as it only handles parsing errors:
BTW @martint we have the same problem with EXECUTE:
trino> prepare test from select * from foo;
PREPARE
trino> execute test;
Query 20230510_184850_00010_fczhd failed: line 3:3: Schema must be specified when session schema is not set
It's even worse, as the line/column in error message refer to how the statement was formatter by the SqlFormatter, not to how it was originally written by the user.
Probably in this case we should skip the position altogether, or place it at the beginning of the EXECUTE statement, or maybe include the executed statement in the message to gie context for the error.
core/trino-parser/src/main/java/io/trino/sql/parser/AstBuilder.java
Outdated
Show resolved
Hide resolved
core/trino-parser/src/main/java/io/trino/sql/tree/ExecuteImmediate.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
If the SqlParser could take a "relative start position", it would solve both issues:
- parsing exceptions would have the correct location,
- the created AST would have the correct locations, so the Analyzer errors would be positioned correctly, too.
There was a problem hiding this comment.
Also, this won't work for a test such as this, as it only handles parsing errors:
BTW @martint we have the same problem with EXECUTE:
trino> prepare test from select * from foo;
PREPARE
trino> execute test;
Query 20230510_184850_00010_fczhd failed: line 3:3: Schema must be specified when session schema is not set
It's even worse, as the line/column in error message refer to how the statement was formatter by the SqlFormatter, not to how it was originally written by the user.
Probably in this case we should skip the position altogether, or place it at the beginning of the EXECUTE statement, or maybe include the executed statement in the message to gie context for the error.
core/trino-parser/src/main/java/io/trino/sql/parser/AstBuilder.java
Outdated
Show resolved
Hide resolved
core/trino-parser/src/main/java/io/trino/sql/parser/SqlParser.java
Outdated
Show resolved
Hide resolved
core/trino-main/src/main/java/io/trino/execution/QueryPreparer.java
Outdated
Show resolved
Hide resolved
core/trino-parser/src/main/java/io/trino/sql/parser/AstBuilder.java
Outdated
Show resolved
Hide resolved
core/trino-parser/src/main/java/io/trino/sql/parser/AstBuilder.java
Outdated
Show resolved
Hide resolved
core/trino-parser/src/main/java/io/trino/sql/parser/SqlParser.java
Outdated
Show resolved
Hide resolved
...ng/trino-product-tests/src/main/java/io/trino/tests/product/jdbc/TestPreparedStatements.java
Outdated
Show resolved
Hide resolved
core/trino-parser/src/main/java/io/trino/sql/tree/ExecuteImmediate.java
Outdated
Show resolved
Hide resolved
core/trino-parser/src/main/java/io/trino/sql/tree/ExecuteImmediate.java
Outdated
Show resolved
Hide resolved
core/trino-parser/src/main/java/io/trino/sql/tree/ExecuteImmediate.java
Outdated
Show resolved
Hide resolved
core/trino-parser/src/main/java/io/trino/sql/tree/ExecuteImmediate.java
Outdated
Show resolved
Hide resolved
Syntax: EXECUTE IMMEDIATE 'SELECT * FROM t WHERE a = ? and b = ?' USING 'foo', 42 The semantics are the same as: PREPARE stmt1 FROM SELECT * FROM t WHERE a = ? and b = ? EXECUTE stmt1 USING 'foo', 42 DEALLOCATE PREPARE stmt1
Description
Fixes #17353
Syntax:
The semantics are the same as:
Additional context and related issues
Release notes
(x) Release notes are required, with the following suggested text: