IMPALA-5030: [TESTS] Adds support for NVL2() function This change adds value tests to expr-test.cc to ensure that NVL2() function is rewritten correctly to IF().
Change-Id: Ide0352d611322de637a61a0004c39f5663192c52 Reviewed-on: http://gerrit.cloudera.org:8080/7000 Reviewed-by: Tim Armstrong <[email protected]> Tested-by: Impala Public Jenkins Project: http://git-wip-us.apache.org/repos/asf/incubator-impala/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-impala/commit/1b9cb04f Tree: http://git-wip-us.apache.org/repos/asf/incubator-impala/tree/1b9cb04f Diff: http://git-wip-us.apache.org/repos/asf/incubator-impala/diff/1b9cb04f Branch: refs/heads/master Commit: 1b9cb04f7997eb8f741b0708a2b2e755e8c75aed Parents: a0e3a06 Author: Vincent Tran <[email protected]> Authored: Sat May 20 07:39:04 2017 -0400 Committer: Impala Public Jenkins <[email protected]> Committed: Fri Jun 2 18:03:22 2017 +0000 ---------------------------------------------------------------------- be/src/exprs/expr-test.cc | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/1b9cb04f/be/src/exprs/expr-test.cc ---------------------------------------------------------------------- diff --git a/be/src/exprs/expr-test.cc b/be/src/exprs/expr-test.cc index 5ff26a1..dcbdeef 100644 --- a/be/src/exprs/expr-test.cc +++ b/be/src/exprs/expr-test.cc @@ -5628,6 +5628,24 @@ TEST_F(ExprTest, ConditionalFunctions) { TestTimestampValue("if(FALSE, cast('2011-01-01 09:01:01' as timestamp), " "cast('1999-06-14 19:07:25' as timestamp))", else_val); + // Test nvl2(), which is rewritten to if() before analysis. + // Returns 2nd arg if 1st arg is not NULL, otherwise it returns 3rd arg. + // Output of nvl2(x,y,z) should be identical to one of if(x is not null,y,z). + TestValue("nvl2(now(), FALSE, TRUE)", TYPE_BOOLEAN, false); + TestValue("nvl2(NULL, FALSE, TRUE)", TYPE_BOOLEAN, true); + TestValue("nvl2(now(), 10, 20)", TYPE_TINYINT, 10); + TestValue("nvl2(NULL, 10, 20)", TYPE_TINYINT, 20); + TestValue("nvl2(TRUE, cast(5.5 as double), cast(8.8 as double))", TYPE_DOUBLE, 5.5); + TestValue("nvl2(NULL, cast(5.5 as double), cast(8.8 as double))", TYPE_DOUBLE, 8.8); + TestStringValue("nvl2('some string', 'abc', 'defgh')", "abc"); + TestStringValue("nvl2(NULL, 'abc', 'defgh')", "defgh"); + TimestampValue first_val = TimestampValue::FromUnixTime(1293872461); + TimestampValue second_val = TimestampValue::FromUnixTime(929387245); + TestTimestampValue("nvl2(FALSE, cast('2011-01-01 09:01:01' as timestamp), " + "cast('1999-06-14 19:07:25' as timestamp))", first_val); + TestTimestampValue("nvl2(NULL, cast('2011-01-01 09:01:01' as timestamp), " + "cast('1999-06-14 19:07:25' as timestamp))", second_val); + // Test nullif(). Return NULL if lhs equals rhs, lhs otherwise. TestIsNull("nullif(NULL, NULL)", TYPE_BOOLEAN); TestIsNull("nullif(TRUE, TRUE)", TYPE_BOOLEAN);
