-
Notifications
You must be signed in to change notification settings - Fork 28.4k
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
[SPARK-50449][SQL] Fix SQL Scripting grammar allowing empty bodies for loops, IF and CASE #48989
base: master
Are you sure you want to change the base?
[SPARK-50449][SQL] Fix SQL Scripting grammar allowing empty bodies for loops, IF and CASE #48989
Conversation
condition = "PARSE_SYNTAX_ERROR", | ||
parameters = Map("error" -> "'LOOP'", "hint" -> "")) | ||
} | ||
|
||
test("loop with if else block") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it also make sense to add test with for with empty body, in this PR or your other one, depending on which you merge first?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I will add it to the one which gets merged last, or if they both get merged then I will create a separate PR.
@@ -623,6 +652,21 @@ class SqlScriptingParserSuite extends SparkFunSuite with SQLHelper { | |||
assert(whileStmt.label.contains("lbl")) | |||
} | |||
|
|||
test("while with empty body") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we also add test like the one in PR description:
WHILE 1=1 DO
BEGIN
END;
END WHILE;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will add that one in the follow up PR, as that case is still not fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dusantism-db Could you open an JIRA and prepend it to PR's title, please.
@MaxGekk done |
What changes were proposed in this pull request?
Before this PR, SQL Scripting grammar allowed for loops, IF and CASE to have empty bodies. Example:
WHILE 1 = 1 DO END WHILE;
If they have an empty body, an internal error is thrown during execution. This PR changes the grammar so that loops, IF and CASE must have at least one statement in their bodies.
Note that this does not completely fix the internal error issue. It is still possible to have something like
where the same error is still thrown, except this construct is correct grammar wise.
This issue will be fixed by a separate PR, as non-trivial interpreter logic changes are required.
Why are the changes needed?
The existing grammar was wrong.
Does this PR introduce any user-facing change?
No.
How was this patch tested?
Unit tests that make sure parsing loops, IF and CASE with empty bodies throws an error.
Was this patch authored or co-authored using generative AI tooling?
No.