IMPALA-5580: fix Java UDFs that return NULL strings In commit 741421de, we accidently made it so that is_null=true StringVals became is_null=false with len=0. Fix that and add a regression test.
Change-Id: I34d288aad66a2609484058c9a177c02200cb6a6e Reviewed-on: http://gerrit.cloudera.org:8080/7364 Reviewed-by: Bharath Vissapragada <[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/924066a4 Tree: http://git-wip-us.apache.org/repos/asf/incubator-impala/tree/924066a4 Diff: http://git-wip-us.apache.org/repos/asf/incubator-impala/diff/924066a4 Branch: refs/heads/master Commit: 924066a4fa554bf8d61a429d0c6d0a55ddd9e2ff Parents: 9037b8e Author: Dan Hecht <[email protected]> Authored: Thu Jul 6 13:49:53 2017 -0700 Committer: Impala Public Jenkins <[email protected]> Committed: Fri Jul 7 01:30:59 2017 +0000 ---------------------------------------------------------------------- be/src/exprs/hive-udf-call.cc | 1 + .../queries/QueryTest/java-udf.test | 58 +++++++++----------- 2 files changed, 28 insertions(+), 31 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/924066a4/be/src/exprs/hive-udf-call.cc ---------------------------------------------------------------------- diff --git a/be/src/exprs/hive-udf-call.cc b/be/src/exprs/hive-udf-call.cc index ae0a407..3e071bf 100644 --- a/be/src/exprs/hive-udf-call.cc +++ b/be/src/exprs/hive-udf-call.cc @@ -327,6 +327,7 @@ StringVal HiveUdfCall::GetStringVal( ScalarExprEvaluator* eval, const TupleRow* row) const { DCHECK_EQ(type_.type, TYPE_STRING); StringVal result = *reinterpret_cast<StringVal*>(Evaluate(eval, row)); + if (result.is_null) return StringVal::null(); // Copy the string into a local allocation with the usual lifetime for expr results. // Needed because the UDF output buffer is owned by the Java UDF executor and may be // freed or reused by the next call into the Java UDF executor. http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/924066a4/testdata/workloads/functional-query/queries/QueryTest/java-udf.test ---------------------------------------------------------------------- diff --git a/testdata/workloads/functional-query/queries/QueryTest/java-udf.test b/testdata/workloads/functional-query/queries/QueryTest/java-udf.test index c4e2f1c..6f256f0 100644 --- a/testdata/workloads/functional-query/queries/QueryTest/java-udf.test +++ b/testdata/workloads/functional-query/queries/QueryTest/java-udf.test @@ -22,71 +22,67 @@ DOUBLE ==== ---- QUERY # Test identity functions -select identity(true); +select identity(true), identity(cast(NULL as boolean)); ---- TYPES -boolean +boolean, boolean ---- RESULTS -true +true,NULL ==== ---- QUERY -select identity(cast(10 as tinyint)); +select identity(cast(10 as tinyint)), identity(cast(NULL as tinyint)); ---- TYPES -tinyint +tinyint, tinyint ---- RESULTS -10 +10,NULL ==== ---- QUERY -select identity(cast(10 as smallint)); +select identity(cast(10 as smallint)), identity(cast(NULL as smallint)); ---- TYPES -smallint +smallint, smallint ---- RESULTS -10 +10,NULL ==== ---- QUERY -select identity(cast(10 as int)); +select identity(cast(10 as int)), identity(cast(NULL as int)); ---- TYPES -int +int, int ---- RESULTS -10 +10,NULL ==== ---- QUERY -select identity(cast(10 as bigint)); +select identity(cast(10 as bigint)), identity(cast(NULL as bigint)); ---- TYPES -bigint +bigint, bigint ---- RESULTS -10 +10,NULL ==== ---- QUERY -select identity(cast(10.0 as float)); +select identity(cast(10.0 as float)), identity(cast(NULL as float)); ---- TYPES -float +float, float ---- RESULTS -10 +10,NULL ==== ---- QUERY -select identity(cast(10.0 as double)); +select identity(cast(10.0 as double)), identity(cast(NULL as double)); ---- TYPES -double +double, double ---- RESULTS -10 +10,NULL ==== ---- QUERY # IMPALA-1456. Each "identity" call below tests a different type (BytesWritable, Text, # and String). select identity("why hello there"), identity("why", " hello there"), - identity("why", " hello", " there"); ----- TYPES -string, string, string ----- RESULTS -'why hello there','why hello there','why hello there' -==== ----- QUERY -select identity(NULL); + identity("why", " hello", " there"), + identity(cast(NULL as string)), + identity(cast(NULL as string), cast(NULL as string)), + identity(cast(NULL as string), cast(NULL as string), cast(NULL as string)); ---- TYPES -boolean +string, string, string, string, string, string ---- RESULTS -NULL +'why hello there','why hello there','why hello there','NULL','NULL','NULL' ==== ---- QUERY # IMPALA-1134. Each "identity" call below tests a different type (BytesWritable, Text,
