You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by kg...@apache.org on 2020/07/13 08:46:26 UTC
[hive] branch master updated: HIVE-22412: StatsUtils throw NPE when
explain (#1209) (xiepengjie reviewed by David Mollitor and Zoltan
Haindrich)
This is an automated email from the ASF dual-hosted git repository.
kgyrtkirk 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 5a54752 HIVE-22412: StatsUtils throw NPE when explain (#1209) (xiepengjie reviewed by David Mollitor and Zoltan Haindrich)
5a54752 is described below
commit 5a54752f8f1964b266a25a47f3d05d894806dc78
Author: Jeff.r <st...@126.com>
AuthorDate: Mon Jul 13 16:46:09 2020 +0800
HIVE-22412: StatsUtils throw NPE when explain (#1209) (xiepengjie reviewed by David Mollitor and Zoltan Haindrich)
---
.../apache/hadoop/hive/ql/stats/StatsUtils.java | 10 +-
ql/src/test/queries/clientpositive/analyze_npe.q | 26 +++
.../results/clientpositive/llap/analyze_npe.q.out | 215 +++++++++++++++++++++
.../StandardConstantMapObjectInspector.java | 4 +-
4 files changed, 252 insertions(+), 3 deletions(-)
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 9b160dd..962b131 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
@@ -1182,7 +1182,12 @@ public class StatsUtils {
// constant list projection of known length
StandardConstantListObjectInspector scloi = (StandardConstantListObjectInspector) oi;
- length = scloi.getWritableConstantValue().size();
+ List<?> value = scloi.getWritableConstantValue();
+ if (null == value) {
+ length = 0;
+ } else {
+ length = value.size();
+ }
// check if list elements are primitive or Objects
ObjectInspector leoi = scloi.getListElementObjectInspector();
@@ -1336,6 +1341,9 @@ public class StatsUtils {
*/
public static long getSizeOfMap(StandardConstantMapObjectInspector scmoi) {
Map<?, ?> map = scmoi.getWritableConstantValue();
+ if (null == map) {
+ return 0L;
+ }
ObjectInspector koi = scmoi.getMapKeyObjectInspector();
ObjectInspector voi = scmoi.getMapValueObjectInspector();
long result = 0;
diff --git a/ql/src/test/queries/clientpositive/analyze_npe.q b/ql/src/test/queries/clientpositive/analyze_npe.q
new file mode 100644
index 0000000..e7cfea0
--- /dev/null
+++ b/ql/src/test/queries/clientpositive/analyze_npe.q
@@ -0,0 +1,26 @@
+drop table if exists explain_npe_map;
+drop table if exists explain_npe_array;
+drop table if exists explain_npe_struct;
+
+create table explain_npe_map ( c1 map<string, string> );
+create table explain_npe_array ( c1 array<string> );
+create table explain_npe_struct ( c1 struct<name:string, age:int> );
+
+-- error
+set hive.cbo.enable=false;
+explain select c1 from explain_npe_map where c1 is null;
+explain select c1 from explain_npe_array where c1 is null;
+-- maybe correct in branch of master,
+-- but i think it is necessary to initialize the value of StandardConstantStructObjectInspector
+explain select c1 from explain_npe_struct where c1 is null;
+
+-- correct
+set hive.cbo.enable=true;
+explain select c1 from explain_npe_map where c1 is null;
+explain select c1 from explain_npe_array where c1 is null;
+explain select c1 from explain_npe_struct where c1 is null;
+
+-- drop test table
+drop table if exists explain_npe_map;
+drop table if exists explain_npe_array;
+drop table if exists explain_npe_struct;
\ No newline at end of file
diff --git a/ql/src/test/results/clientpositive/llap/analyze_npe.q.out b/ql/src/test/results/clientpositive/llap/analyze_npe.q.out
new file mode 100644
index 0000000..f532295
--- /dev/null
+++ b/ql/src/test/results/clientpositive/llap/analyze_npe.q.out
@@ -0,0 +1,215 @@
+PREHOOK: query: drop table if exists explain_npe_map
+PREHOOK: type: DROPTABLE
+POSTHOOK: query: drop table if exists explain_npe_map
+POSTHOOK: type: DROPTABLE
+PREHOOK: query: drop table if exists explain_npe_array
+PREHOOK: type: DROPTABLE
+POSTHOOK: query: drop table if exists explain_npe_array
+POSTHOOK: type: DROPTABLE
+PREHOOK: query: drop table if exists explain_npe_struct
+PREHOOK: type: DROPTABLE
+POSTHOOK: query: drop table if exists explain_npe_struct
+POSTHOOK: type: DROPTABLE
+PREHOOK: query: create table explain_npe_map ( c1 map<string, string> )
+PREHOOK: type: CREATETABLE
+PREHOOK: Output: database:default
+PREHOOK: Output: default@explain_npe_map
+POSTHOOK: query: create table explain_npe_map ( c1 map<string, string> )
+POSTHOOK: type: CREATETABLE
+POSTHOOK: Output: database:default
+POSTHOOK: Output: default@explain_npe_map
+PREHOOK: query: create table explain_npe_array ( c1 array<string> )
+PREHOOK: type: CREATETABLE
+PREHOOK: Output: database:default
+PREHOOK: Output: default@explain_npe_array
+POSTHOOK: query: create table explain_npe_array ( c1 array<string> )
+POSTHOOK: type: CREATETABLE
+POSTHOOK: Output: database:default
+POSTHOOK: Output: default@explain_npe_array
+PREHOOK: query: create table explain_npe_struct ( c1 struct<name:string, age:int> )
+PREHOOK: type: CREATETABLE
+PREHOOK: Output: database:default
+PREHOOK: Output: default@explain_npe_struct
+POSTHOOK: query: create table explain_npe_struct ( c1 struct<name:string, age:int> )
+POSTHOOK: type: CREATETABLE
+POSTHOOK: Output: database:default
+POSTHOOK: Output: default@explain_npe_struct
+PREHOOK: query: explain select c1 from explain_npe_map where c1 is null
+PREHOOK: type: QUERY
+PREHOOK: Input: default@explain_npe_map
+#### A masked pattern was here ####
+POSTHOOK: query: explain select c1 from explain_npe_map where c1 is null
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@explain_npe_map
+#### A masked pattern was here ####
+STAGE DEPENDENCIES:
+ Stage-0 is a root stage
+
+STAGE PLANS:
+ Stage: Stage-0
+ Fetch Operator
+ limit: -1
+ Processor Tree:
+ TableScan
+ alias: explain_npe_map
+ filterExpr: c1 is null (type: boolean)
+ Filter Operator
+ predicate: c1 is null (type: boolean)
+ Select Operator
+ expressions: Const map<string,string> null (type: map<string,string>)
+ outputColumnNames: _col0
+ ListSink
+
+PREHOOK: query: explain select c1 from explain_npe_array where c1 is null
+PREHOOK: type: QUERY
+PREHOOK: Input: default@explain_npe_array
+#### A masked pattern was here ####
+POSTHOOK: query: explain select c1 from explain_npe_array where c1 is null
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@explain_npe_array
+#### A masked pattern was here ####
+STAGE DEPENDENCIES:
+ Stage-0 is a root stage
+
+STAGE PLANS:
+ Stage: Stage-0
+ Fetch Operator
+ limit: -1
+ Processor Tree:
+ TableScan
+ alias: explain_npe_array
+ filterExpr: c1 is null (type: boolean)
+ Filter Operator
+ predicate: c1 is null (type: boolean)
+ Select Operator
+ expressions: Const array<string> null (type: array<string>)
+ outputColumnNames: _col0
+ ListSink
+
+PREHOOK: query: explain select c1 from explain_npe_struct where c1 is null
+PREHOOK: type: QUERY
+PREHOOK: Input: default@explain_npe_struct
+#### A masked pattern was here ####
+POSTHOOK: query: explain select c1 from explain_npe_struct where c1 is null
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@explain_npe_struct
+#### A masked pattern was here ####
+STAGE DEPENDENCIES:
+ Stage-0 is a root stage
+
+STAGE PLANS:
+ Stage: Stage-0
+ Fetch Operator
+ limit: -1
+ Processor Tree:
+ TableScan
+ alias: explain_npe_struct
+ filterExpr: c1 is null (type: boolean)
+ Filter Operator
+ predicate: c1 is null (type: boolean)
+ Select Operator
+ outputColumnNames: _col0
+ ListSink
+
+PREHOOK: query: explain select c1 from explain_npe_map where c1 is null
+PREHOOK: type: QUERY
+PREHOOK: Input: default@explain_npe_map
+#### A masked pattern was here ####
+POSTHOOK: query: explain select c1 from explain_npe_map where c1 is null
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@explain_npe_map
+#### A masked pattern was here ####
+STAGE DEPENDENCIES:
+ Stage-0 is a root stage
+
+STAGE PLANS:
+ Stage: Stage-0
+ Fetch Operator
+ limit: -1
+ Processor Tree:
+ TableScan
+ alias: explain_npe_map
+ filterExpr: c1 is null (type: boolean)
+ Filter Operator
+ predicate: c1 is null (type: boolean)
+ Select Operator
+ expressions: Const map<string,string> null (type: map<string,string>)
+ outputColumnNames: _col0
+ ListSink
+
+PREHOOK: query: explain select c1 from explain_npe_array where c1 is null
+PREHOOK: type: QUERY
+PREHOOK: Input: default@explain_npe_array
+#### A masked pattern was here ####
+POSTHOOK: query: explain select c1 from explain_npe_array where c1 is null
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@explain_npe_array
+#### A masked pattern was here ####
+STAGE DEPENDENCIES:
+ Stage-0 is a root stage
+
+STAGE PLANS:
+ Stage: Stage-0
+ Fetch Operator
+ limit: -1
+ Processor Tree:
+ TableScan
+ alias: explain_npe_array
+ filterExpr: c1 is null (type: boolean)
+ Filter Operator
+ predicate: c1 is null (type: boolean)
+ Select Operator
+ expressions: Const array<string> null (type: array<string>)
+ outputColumnNames: _col0
+ ListSink
+
+PREHOOK: query: explain select c1 from explain_npe_struct where c1 is null
+PREHOOK: type: QUERY
+PREHOOK: Input: default@explain_npe_struct
+#### A masked pattern was here ####
+POSTHOOK: query: explain select c1 from explain_npe_struct where c1 is null
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@explain_npe_struct
+#### A masked pattern was here ####
+STAGE DEPENDENCIES:
+ Stage-0 is a root stage
+
+STAGE PLANS:
+ Stage: Stage-0
+ Fetch Operator
+ limit: -1
+ Processor Tree:
+ TableScan
+ alias: explain_npe_struct
+ filterExpr: c1 is null (type: boolean)
+ Filter Operator
+ predicate: c1 is null (type: boolean)
+ Select Operator
+ expressions: null (type: void)
+ outputColumnNames: _col0
+ ListSink
+
+PREHOOK: query: drop table if exists explain_npe_map
+PREHOOK: type: DROPTABLE
+PREHOOK: Input: default@explain_npe_map
+PREHOOK: Output: default@explain_npe_map
+POSTHOOK: query: drop table if exists explain_npe_map
+POSTHOOK: type: DROPTABLE
+POSTHOOK: Input: default@explain_npe_map
+POSTHOOK: Output: default@explain_npe_map
+PREHOOK: query: drop table if exists explain_npe_array
+PREHOOK: type: DROPTABLE
+PREHOOK: Input: default@explain_npe_array
+PREHOOK: Output: default@explain_npe_array
+POSTHOOK: query: drop table if exists explain_npe_array
+POSTHOOK: type: DROPTABLE
+POSTHOOK: Input: default@explain_npe_array
+POSTHOOK: Output: default@explain_npe_array
+PREHOOK: query: drop table if exists explain_npe_struct
+PREHOOK: type: DROPTABLE
+PREHOOK: Input: default@explain_npe_struct
+PREHOOK: Output: default@explain_npe_struct
+POSTHOOK: query: drop table if exists explain_npe_struct
+POSTHOOK: type: DROPTABLE
+POSTHOOK: Input: default@explain_npe_struct
+POSTHOOK: Output: default@explain_npe_struct
diff --git a/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/StandardConstantMapObjectInspector.java b/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/StandardConstantMapObjectInspector.java
index 55b9fc8..da8b319 100644
--- a/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/StandardConstantMapObjectInspector.java
+++ b/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/StandardConstantMapObjectInspector.java
@@ -40,8 +40,8 @@ public class StandardConstantMapObjectInspector extends StandardMapObjectInspect
*/
protected StandardConstantMapObjectInspector(ObjectInspector mapKeyObjectInspector,
ObjectInspector mapValueObjectInspector, Map<?, ?> value) {
- super(mapKeyObjectInspector, mapValueObjectInspector);
- this.value = value;
+ super(mapKeyObjectInspector, mapValueObjectInspector);
+ this.value = value;
}
@Override