[SPARK-14541] [SQL] SQL function: IFNULL, NULLIF, NVL and NVL2#12373
[SPARK-14541] [SQL] SQL function: IFNULL, NULLIF, NVL and NVL2#12373bomeng wants to merge 9 commits intoapache:masterfrom bomeng:SPARK-14541
Conversation
|
Test build #55758 has finished for PR 12373 at commit
|
|
Test build #55773 has finished for PR 12373 at commit
|
|
|
||
| override def genCode(ctx: CodegenContext, ev: ExprCode): String = { | ||
| val leftGen = left.gen(ctx) | ||
| val rightGen = right.gen(ctx) |
There was a problem hiding this comment.
We have CodegenContext.genEqual to generate codes for equality check. You can see how EqualTo expression uses it.
There was a problem hiding this comment.
Thanks, @viirya ! That simplifies the logic!
|
Test build #55786 has finished for PR 12373 at commit
|
|
Test build #55832 has finished for PR 12373 at commit
|
|
Test build #55845 has finished for PR 12373 at commit
|
|
Test build #55850 has finished for PR 12373 at commit
|
| * @group normal_funcs | ||
| * @since 2.0.0 | ||
| */ | ||
| def nvl(col1: Column, col2: Column): Column = withExpr { Nvl(col1.expr, col2.expr)} |
|
Also can you remove the "JIRA related" section from the description? It is redundant with the title when makes into the commit message. |
|
I will address these issues tomorrow! Thank you all! |
|
I have revisited the codes and made the codes more robust. Heavily tested against different data types by introducing testAllTypes2Values() with 2 different values. PR description was updated. Javadoc was fixed. Please leave comments! |
|
Test build #55947 has finished for PR 12373 at commit
|
|
Test build #55948 has finished for PR 12373 at commit
|
|
I added #13084 I thought about it more -- since it is unclear how often people will actually use these functions, it's probably not worth following strictly the corner case behaviors in Oracle/MSSQL. I created a new small framework that allows replacing the expressions at runtime with existing expressions, so we don't need to re-implement codegen. |
## What changes were proposed in this pull request? This patch adds support for a few SQL functions to improve compatibility with other databases: IFNULL, NULLIF, NVL and NVL2. In order to do this, this patch introduced a RuntimeReplaceable expression trait that allows replacing an unevaluable expression in the optimizer before evaluation. Note that the semantics are not completely identical to other databases in esoteric cases. ## How was this patch tested? Added a new test suite SQLCompatibilityFunctionSuite. Closes #12373. Author: Reynold Xin <rxin@databricks.com> Closes #13084 from rxin/SPARK-14541. (cherry picked from commit eda2800) Signed-off-by: Yin Huai <yhuai@databricks.com>
What changes were proposed in this pull request?
I am trying to implement functions
NULLIFin this PR. The meaning of NULLIF can be found here:NULLIF( )
NVL( ) / IFNULL( )
IFNULL()andNVL()are the same.NVL2( )
How was this patch tested?
Test cases were added.