diff --git a/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorizationContext.java b/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorizationContext.java index 565696d..535e4b3 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorizationContext.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorizationContext.java @@ -717,13 +717,15 @@ ExprNodeDesc foldConstantsForUnaryExpression(ExprNodeDesc exprDesc) throws HiveE private VectorExpression getConstantVectorExpression(Object constantValue, TypeInfo typeInfo, Mode mode) throws HiveException { - String type = typeInfo.getTypeName(); + String type = typeInfo.getTypeName(); String colVectorType = getNormalizedTypeName(type); int outCol = -1; if (mode == Mode.PROJECTION) { outCol = ocm.allocateOutputColumn(colVectorType); } - if (decimalTypePattern.matcher(type).matches()) { + if (constantValue == null) { + return new ConstantVectorExpression(outCol, type, true); + } else if (decimalTypePattern.matcher(type).matches()) { VectorExpression ve = new ConstantVectorExpression(outCol, (Decimal128) constantValue); ve.setOutputType(typeInfo.getTypeName()); return ve; diff --git a/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/ConstantVectorExpression.java b/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/ConstantVectorExpression.java index a1a5584..9fd3853 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/ConstantVectorExpression.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/ConstantVectorExpression.java @@ -41,6 +41,7 @@ private double doubleValue = 0; private byte[] bytesValue = null; private Decimal128 decimalValue = null; + private boolean isNullValue = false; private Type type; private int bytesValueLength = 0; @@ -74,34 +75,58 @@ public ConstantVectorExpression(int outputColumn, Decimal128 value) { this(outputColumn, "decimal"); setDecimalValue(value); } - + + /* + * Support for null constant object + */ + public ConstantVectorExpression(int outputColumn, String typeString, boolean isNull) { + this(outputColumn, typeString); + isNullValue = isNull; + } + private void evaluateLong(VectorizedRowBatch vrg) { LongColumnVector cv = (LongColumnVector) vrg.cols[outputColumn]; cv.isRepeating = true; - cv.noNulls = true; - cv.vector[0] = longValue; + cv.noNulls = !isNullValue; + if (!isNullValue) { + cv.vector[0] = longValue; + } else { + cv.isNull[0] = true; + } } private void evaluateDouble(VectorizedRowBatch vrg) { DoubleColumnVector cv = (DoubleColumnVector) vrg.cols[outputColumn]; cv.isRepeating = true; - cv.noNulls = true; - cv.vector[0] = doubleValue; + cv.noNulls = !isNullValue; + if (!isNullValue) { + cv.vector[0] = doubleValue; + } else { + cv.isNull[0] = true; + } } private void evaluateBytes(VectorizedRowBatch vrg) { BytesColumnVector cv = (BytesColumnVector) vrg.cols[outputColumn]; cv.isRepeating = true; - cv.noNulls = true; + cv.noNulls = !isNullValue; cv.initBuffer(); - cv.setVal(0, bytesValue, 0, bytesValueLength); + if (!isNullValue) { + cv.setVal(0, bytesValue, 0, bytesValueLength); + } else { + cv.isNull[0] = true; + } } private void evaluateDecimal(VectorizedRowBatch vrg) { DecimalColumnVector dcv = (DecimalColumnVector) vrg.cols[outputColumn]; dcv.isRepeating = true; - dcv.noNulls = true; - dcv.vector[0].update(decimalValue); + dcv.noNulls = !isNullValue; + if (!isNullValue) { + dcv.vector[0].update(decimalValue); + } else { + dcv.isNull[0] = true; + } } @Override