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 9de1833..adf447d 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 @@ -479,24 +479,18 @@ public VectorExpression getVectorExpression(ExprNodeDesc exprDesc, VectorExpress ve = getColumnVectorExpression((ExprNodeColumnDesc) exprDesc, mode); } else if (exprDesc instanceof ExprNodeGenericFuncDesc) { ExprNodeGenericFuncDesc expr = (ExprNodeGenericFuncDesc) exprDesc; - if (isCustomUDF(expr)) { - ve = getCustomUDFExpression(expr, mode); - } else { - // Add cast expression if needed. Child expressions of a udf may return different data types // and that would require converting their data types to evaluate the udf. // For example decimal column added to an integer column would require integer column to be // cast to decimal. - List childExpressions = getChildExpressionsWithImplicitCast(expr.getGenericUDF(), + // Note: this is a no-op for custom UDFs + List childExpressions = getChildExpressionsWithImplicitCast(expr.getGenericUDF(), exprDesc.getChildren(), exprDesc.getTypeInfo()); - ve = getGenericUdfVectorExpression(expr.getGenericUDF(), - childExpressions, mode, exprDesc.getTypeInfo()); - if (ve == null) { - /* - * Ok, no vectorized class available. No problem -- try to use the VectorUDFAdaptor. - */ - ve = getCustomUDFExpression(expr, mode); - } + ve = getGenericUdfVectorExpression(expr.getGenericUDF(), childExpressions, mode, + exprDesc.getTypeInfo()); + if (ve == null) { + /* Ok, no vectorized class available. No problem -- try to use the VectorUDFAdaptor. */ + ve = getCustomUDFExpression(expr, mode); } } else if (exprDesc instanceof ExprNodeConstantDesc) { ve = getConstantVectorExpression(((ExprNodeConstantDesc) exprDesc).getValue(), exprDesc.getTypeInfo(), @@ -562,8 +556,13 @@ private TypeInfo getCommonTypeForChildExpressions(GenericUDF genericUdf, */ private List getChildExpressionsWithImplicitCast(GenericUDF genericUDF, List children, TypeInfo returnType) throws HiveException { - if (isExcludedFromCast(genericUDF)) { + if (isCustomUDF(genericUDF.getUdfName())) { + // no implicit casts possible + return children; + } + + if (isExcludedFromCast(genericUDF)) { // No implicit cast needed return children; } @@ -800,9 +799,12 @@ public static String arg0Type(ExprNodeGenericFuncDesc expr) { } // Return true if this is a custom UDF or custom GenericUDF. - // This is for use only in the planner. It will fail in a task. + // This two functions are for use only in the planner. It will fail in a task. public static boolean isCustomUDF(ExprNodeGenericFuncDesc expr) { - String udfName = expr.getFuncText(); + return isCustomUDF(expr.getFuncText()); + } + + private static boolean isCustomUDF(String udfName) { if (udfName == null) { return false; }