partiql-lang-kotlin
partiql-lang-kotlin copied to clipboard
Inconsistent exceptions and error messages for DML statements as arguments for EXEC
Tried passing DML statements as arguments to a system stored procedure, and got the following different errors for each:
DML INSERT
- Statement:
EXEC abc_proc INSERT INTO dogs <<{}>>
- Error:
IllegalStateException: Can't transform class org.partiql.lang.ast.DataManipulation to a PartiqlAst.expr
DML DELETE
- Statement:
EXEC abc_proc DELETE FROM dogs WHERE name = 'Jack'
- Error:
ParserException: Keyword delete only expected at the top level in the query
DML UPDATE
- Statement:
EXEC abc_proc UPDATE dogs SET dogs.name = '1'
- Error:
ParserException: Keyword null only expected at the top level in the query
DML REMOVE
- Statement:
EXEC abc_proc FROM dogs REMOVE dogs.name
- Error:
ParserException: Keyword null only expected at the top level in the query
To clarify, I was expecting all of them would return a parser exception with a clear message.
Thanks for bringing this up. Some of the DML ParseNode
s are missing the associated tokens (e.g. 'REMOVE'), which leads to the "null" in the error message. I also found some other examples where the "null" shows up in the error message. E.g.:
-
SET
following DMLFROM
:EXEC foo FROM x WHERE a = b SET k[3] = 5
- expressions with multiple DML statements. (this results in a DML
ParseType
ofDML_LIST
):EXEC abc_proc UPDATE x SET k = 5, m = 6 INSERT INTO c VALUE << 1 >> REMOVE a SET l = 3 REMOVE b WHERE a = b RETURNING MODIFIED OLD a
The fix may require some additional parser refactoring to give the clearest error message and location.
By the way, for the first example you had using INSERT INTO
, I'm not getting the IllegalStateException
that you experienced. I'm getting a parser exception like the other 3 cases:
Welcome to the PartiQL REPL!
Using version: 0.4.1-SNAPSHOT-c6e3fc6
PartiQL> EXEC abc_proc INSERT INTO dogs <<{}>>
| !!
org.partiql.lang.syntax.ParserException: Keyword insert_into only expected at the top level in the query
Parser Error: at line 1, column 15: unexpected term found, KEYWORD : insert_into
This problem is not only about using DML with exec
. The point is that we don't have a formal PartiQL grammar and make syntax checking accordingly.