You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by sa...@apache.org on 2019/08/09 04:43:42 UTC

[hive] branch master updated: HIVE-16587: NPE when inserting complex types with nested null values (Naresh P R, reviewed by Sankar Hariappan)

This is an automated email from the ASF dual-hosted git repository.

sankarh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hive.git


The following commit(s) were added to refs/heads/master by this push:
     new 96f7960  HIVE-16587: NPE when inserting complex types with nested null values (Naresh P R, reviewed by Sankar Hariappan)
96f7960 is described below

commit 96f7960c790fadb6bbc9d81fe095288241d86d8c
Author: Naresh P R <pr...@gmail.com>
AuthorDate: Mon Aug 5 23:53:11 2019 +0530

    HIVE-16587: NPE when inserting complex types with nested null values (Naresh P R, reviewed by Sankar Hariappan)
    
    Signed-off-by: Sankar Hariappan <sa...@apache.org>
---
 .../test/resources/testconfiguration.properties    |  3 +-
 .../apache/hadoop/hive/ql/stats/StatsUtils.java    |  4 +-
 .../clientpositive/tez_complextype_with_null.q     | 15 +++++++
 .../tez/tez_complextype_with_null.q.out            | 50 ++++++++++++++++++++++
 4 files changed, 69 insertions(+), 3 deletions(-)

diff --git a/itests/src/test/resources/testconfiguration.properties b/itests/src/test/resources/testconfiguration.properties
index f390dc5..84c20426 100644
--- a/itests/src/test/resources/testconfiguration.properties
+++ b/itests/src/test/resources/testconfiguration.properties
@@ -42,7 +42,8 @@ minitez.query.files=acid_vectorization_original_tez.q,\
   multi_count_distinct.q,\
   tez-tag.q,\
   tez_union_with_udf.q,\
-  tez_union_udtf.q
+  tez_union_udtf.q,\
+  tez_complextype_with_null.q
 
 
 minillap.shared.query.files=insert_into1.q,\
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/stats/StatsUtils.java b/ql/src/java/org/apache/hadoop/hive/ql/stats/StatsUtils.java
index e0f401b..1795ae5 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/stats/StatsUtils.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/stats/StatsUtils.java
@@ -1345,11 +1345,11 @@ public class StatsUtils {
     if (oi instanceof WritableStringObjectInspector) {
       WritableStringObjectInspector woi = (WritableStringObjectInspector) oi;
       return JavaDataModel.get().lengthForStringOfLength(
-          woi.getPrimitiveWritableObject(value).getLength());
+        value == null ? 0 : woi.getPrimitiveWritableObject(value).getLength());
     } else if (oi instanceof WritableBinaryObjectInspector) {
       WritableBinaryObjectInspector woi = (WritableBinaryObjectInspector) oi;
       return JavaDataModel.get().lengthForByteArrayOfSize(
-          woi.getPrimitiveWritableObject(value).getLength());
+        value == null ? 0 : woi.getPrimitiveWritableObject(value).getLength());
     } else if (oi instanceof WritableBooleanObjectInspector) {
       return JavaDataModel.get().primitive1();
     } else if (oi instanceof WritableByteObjectInspector) {
diff --git a/ql/src/test/queries/clientpositive/tez_complextype_with_null.q b/ql/src/test/queries/clientpositive/tez_complextype_with_null.q
new file mode 100644
index 0000000..7a0f240
--- /dev/null
+++ b/ql/src/test/queries/clientpositive/tez_complextype_with_null.q
@@ -0,0 +1,15 @@
+CREATE TABLE complex1 (
+    c0 int,
+    c1 array<int>,
+    c2 map<int, string>,
+    c3 struct<f1:int,f2:string,f3:array<int>>,
+    c4 array<struct<f1:int,f2:string,f3:array<int>>>);
+
+INSERT INTO complex1
+    SELECT 3,
+       array(1, 2, null),
+       map(1, 'one', 2, null),
+       named_struct('f1', cast(null as int), 'f2', cast(null as string), 'f3', array(1, 2, null)),
+       array(named_struct('f1', 11, 'f2', 'two', 'f3', array(2, 3, 4)));
+
+select * from complex1;
diff --git a/ql/src/test/results/clientpositive/tez/tez_complextype_with_null.q.out b/ql/src/test/results/clientpositive/tez/tez_complextype_with_null.q.out
new file mode 100644
index 0000000..f20151d
--- /dev/null
+++ b/ql/src/test/results/clientpositive/tez/tez_complextype_with_null.q.out
@@ -0,0 +1,50 @@
+PREHOOK: query: CREATE TABLE complex1 (
+    c0 int,
+    c1 array<int>,
+    c2 map<int, string>,
+    c3 struct<f1:int,f2:string,f3:array<int>>,
+    c4 array<struct<f1:int,f2:string,f3:array<int>>>)
+PREHOOK: type: CREATETABLE
+PREHOOK: Output: database:default
+PREHOOK: Output: default@complex1
+POSTHOOK: query: CREATE TABLE complex1 (
+    c0 int,
+    c1 array<int>,
+    c2 map<int, string>,
+    c3 struct<f1:int,f2:string,f3:array<int>>,
+    c4 array<struct<f1:int,f2:string,f3:array<int>>>)
+POSTHOOK: type: CREATETABLE
+POSTHOOK: Output: database:default
+POSTHOOK: Output: default@complex1
+PREHOOK: query: INSERT INTO complex1
+    SELECT 3,
+       array(1, 2, null),
+       map(1, 'one', 2, null),
+       named_struct('f1', cast(null as int), 'f2', cast(null as string), 'f3', array(1, 2, null)),
+       array(named_struct('f1', 11, 'f2', 'two', 'f3', array(2, 3, 4)))
+PREHOOK: type: QUERY
+PREHOOK: Input: _dummy_database@_dummy_table
+PREHOOK: Output: default@complex1
+POSTHOOK: query: INSERT INTO complex1
+    SELECT 3,
+       array(1, 2, null),
+       map(1, 'one', 2, null),
+       named_struct('f1', cast(null as int), 'f2', cast(null as string), 'f3', array(1, 2, null)),
+       array(named_struct('f1', 11, 'f2', 'two', 'f3', array(2, 3, 4)))
+POSTHOOK: type: QUERY
+POSTHOOK: Input: _dummy_database@_dummy_table
+POSTHOOK: Output: default@complex1
+POSTHOOK: Lineage: complex1.c0 SIMPLE []
+POSTHOOK: Lineage: complex1.c1 EXPRESSION []
+POSTHOOK: Lineage: complex1.c2 EXPRESSION []
+POSTHOOK: Lineage: complex1.c3 EXPRESSION []
+POSTHOOK: Lineage: complex1.c4 EXPRESSION []
+PREHOOK: query: select * from complex1
+PREHOOK: type: QUERY
+PREHOOK: Input: default@complex1
+PREHOOK: Output: hdfs://### HDFS PATH ###
+POSTHOOK: query: select * from complex1
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@complex1
+POSTHOOK: Output: hdfs://### HDFS PATH ###
+3	[1,2,null]	{1:"one",2:null}	{"f1":null,"f2":null,"f3":[1,2,null]}	[{"f1":11,"f2":"two","f3":[2,3,4]}]