diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorizationContext.java ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorizationContext.java index f00804e..068b418 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorizationContext.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorizationContext.java @@ -2017,12 +2017,7 @@ private VectorExpression getCustomUDFExpression(ExprNodeGenericFuncDesc expr) variableArgPositions.add(i); argDescs[i].setVariable(getInputColumnIndex(((ExprNodeColumnDesc) child).getColumn())); } else if (child instanceof ExprNodeConstantDesc) { - if (((ExprNodeConstantDesc) child).getValue() == null) { - // cannot handle constant null at the moment - throw new HiveException("Unable to vectorize custom UDF. Custom udf containing " - + "constant null argument cannot be currently vectorized."); - } - // this is a constant + // this is a constant (or null) argDescs[i].setConstant((ExprNodeConstantDesc) child); } else { throw new HiveException("Unable to vectorize custom UDF. Encountered unsupported expr desc : " diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/vector/udf/VectorUDFArgDesc.java ql/src/java/org/apache/hadoop/hive/ql/exec/vector/udf/VectorUDFArgDesc.java index e113980..6abfe63 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/vector/udf/VectorUDFArgDesc.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/vector/udf/VectorUDFArgDesc.java @@ -59,13 +59,18 @@ public void setConstant(ExprNodeConstantDesc expr) { * during initialization. */ public void prepareConstant() { - PrimitiveCategory pc = ((PrimitiveTypeInfo) constExpr.getTypeInfo()) - .getPrimitiveCategory(); - - // Convert from Java to Writable - Object writableValue = PrimitiveObjectInspectorFactory - .getPrimitiveJavaObjectInspector(pc).getPrimitiveWritableObject( - constExpr.getValue()); + final Object writableValue; + if (constExpr != null) { + PrimitiveCategory pc = ((PrimitiveTypeInfo) constExpr.getTypeInfo()) + .getPrimitiveCategory(); + + // Convert from Java to Writable + writableValue = PrimitiveObjectInspectorFactory + .getPrimitiveJavaObjectInspector(pc).getPrimitiveWritableObject( + constExpr.getValue()); + } else { + writableValue = null; + } constObjVal = new GenericUDF.DeferredJavaObject(writableValue); } diff --git ql/src/test/queries/clientpositive/vectorized_case.q ql/src/test/queries/clientpositive/vectorized_case.q index 8799fbb..7242bd7 100644 --- ql/src/test/queries/clientpositive/vectorized_case.q +++ ql/src/test/queries/clientpositive/vectorized_case.q @@ -36,3 +36,21 @@ where csmallint = 418 or csmallint = 12205 or csmallint = 10583 ; +explain +select + csmallint, + case + when csmallint = 418 then "a" + when csmallint = 12205 then "b" + else null + end, + case csmallint + when 418 then "a" + when 12205 then null + else "c" + end +from alltypesorc +where csmallint = 418 +or csmallint = 12205 +or csmallint = 10583 +; diff --git ql/src/test/results/clientpositive/vectorized_case.q.out ql/src/test/results/clientpositive/vectorized_case.q.out index 73bf12d..347a93e 100644 --- ql/src/test/results/clientpositive/vectorized_case.q.out +++ ql/src/test/results/clientpositive/vectorized_case.q.out @@ -109,3 +109,72 @@ POSTHOOK: Input: default@alltypesorc 10583 c c 418 a a 12205 b b +PREHOOK: query: explain +select + csmallint, + case + when csmallint = 418 then "a" + when csmallint = 12205 then "b" + else null + end, + case csmallint + when 418 then "a" + when 12205 then null + else "c" + end +from alltypesorc +where csmallint = 418 +or csmallint = 12205 +or csmallint = 10583 +PREHOOK: type: QUERY +POSTHOOK: query: explain +select + csmallint, + case + when csmallint = 418 then "a" + when csmallint = 12205 then "b" + else null + end, + case csmallint + when 418 then "a" + when 12205 then null + else "c" + end +from alltypesorc +where csmallint = 418 +or csmallint = 12205 +or csmallint = 10583 +POSTHOOK: type: QUERY +STAGE DEPENDENCIES: + Stage-1 is a root stage + Stage-0 depends on stages: Stage-1 + +STAGE PLANS: + Stage: Stage-1 + Map Reduce + Map Operator Tree: + TableScan + alias: alltypesorc + Statistics: Num rows: 12288 Data size: 2641964 Basic stats: COMPLETE Column stats: NONE + Filter Operator + predicate: ((csmallint = 418) or (csmallint = 12205) or (csmallint = 10583)) (type: boolean) + Statistics: Num rows: 12288 Data size: 2641964 Basic stats: COMPLETE Column stats: NONE + Select Operator + expressions: csmallint (type: smallint), CASE WHEN ((csmallint = 418)) THEN ('a') WHEN ((csmallint = 12205)) THEN ('b') ELSE (null) END (type: string), CASE (csmallint) WHEN (418) THEN ('a') WHEN (12205) THEN (null) ELSE ('c') END (type: string) + outputColumnNames: _col0, _col1, _col2 + Statistics: Num rows: 12288 Data size: 2641964 Basic stats: COMPLETE Column stats: NONE + File Output Operator + compressed: false + Statistics: Num rows: 12288 Data size: 2641964 Basic stats: COMPLETE Column stats: NONE + table: + input format: org.apache.hadoop.mapred.TextInputFormat + output format: org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat + serde: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe + Execution mode: vectorized + + Stage: Stage-0 + Fetch Operator + limit: -1 + Processor Tree: + ListSink +