partiql-lang-kotlin icon indicating copy to clipboard operation
partiql-lang-kotlin copied to clipboard

Inconsistent exceptions and error messages for DML statements as arguments for EXEC

Open arahak opened this issue 3 years ago • 3 comments

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.

arahak avatar Oct 29 '21 20:10 arahak

Thanks for bringing this up. Some of the DML ParseNodes 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 DML FROM: EXEC foo FROM x WHERE a = b SET k[3] = 5
  • expressions with multiple DML statements. (this results in a DML ParseType of DML_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.

alancai98 avatar Nov 03 '21 22:11 alancai98

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

alancai98 avatar Nov 03 '21 22:11 alancai98

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.

lziq avatar Dec 17 '21 23:12 lziq