Description
Description
While working on replacing the SqlLexer and SqlParser, I was trying to figure out the order of precedence for operators, and there is a clear inconsistency with the way the current parser handles certain operators.
Also, since we pass all the tests, our tests are also wrong and need to be fixed.
Here's a breakdown:
BETWEEN
andLIKE
have the SAME precedence as<
,>
,<=
, and>=
.BETWEEN
andLIKE
have the SAME precedence asIS
.BETWEEN
andLIKE
have HIGHER precedence thanIN
.IN
has the SAME precedence as=
,!=
, and<>
.
Now, our issue seemingly comes from IS
.
BETWEEN
andLIKE
have the SAME precedence asIS
.IS
has the SAME precedence asIN
. This doesnt' make sense becauseBETWEEN
/LIKE
have HIGHER precedence thanIN
.IS
has the SAME precedence as<
,>
,<=
, and>=
.IS
has the SAME precedence as=
,!=
, and<>
.
TLDR
So, TLDR, we have a problem with inconsistency in our grammar. This can be resolved be creating a formal precedence table.
Visual TLDR:
Textual TLDR:
- IS has the SAME precedence as BETWEEN/LIKE, but they both have different precedences in comparison to < and IN.
To Reproduce
The following shows that IS
and =
have the SAME precedence.
PartiQL> a IS BOOL = b
!!
PartiQL> a = b IS BOOL
!!
The following shows that IS
and LIKE
have the SAME precedence
PartiQL> a IS BOOL LIKE c
!!
PartiQL> a LIKE c IS BOOL
!!
The following shoes that LIKE
has HIGHER precedence than =
PartiQL> a = b LIKE c
!!
PartiQL> a LIKE b = c
!!
NOTE: You can see more inconsistencies when you use IN
and BETWEEN
also.
NOTE: When the AST is printed out with !!
, whichever operator is nested is the one with higher precedence (if you test both back and forth). If the LHS is always nested, then we can say that the two operators have equal precedence.
Why
To me, this should be prioritized. PartiQL is a language, and our basic operations don't have an established precedence yet.
To Fix
- Define a precedence table
- Fix the parser (either the old one, or just the new one)
- We need to update documentation to define a formal precedence table to convery to our customers