-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-17753][SQL] Allow a complex expression as the input a value based case statement #15322
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
Conversation
|
Thank you for pinging me! |
|
@hvanhovell , it looks great. Most of cases are passed. I'm wondering if we can support the following, too? sql("SELECT CASE 'a'='a' WHEN TRUE THEN 1 END").showSince the followings are passed, the above one is a minor one. sql("SELECT CASE ('a'='a') WHEN TRUE THEN 1 END").show
sql("SELECT CASE 1=1 WHEN TRUE THEN 1 END").show
sql("SELECT CASE 1='a' WHEN TRUE THEN 1 END").show |
|
Test build #66232 has finished for PR 15322 at commit
|
|
@dongjoon-hyun I had to move a few rules around to get your example working. It was hitting the |
|
Ah, that was the reason. Thank you so much, @hvanhovell . |
|
Test build #66246 has finished for PR 15322 at commit
|
| CaseKeyWhen('a, Seq(1, 'b, 2, 'c, 'd))) | ||
| assertEqual("case (a or b) when true then c when false then d else e end", | ||
| CaseKeyWhen('a || 'b, Seq(true, 'c, false, 'd, 'e))) | ||
| assertEqual("case 'a'='a' when true then 1 end", |
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.
nit: seems 'a'='a' is a valueExpression? So it should be passed even without this change.
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.
Yeah, I thought the same thing. The issue here is that case 'a' also matches the typeConstructor rule which was triggered before the simpleCase rule. So I also fixed this by moving the rules around a bit more.
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.
oh, I see. Currently the first element in typeConstructor is an identifier. Is it too loose?
|
LGTM except a minor comment. |
|
Merging to master/2.0. Thanks for the reviews! |
…sed case statement ## What changes were proposed in this pull request? We currently only allow relatively simple expressions as the input for a value based case statement. Expressions like `case (a > 1) or (b = 2) when true then 1 when false then 0 end` currently fail. This PR adds support for such expressions. ## How was this patch tested? Added a test to the ExpressionParserSuite. Author: Herman van Hovell <hvanhovell@databricks.com> Closes #15322 from hvanhovell/SPARK-17753. (cherry picked from commit 2bbecde) Signed-off-by: Herman van Hovell <hvanhovell@databricks.com>
What changes were proposed in this pull request?
We currently only allow relatively simple expressions as the input for a value based case statement. Expressions like
case (a > 1) or (b = 2) when true then 1 when false then 0 endcurrently fail. This PR adds support for such expressions.How was this patch tested?
Added a test to the ExpressionParserSuite.