-
Notifications
You must be signed in to change notification settings - Fork 29.1k
[SPARK-14541] [SQL] SQL function: IFNULL, NULLIF, NVL and NVL2 #12373
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
Closed
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c479394
support of NULLIF()
fc144ee
forgot to remove the test line
aedcbf3
use ctx.genEqual()
93bff09
support of NVL()
de65cf4
support of IFNULL()
04a361a
support of NVL2()
1a0fae8
update the codes
451e5fb
update the codes
4e21e1a
update the docs and codes
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1014,6 +1014,40 @@ object functions { | |
| */ | ||
| def nanvl(col1: Column, col2: Column): Column = withExpr { NaNvl(col1.expr, col2.expr) } | ||
|
|
||
| /** | ||
| * Returns null if col1 equals to col2, otherwise returns col1. | ||
| * | ||
| * @group normal_funcs | ||
| * @since 2.0.0 | ||
| */ | ||
| def nullif(col1: Column, col2: Column): Column = withExpr { NullIf(col1.expr, col2.expr)} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe we don't need to add these to functions.scala. they are too sql specific |
||
|
|
||
| /** | ||
| * Returns col2 if col1 equals is null, otherwise returns col1. | ||
| * | ||
| * @group normal_funcs | ||
| * @since 2.0.0 | ||
| */ | ||
| def nvl(col1: Column, col2: Column): Column = withExpr { Nvl(col1.expr, col2.expr)} | ||
|
|
||
| /** | ||
| * Returns col2 if col1 equals is null, otherwise returns col1. Same as NVL(). | ||
| * | ||
| * @group normal_funcs | ||
| * @since 2.0.0 | ||
| */ | ||
| def ifnull(col1: Column, col2: Column): Column = withExpr { Nvl(col1.expr, col2.expr)} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. docs |
||
|
|
||
| /** | ||
| * Returns col3 if col1 equals is null, otherwise returns col2. | ||
| * | ||
| * @group normal_funcs | ||
| * @since 2.0.0 | ||
| */ | ||
| def nvl2(col1: Column, col2: Column, col3: Column): Column = withExpr { | ||
| Nvl2(col1.expr, col2.expr, col3.expr) | ||
| } | ||
|
|
||
| /** | ||
| * Unary minus, i.e. negate the expression. | ||
| * {{{ | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
isn't this just coalesce?
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 say, yes, kind of. Here is what I found: difference
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.
we should document the difference if there are any
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.
Did not notice this. I will do it shortly.