-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TECH DEBT]: Handle the precedence of the INTERSECT
set operation in the grammar(s) rather than in code
#1255
Closed
2 tasks done
Labels
antlr
Changes to any of the ANTLR g4 grammar files.
feat/ir
everything related to abstract syntax trees
sql/snowflake
sql/tsql
tech debt
design flaws and other cascading effects
Comments
3 tasks
github-merge-queue bot
pushed a commit
that referenced
this issue
Dec 4, 2024
) This PR updates the TSQL grammar and accompanying IR processing so that the precedence of `INTERSECT` is handled by the grammar instead of during transportation to our IR. Relates #1255.
github-merge-queue bot
pushed a commit
that referenced
this issue
Dec 9, 2024
…rations (#1288) This PR updates the Snowflake processing so that the precedence of `INTERSECT` is handled correctly. At present the set operations (`UNION`, `EXCEPT` and `INTERSECT`) are all handled left-to-right with equal precedence. However this is incorrect, Snowflake semantics are[^1], from highest to lowest: 1. Parenthesis 2. `INTERSECT` 3. `UNION [ALL]` and `MINUS`/`EXCEPT` At the same level operators are processed from left to right. Resolves #1255. Tests coverage: - Unit tests. - Transpiler tests. - Functional tests. Incidental changes include factoring out some of the tests that we run against TSQL so that the same tests can run against Snowflake. [^1]: Reference: https://docs.snowflake.com/en/sql-reference/operators-query
sundarshankar89
pushed a commit
to sundarshankar89/remorph
that referenced
this issue
Jan 2, 2025
…rations (databrickslabs#1288) This PR updates the Snowflake processing so that the precedence of `INTERSECT` is handled correctly. At present the set operations (`UNION`, `EXCEPT` and `INTERSECT`) are all handled left-to-right with equal precedence. However this is incorrect, Snowflake semantics are[^1], from highest to lowest: 1. Parenthesis 2. `INTERSECT` 3. `UNION [ALL]` and `MINUS`/`EXCEPT` At the same level operators are processed from left to right. Resolves databrickslabs#1255. Tests coverage: - Unit tests. - Transpiler tests. - Functional tests. Incidental changes include factoring out some of the tests that we run against TSQL so that the same tests can run against Snowflake. [^1]: Reference: https://docs.snowflake.com/en/sql-reference/operators-query
sundarshankar89
pushed a commit
to sundarshankar89/remorph
that referenced
this issue
Jan 3, 2025
…rations (databrickslabs#1288) This PR updates the Snowflake processing so that the precedence of `INTERSECT` is handled correctly. At present the set operations (`UNION`, `EXCEPT` and `INTERSECT`) are all handled left-to-right with equal precedence. However this is incorrect, Snowflake semantics are[^1], from highest to lowest: 1. Parenthesis 2. `INTERSECT` 3. `UNION [ALL]` and `MINUS`/`EXCEPT` At the same level operators are processed from left to right. Resolves databrickslabs#1255. Tests coverage: - Unit tests. - Transpiler tests. - Functional tests. Incidental changes include factoring out some of the tests that we run against TSQL so that the same tests can run against Snowflake. [^1]: Reference: https://docs.snowflake.com/en/sql-reference/operators-query
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
antlr
Changes to any of the ANTLR g4 grammar files.
feat/ir
everything related to abstract syntax trees
sql/snowflake
sql/tsql
tech debt
design flaws and other cascading effects
Current Behavior
As part of #1227 it became clear that our grammars for set operations treat
INTERSECT
,UNION
andEXCEPT
as equivalent. However it turns out thatINTERSECT
has higher precedence than the others. Although this can be dealt with in code during conversion to the IR, it would be better if this was reflected by the grammar (which also simplifies the conversion to IR).Expected Behavior
The grammars should treat
INTERSECT
as having higher precedence thanUNION
andEXCEPT
.The rules of precedence for set operations are:
INTERSECT
EXCEPT
andUNION
ordered from left-to-right.Given that
INTERSECT
is commutative, ordering is unimportant.Needs to be fixed in:
INTERSECT
with respect to other set operations #1288)References:
Relevant grammar rules:
remorph/core/src/main/antlr4/com/databricks/labs/remorph/parsers/snowflake/SnowflakeParser.g4
Lines 3154 to 3158 in 932080a
remorph/core/src/main/antlr4/com/databricks/labs/remorph/parsers/tsql/TSqlParser.g4
Lines 2796 to 2800 in 932080a
Changing the grammar will mean refactoring this code:
remorph/core/src/main/scala/com/databricks/labs/remorph/parsers/tsql/TSqlRelationBuilder.scala
Lines 79 to 134 in 932080a
The text was updated successfully, but these errors were encountered: