diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java index aaf2399..d9b0da2 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java @@ -19,9 +19,11 @@ package org.apache.hadoop.hive.ql.exec; import java.lang.reflect.Method; +import java.lang.reflect.Type; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.Comparator; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashSet; @@ -1164,6 +1166,27 @@ public static Method getMethodInternal(Class udfClass, List mlist, bo List udfMethods = new ArrayList(); // The cost of the result int leastConversionCost = Integer.MAX_VALUE; + + // To let variable method in the end + mlist.sort(new Comparator() { + @Override + public int compare(Method arg0, Method arg1) { + Type[] methodParameterTypes = arg0.getGenericParameterTypes(); + + // Whether the method takes variable-length arguments + // Whether the method takes an array like Object[], + // or String[] etc in the last argument. + Type lastParaElementType = TypeInfoUtils + .getArrayElementType(methodParameterTypes.length == 0 ? null + : methodParameterTypes[methodParameterTypes.length - 1]); + boolean isVariableLengthArgument = (lastParaElementType != null); + if(isVariableLengthArgument) { + return 1; + }else { + return -1; + } + } + }); for (Method m : mlist) { List argumentsAccepted = TypeInfoUtils.getParameterTypeInfos(m,