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 97e4059..1167f16 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 @@ -3250,10 +3250,44 @@ private boolean isNullConst(ExprNodeDesc exprNodeDesc) { private VectorExpression getIfExpression(GenericUDFIf genericUDFIf, List childExpr, VectorExpressionDescriptor.Mode mode, TypeInfo returnType) throws HiveException { - if (mode != VectorExpressionDescriptor.Mode.PROJECTION) { + boolean isFilter = false; // Assume. + if (mode == VectorExpressionDescriptor.Mode.FILTER) { + + // Is output type a BOOLEAN? + if (returnType.getCategory() == Category.PRIMITIVE && + ((PrimitiveTypeInfo) returnType).getPrimitiveCategory() == PrimitiveCategory.BOOLEAN) { + isFilter = true; + } else { + return null; + } + } + + // Get a PROJECTION IF expression. + VectorExpression ve = doGetIfExpression(genericUDFIf, childExpr, returnType); + + if (ve == null) { return null; } + if (isFilter) { + + // Wrap the PROJECTION IF expression output with a filter. + SelectColumnIsTrue filterVectorExpr = new SelectColumnIsTrue(ve.getOutputColumnNum()); + + filterVectorExpr.setChildExpressions(new VectorExpression[] {ve}); + + filterVectorExpr.setInputTypeInfos(ve.getOutputTypeInfo()); + filterVectorExpr.setInputDataTypePhysicalVariations(ve.getOutputDataTypePhysicalVariation()); + + return filterVectorExpr; + } else { + return ve; + } + } + + private VectorExpression doGetIfExpression(GenericUDFIf genericUDFIf, List childExpr, + TypeInfo returnType) throws HiveException { + // Add HiveConf variable with 3 modes: // 1) adaptor: Always use VectorUDFAdaptor for IF statements. // @@ -3300,8 +3334,10 @@ private VectorExpression getIfExpression(GenericUDFIf genericUDFIf, List udfClass = genericUDFIf.getClass(); return getVectorExpressionForUdf( - genericUDFIf, udfClass, childExpr, mode, returnType); + genericUDFIf, udfClass, childExpr, VectorExpressionDescriptor.Mode.PROJECTION, returnType); } private VectorExpression getWhenExpression(List childExpr, VectorExpressionDescriptor.Mode mode, TypeInfo returnType) throws HiveException { - if (mode != VectorExpressionDescriptor.Mode.PROJECTION) { - return null; - } final int size = childExpr.size(); final ExprNodeDesc whenDesc = childExpr.get(0);