-
Notifications
You must be signed in to change notification settings - Fork 28.5k
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-7321][SQL] Add Column expression for conditional statements (when/otherwise) #6072
Conversation
[SPARK-7321][SQL] Add Column expression for conditional statements
Merged build triggered. |
Merged build started. |
Merged build triggered. |
Merged build started. |
Test build #32464 has started for PR 6072 at commit |
Merged build finished. Test FAILed. |
Test FAILed. |
Jenkins, retest this please. |
Merged build triggered. |
Merged build started. |
Test build #32466 has started for PR 6072 at commit |
How about "case key when" syntax? Like "CASE a WHEN b THEN c [WHEN d THEN e]* [ELSE f] END" in SQL and |
the one you suggested is more like switch function in C/Java. The one here is just general if/else. We should add that one too, but in separate PR. |
Test build #32464 has finished for PR 6072 at commit
|
Merged build finished. Test PASSed. |
Test PASSed. |
Test build #32466 has finished for PR 6072 at commit
|
Merged build finished. Test PASSed. |
Test PASSed. |
*/ | ||
def otherwise(value: Any):Column = this.expr match { | ||
case CaseWhen(branches: Seq[Expression]) => | ||
CaseWhen(branches :+ lit(value).expr) |
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.
What if user mistakenly call otherwise
twice? Then we will build a wrong CaseWhen
expression here. Maybe we should create a helper class like what we did for NA functions and aggregate functions?
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.
Good point. It is too heavy weight to have a whole class dedicated to this, but I will add code to throw exceptions if otherwise has been applied previously.
Merged build triggered. |
Merged build started. |
Test build #32525 has started for PR 6072 at commit |
Test build #32525 timed out for PR 6072 at commit |
Merged build finished. Test FAILed. |
Test FAILed. |
Jenkins, retest this please. |
Merged build triggered. |
Merged build started. |
Test build #32542 has started for PR 6072 at commit |
Test build #32542 has finished for PR 6072 at commit
|
Merged build finished. Test FAILed. |
Test FAILed. |
Jenkins, retest this please. |
Merged build triggered. |
Merged build started. |
Test build #32557 has started for PR 6072 at commit |
Test build #32557 has finished for PR 6072 at commit
|
Merged build finished. Test PASSed. |
Test PASSed. |
…hen/otherwise) This builds on #5932 and should close #5932 as well. As an example: ```python df.select(when(df['age'] == 2, 3).otherwise(4).alias("age")).collect() ``` Author: Reynold Xin <[email protected]> Author: kaka1992 <[email protected]> Closes #6072 from rxin/when-expr and squashes the following commits: 8f49201 [Reynold Xin] Throw exception if otherwise is applied twice. 0455eda [Reynold Xin] Reset run-tests. bfb9d9f [Reynold Xin] Updated documentation and test cases. 762f6a5 [Reynold Xin] Merge pull request #5932 from kaka1992/IFCASE 95724c6 [kaka1992] Update 8218d0a [kaka1992] Update 801009e [kaka1992] Update 76d6346 [kaka1992] [SPARK-7321][SQL] Add Column expression for conditional statements (if, case) (cherry picked from commit 97dee31) Signed-off-by: Reynold Xin <[email protected]>
…hen/otherwise) This builds on apache#5932 and should close apache#5932 as well. As an example: ```python df.select(when(df['age'] == 2, 3).otherwise(4).alias("age")).collect() ``` Author: Reynold Xin <[email protected]> Author: kaka1992 <[email protected]> Closes apache#6072 from rxin/when-expr and squashes the following commits: 8f49201 [Reynold Xin] Throw exception if otherwise is applied twice. 0455eda [Reynold Xin] Reset run-tests. bfb9d9f [Reynold Xin] Updated documentation and test cases. 762f6a5 [Reynold Xin] Merge pull request apache#5932 from kaka1992/IFCASE 95724c6 [kaka1992] Update 8218d0a [kaka1992] Update 801009e [kaka1992] Update 76d6346 [kaka1992] [SPARK-7321][SQL] Add Column expression for conditional statements (if, case)
…hen/otherwise) This builds on apache#5932 and should close apache#5932 as well. As an example: ```python df.select(when(df['age'] == 2, 3).otherwise(4).alias("age")).collect() ``` Author: Reynold Xin <[email protected]> Author: kaka1992 <[email protected]> Closes apache#6072 from rxin/when-expr and squashes the following commits: 8f49201 [Reynold Xin] Throw exception if otherwise is applied twice. 0455eda [Reynold Xin] Reset run-tests. bfb9d9f [Reynold Xin] Updated documentation and test cases. 762f6a5 [Reynold Xin] Merge pull request apache#5932 from kaka1992/IFCASE 95724c6 [kaka1992] Update 8218d0a [kaka1992] Update 801009e [kaka1992] Update 76d6346 [kaka1992] [SPARK-7321][SQL] Add Column expression for conditional statements (if, case)
…hen/otherwise) This builds on apache#5932 and should close apache#5932 as well. As an example: ```python df.select(when(df['age'] == 2, 3).otherwise(4).alias("age")).collect() ``` Author: Reynold Xin <[email protected]> Author: kaka1992 <[email protected]> Closes apache#6072 from rxin/when-expr and squashes the following commits: 8f49201 [Reynold Xin] Throw exception if otherwise is applied twice. 0455eda [Reynold Xin] Reset run-tests. bfb9d9f [Reynold Xin] Updated documentation and test cases. 762f6a5 [Reynold Xin] Merge pull request apache#5932 from kaka1992/IFCASE 95724c6 [kaka1992] Update 8218d0a [kaka1992] Update 801009e [kaka1992] Update 76d6346 [kaka1992] [SPARK-7321][SQL] Add Column expression for conditional statements (if, case)
This builds on #5932 and should close #5932 as well.
As an example: