Index: ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java (revision 1507705) +++ ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java (working copy) @@ -177,7 +177,6 @@ public static final String LAG_FUNC_NAME = "lag"; public static final String LAST_VALUE_FUNC_NAME = "last_value"; - public static final String WINDOWING_TABLE_FUNCTION = "windowingtablefunction"; public static final String NOOP_TABLE_FUNCTION = "noop"; public static final String NOOP_MAP_TABLE_FUNCTION = "noopwithmap"; @@ -187,7 +186,7 @@ /* * UDAFS that only work when the input rows have an order. */ - public static final HashSet UDAFS_IMPLY_ORDER = new HashSet(); + static Set udafsImplyOrder = Collections.synchronizedSet(new HashSet()); static { registerUDF("concat", UDFConcat.class, false); @@ -428,7 +427,6 @@ registerGenericUDF(true, LEAD_FUNC_NAME, GenericUDFLead.class); registerGenericUDF(true, LAG_FUNC_NAME, GenericUDFLag.class); - registerHiveUDAFsAsWindowFunctions(); registerWindowFunction("row_number", new GenericUDAFRowNumber()); registerWindowFunction("rank", new GenericUDAFRank()); registerWindowFunction("dense_rank", new GenericUDAFDenseRank()); @@ -440,15 +438,6 @@ registerWindowFunction(LEAD_FUNC_NAME, new GenericUDAFLead(), false); registerWindowFunction(LAG_FUNC_NAME, new GenericUDAFLag(), false); - UDAFS_IMPLY_ORDER.add("rank"); - UDAFS_IMPLY_ORDER.add("dense_rank"); - UDAFS_IMPLY_ORDER.add("percent_rank"); - UDAFS_IMPLY_ORDER.add("cume_dist"); - UDAFS_IMPLY_ORDER.add(LEAD_FUNC_NAME); - UDAFS_IMPLY_ORDER.add(LAG_FUNC_NAME); - UDAFS_IMPLY_ORDER.add("first_value"); - UDAFS_IMPLY_ORDER.add("last_value"); - registerTableFunction(NOOP_TABLE_FUNCTION, NoopResolver.class); registerTableFunction(NOOP_MAP_TABLE_FUNCTION, NoopWithMapResolver.class); registerTableFunction(WINDOWING_TABLE_FUNCTION, WindowingTableFunctionResolver.class); @@ -754,9 +743,8 @@ args[ii] = argumentOIs.get(ii); } - GenericUDAFParameterInfo paramInfo = - new SimpleGenericUDAFParameterInfo( - args, isDistinct, isAllColumns); + GenericUDAFParameterInfo paramInfo = new SimpleGenericUDAFParameterInfo(args, isDistinct, + isAllColumns); if (udafResolver instanceof GenericUDAFResolver2) { udafEvaluator = ((GenericUDAFResolver2) udafResolver).getEvaluator(paramInfo); @@ -768,21 +756,20 @@ @SuppressWarnings("deprecation") public static GenericUDAFEvaluator getGenericWindowingEvaluator(String name, - List argumentOIs, boolean isDistinct, - boolean isAllColumns) throws SemanticException { - + List argumentOIs, boolean isDistinct, boolean isAllColumns) + throws SemanticException { WindowFunctionInfo finfo = windowFunctions.get(name.toLowerCase()); - if (finfo == null) { return null;} - if ( !name.toLowerCase().equals(LEAD_FUNC_NAME) && - !name.toLowerCase().equals(LAG_FUNC_NAME) ) { - return getGenericUDAFEvaluator(name, argumentOIs, isDistinct, isAllColumns); + if (finfo == null) { + return null; } - + if (!name.toLowerCase().equals(LEAD_FUNC_NAME) && !name.toLowerCase().equals(LAG_FUNC_NAME)) { + return getGenericUDAFEvaluator(name, argumentOIs, isDistinct, isAllColumns); + } // this must be lead/lag UDAF ObjectInspector args[] = new ObjectInspector[argumentOIs.size()]; GenericUDAFResolver udafResolver = finfo.getfInfo().getGenericUDAFResolver(); GenericUDAFParameterInfo paramInfo = new SimpleGenericUDAFParameterInfo( - argumentOIs.toArray(args), isDistinct, isAllColumns); + argumentOIs.toArray(args), isDistinct, isAllColumns); return ((GenericUDAFResolver2) udafResolver).getEvaluator(paramInfo); } @@ -792,18 +779,14 @@ * for UDAFRegistry. * @throws UDFArgumentException */ - public static Method getMethodInternal(Class udfClass, - String methodName, boolean exact, List argumentClasses) - throws UDFArgumentException { - + public static Method getMethodInternal(Class udfClass, String methodName, + boolean exact, List argumentClasses) throws UDFArgumentException { List mlist = new ArrayList(); - for (Method m : udfClass.getMethods()) { if (m.getName().equals(methodName)) { mlist.add(m); } } - return getMethodInternal(udfClass, mlist, exact, argumentClasses); } @@ -819,8 +802,20 @@ public static void registerGenericUDAF(boolean isNative, String functionName, GenericUDAFResolver genericUDAFResolver) { - mFunctions.put(functionName.toLowerCase(), new FunctionInfo(isNative, - functionName.toLowerCase(), genericUDAFResolver)); + String lowerName = functionName.toLowerCase(); + FunctionInfo info = new FunctionInfo(isNative, + functionName.toLowerCase(), genericUDAFResolver); + mFunctions.put(functionName.toLowerCase(), info); + if (info.isGenericUDAF()) { + WindowFunctionInfo wInfo = new WindowFunctionInfo(info); + windowFunctions.put(lowerName, wInfo); + WindowFunctionDescription description = genericUDAFResolver.getClass().getAnnotation(WindowFunctionDescription.class); + if (description != null){ + if (description.impliesOrder()){ + udafsImplyOrder.add(functionName.toLowerCase()); + } + } + } } public static void registerTemporaryUDAF(String functionName, @@ -1317,23 +1312,21 @@ } /** - * Registers thae appropriate kind of temporary function based on a class's - * type. - * - * @param macroName name under which to register the macro - * - * @param body the expression which the macro evaluates to - * - * @param colNames the names of the arguments to the macro - * - * @param colTypes the types of the arguments to the macro + * Registers the appropriate kind of temporary function based on a class's type. + * @param macroName + * name under which to register the macro + * @param body + * the expression which the macro evaluates to + * @param colNames + * the names of the arguments to the macro + * @param colTypes + * the types of the arguments to the macro */ - public static void registerTemporaryMacro( - String macroName, ExprNodeDesc body, - List colNames, List colTypes) { + public static void registerTemporaryMacro(String macroName, ExprNodeDesc body, + List colNames, List colTypes) { - FunctionInfo fI = new FunctionInfo(false, macroName, - new GenericUDFMacro(macroName, body, colNames, colTypes)); + FunctionInfo fI = new FunctionInfo(false, macroName, new GenericUDFMacro(macroName, body, + colNames, colTypes)); mFunctions.put(macroName.toLowerCase(), fI); } @@ -1384,8 +1377,7 @@ //---------PTF functions------------ - public static void registerWindowFunction(String name, GenericUDAFResolver wFn) - { + public static void registerWindowFunction(String name, GenericUDAFResolver wFn) { registerWindowFunction(name, wFn, true); } @@ -1402,72 +1394,50 @@ * @param wFn * @param registerAsUDAF */ - public static void registerWindowFunction(String name, GenericUDAFResolver wFn, boolean registerAsUDAF) - { + public static void registerWindowFunction(String name, GenericUDAFResolver wFn, + boolean registerAsUDAF) { FunctionInfo fInfo = null; if (registerAsUDAF) { registerGenericUDAF(true, name, wFn); fInfo = getFunctionInfo(name); + } else { + fInfo = new FunctionInfo(true, name.toLowerCase(), wFn); } - else { - fInfo = new FunctionInfo(true, - name.toLowerCase(), wFn); - } - WindowFunctionInfo wInfo = new WindowFunctionInfo(fInfo); windowFunctions.put(name.toLowerCase(), wInfo); } - public static WindowFunctionInfo getWindowFunctionInfo(String name) - { + public static WindowFunctionInfo getWindowFunctionInfo(String name) { return windowFunctions.get(name.toLowerCase()); } public static boolean impliesOrder(String functionName) { - return functionName == null ? false : UDAFS_IMPLY_ORDER.contains(functionName.toLowerCase()); + return functionName == null ? false : udafsImplyOrder.contains(functionName.toLowerCase()); } - static void registerHiveUDAFsAsWindowFunctions() - { - Set fNames = getFunctionNames(); - for(String fName : fNames) - { - FunctionInfo fInfo = getFunctionInfo(fName); - if ( fInfo.isGenericUDAF()) - { - WindowFunctionInfo wInfo = new WindowFunctionInfo(fInfo); - windowFunctions.put(fName, wInfo); - } - } - } - - public static boolean isTableFunction(String name) - { + public static boolean isTableFunction(String name) { FunctionInfo tFInfo = mFunctions.get(name.toLowerCase()); return tFInfo != null && !tFInfo.isInternalTableFunction() && tFInfo.isTableFunction(); } - public static TableFunctionResolver getTableFunctionResolver(String name) - { + public static TableFunctionResolver getTableFunctionResolver(String name) { FunctionInfo tfInfo = mFunctions.get(name.toLowerCase()); - if(tfInfo.isTableFunction()) { + if (tfInfo.isTableFunction()) { return (TableFunctionResolver) ReflectionUtils.newInstance(tfInfo.getFunctionClass(), null); } return null; } - public static TableFunctionResolver getWindowingTableFunction() - { + public static TableFunctionResolver getWindowingTableFunction() { return getTableFunctionResolver(WINDOWING_TABLE_FUNCTION); } - public static TableFunctionResolver getNoopTableFunction() - { + public static TableFunctionResolver getNoopTableFunction() { return getTableFunctionResolver(NOOP_TABLE_FUNCTION); } - public static void registerTableFunction(String name, Class tFnCls) - { + public static void registerTableFunction(String name, + Class tFnCls) { FunctionInfo tInfo = new FunctionInfo(name, tFnCls); mFunctions.put(name.toLowerCase(), tInfo); } Index: ql/src/java/org/apache/hadoop/hive/ql/exec/WindowFunctionDescription.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/exec/WindowFunctionDescription.java (revision 1507705) +++ ql/src/java/org/apache/hadoop/hive/ql/exec/WindowFunctionDescription.java (working copy) @@ -28,27 +28,33 @@ import org.apache.hadoop.hive.ql.udf.ptf.WindowingTableFunction; @Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE}) +@Target({ ElementType.TYPE }) @Documented -public @interface WindowFunctionDescription -{ - Description description (); - /** - * controls whether this function can be applied to a Window. - *

- * Ranking function: Rank, Dense_Rank, Percent_Rank and Cume_Dist don't operate on Windows. - * Why? a window specification implies a row specific range i.e. every row gets its own set of rows to process the UDAF on. - * For ranking defining a set of rows for every row makes no sense. - *

- * All other UDAFs can be computed for a Window. - */ - boolean supportsWindow() default true; - /** - * A WindowFunc is implemented as {@link GenericUDAFResolver2}. It returns only one value. - * If this is true then the function must return a List which is taken to be the column for this function in the Output table returned by the - * {@link WindowingTableFunction}. Otherwise the output is assumed to be a single value, the column of the Output will contain the same value - * for all the rows. - */ - boolean pivotResult() default false; +public @interface WindowFunctionDescription { + Description description(); + + /** + * controls whether this function can be applied to a Window. + *

+ * Ranking function: Rank, Dense_Rank, Percent_Rank and Cume_Dist don't operate on Windows. Why? a + * window specification implies a row specific range i.e. every row gets its own set of rows to + * process the UDAF on. For ranking defining a set of rows for every row makes no sense. + *

+ * All other UDAFs can be computed for a Window. + */ + boolean supportsWindow() default true; + + /** + * A WindowFunc is implemented as {@link GenericUDAFResolver2}. It returns only one value. If this + * is true then the function must return a List which is taken to be the column for this function + * in the Output table returned by the {@link WindowingTableFunction}. Otherwise the output is + * assumed to be a single value, the column of the Output will contain the same value for all the + * rows. + */ + boolean pivotResult() default false; + + /** + * These windowing functions imply order + */ + boolean impliesOrder() default false; } - Index: ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFCumeDist.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFCumeDist.java (revision 1507705) +++ ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFCumeDist.java (working copy) @@ -32,43 +32,37 @@ import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory; import org.apache.hadoop.io.IntWritable; -@WindowFunctionDescription -( - description = @Description( - name = "cume_dist", - value = "_FUNC_(x) - The CUME_DIST function (defined as the inverse of percentile in some " + - "statistical books) computes the position of a specified value relative to a set of values. " + - "To compute the CUME_DIST of a value x in a set S of size N, you use the formula: " + - "CUME_DIST(x) = number of values in S coming before " + - " and including x in the specified order/ N" - ), - supportsWindow = false, - pivotResult = true +@WindowFunctionDescription( + description = @Description( + name = "cume_dist", + value = "_FUNC_(x) - The CUME_DIST function (defined as the inverse of percentile in some " + + "statistical books) computes the position of a specified value relative to a set of values. " + + "To compute the CUME_DIST of a value x in a set S of size N, you use the formula: " + + "CUME_DIST(x) = number of values in S coming before " + + "and including x in the specified order/ N" ), + supportsWindow = false, + pivotResult = true, + impliesOrder = true ) -public class GenericUDAFCumeDist extends GenericUDAFRank -{ +public class GenericUDAFCumeDist extends GenericUDAFRank { - static final Log LOG = LogFactory.getLog(GenericUDAFCumeDist.class.getName()); + static final Log LOG = LogFactory.getLog(GenericUDAFCumeDist.class.getName()); - @Override - protected GenericUDAFRankEvaluator createEvaluator() - { - return new GenericUDAFCumeDistEvaluator(); - } + @Override + protected GenericUDAFRankEvaluator createEvaluator() { + return new GenericUDAFCumeDistEvaluator(); + } - public static class GenericUDAFCumeDistEvaluator extends GenericUDAFRankEvaluator - { + public static class GenericUDAFCumeDistEvaluator extends GenericUDAFRankEvaluator { @Override - public ObjectInspector init(Mode m, ObjectInspector[] parameters) throws HiveException - { + public ObjectInspector init(Mode m, ObjectInspector[] parameters) throws HiveException { super.init(m, parameters); return ObjectInspectorFactory - .getStandardListObjectInspector(PrimitiveObjectInspectorFactory.writableDoubleObjectInspector); + .getStandardListObjectInspector(PrimitiveObjectInspectorFactory.writableDoubleObjectInspector); } @Override - public Object terminate(AggregationBuffer agg) throws HiveException - { + public Object terminate(AggregationBuffer agg) throws HiveException { List ranks = ((RankBuffer) agg).rowNums; int ranksSize = ranks.size(); double ranksSizeDouble = ranksSize; Index: ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFDenseRank.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFDenseRank.java (revision 1507705) +++ ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFDenseRank.java (working copy) @@ -23,8 +23,7 @@ import org.apache.hadoop.hive.ql.exec.Description; import org.apache.hadoop.hive.ql.exec.WindowFunctionDescription; -@WindowFunctionDescription -( +@WindowFunctionDescription( description = @Description( name = "dense_rank", value = "_FUNC_(x) The difference between RANK and DENSE_RANK is that DENSE_RANK leaves no " + @@ -34,28 +33,24 @@ "that the next person came in third." ), supportsWindow = false, - pivotResult = true + pivotResult = true, + impliesOrder = true ) -public class GenericUDAFDenseRank extends GenericUDAFRank -{ - static final Log LOG = LogFactory.getLog(GenericUDAFDenseRank.class.getName()); +public class GenericUDAFDenseRank extends GenericUDAFRank { + static final Log LOG = LogFactory.getLog(GenericUDAFDenseRank.class.getName()); - @Override - protected GenericUDAFRankEvaluator createEvaluator() - { - return new GenericUDAFDenseRankEvaluator(); - } + @Override + protected GenericUDAFRankEvaluator createEvaluator() { + return new GenericUDAFDenseRankEvaluator(); + } - public static class GenericUDAFDenseRankEvaluator extends GenericUDAFRankEvaluator - { - /* - * Called when the value in the partition has changed. Update the currentRank - */ - @Override - protected void nextRank(RankBuffer rb) - { - rb.currentRank++; - } - } + public static class GenericUDAFDenseRankEvaluator extends GenericUDAFRankEvaluator { + /* + * Called when the value in the partition has changed. Update the currentRank + */ + @Override + protected void nextRank(RankBuffer rb) { + rb.currentRank++; + } + } } - Index: ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFFirstValue.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFFirstValue.java (revision 1507705) +++ ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFFirstValue.java (working copy) @@ -34,135 +34,111 @@ import org.apache.hadoop.hive.serde2.typeinfo.TypeInfo; import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory; -@WindowFunctionDescription -( - description = @Description( - name = "first_value", - value = "_FUNC_(x)" - ), - supportsWindow = true, - pivotResult = false +@WindowFunctionDescription ( + description = @Description( + name = "first_value", + value = "_FUNC_(x)" ), + supportsWindow = true, + pivotResult = false, + impliesOrder = true ) -public class GenericUDAFFirstValue extends AbstractGenericUDAFResolver -{ - static final Log LOG = LogFactory.getLog(GenericUDAFFirstValue.class.getName()); +public class GenericUDAFFirstValue extends AbstractGenericUDAFResolver { + static final Log LOG = LogFactory.getLog(GenericUDAFFirstValue.class.getName()); - @Override - public GenericUDAFEvaluator getEvaluator(TypeInfo[] parameters) throws SemanticException - { - if (parameters.length > 2) - { - throw new UDFArgumentTypeException(2, "At most 2 arguments expected"); - } - if ( parameters.length > 1 && !parameters[1].equals(TypeInfoFactory.booleanTypeInfo) ) - { - throw new UDFArgumentTypeException(1, "second argument must be a boolean expression"); - } - return createEvaluator(); - } + @Override + public GenericUDAFEvaluator getEvaluator(TypeInfo[] parameters) throws SemanticException { + if (parameters.length > 2) { + throw new UDFArgumentTypeException(2, "At most 2 arguments expected"); + } + if (parameters.length > 1 && !parameters[1].equals(TypeInfoFactory.booleanTypeInfo)) { + throw new UDFArgumentTypeException(1, "second argument must be a boolean expression"); + } + return createEvaluator(); + } - protected GenericUDAFFirstValueEvaluator createEvaluator() - { - return new GenericUDAFFirstValueEvaluator(); - } + protected GenericUDAFFirstValueEvaluator createEvaluator() { + return new GenericUDAFFirstValueEvaluator(); + } - static class FirstValueBuffer implements AggregationBuffer - { - Object val; - boolean valSet; - boolean firstRow; - boolean skipNulls; + static class FirstValueBuffer implements AggregationBuffer { + Object val; + boolean valSet; + boolean firstRow; + boolean skipNulls; - FirstValueBuffer() - { - init(); - } + FirstValueBuffer() { + init(); + } - void init() - { - val = null; - valSet = false; - firstRow = true; - skipNulls = false; - } + void init() { + val = null; + valSet = false; + firstRow = true; + skipNulls = false; + } + } - } + public static class GenericUDAFFirstValueEvaluator extends GenericUDAFEvaluator { + ObjectInspector inputOI; + ObjectInspector outputOI; - public static class GenericUDAFFirstValueEvaluator extends GenericUDAFEvaluator - { - ObjectInspector inputOI; - ObjectInspector outputOI; + @Override + public ObjectInspector init(Mode m, ObjectInspector[] parameters) throws HiveException { + super.init(m, parameters); + if (m != Mode.COMPLETE) { + throw new HiveException("Only COMPLETE mode supported for Rank function"); + } + inputOI = parameters[0]; + outputOI = ObjectInspectorUtils.getStandardObjectInspector(inputOI, + ObjectInspectorCopyOption.WRITABLE); + return outputOI; + } - @Override - public ObjectInspector init(Mode m, ObjectInspector[] parameters) throws HiveException - { - super.init(m, parameters); - if (m != Mode.COMPLETE) - { - throw new HiveException( - "Only COMPLETE mode supported for Rank function"); - } - inputOI = parameters[0]; - outputOI = ObjectInspectorUtils.getStandardObjectInspector(inputOI, ObjectInspectorCopyOption.WRITABLE); - return outputOI; - } + @Override + public AggregationBuffer getNewAggregationBuffer() throws HiveException { + return new FirstValueBuffer(); + } - @Override - public AggregationBuffer getNewAggregationBuffer() throws HiveException - { - return new FirstValueBuffer(); - } + @Override + public void reset(AggregationBuffer agg) throws HiveException { + ((FirstValueBuffer) agg).init(); + } - @Override - public void reset(AggregationBuffer agg) throws HiveException - { - ((FirstValueBuffer) agg).init(); - } + @Override + public void iterate(AggregationBuffer agg, Object[] parameters) throws HiveException { + FirstValueBuffer fb = (FirstValueBuffer) agg; - @Override - public void iterate(AggregationBuffer agg, Object[] parameters) throws HiveException - { - FirstValueBuffer fb = (FirstValueBuffer) agg; + if (fb.firstRow) { + fb.firstRow = false; + if (parameters.length == 2) { + fb.skipNulls = PrimitiveObjectInspectorUtils.getBoolean(parameters[1], + PrimitiveObjectInspectorFactory.writableBooleanObjectInspector); + } + } - if (fb.firstRow ) - { - fb.firstRow = false; - if ( parameters.length == 2 ) - { - fb.skipNulls = PrimitiveObjectInspectorUtils.getBoolean( - parameters[1], - PrimitiveObjectInspectorFactory.writableBooleanObjectInspector); - } - } + if (!fb.valSet) { + fb.val = ObjectInspectorUtils.copyToStandardObject(parameters[0], inputOI, + ObjectInspectorCopyOption.WRITABLE); + if (!fb.skipNulls || fb.val != null) { + fb.valSet = true; + } + } + } - if ( !fb.valSet ) - { - fb.val = ObjectInspectorUtils.copyToStandardObject(parameters[0], inputOI, ObjectInspectorCopyOption.WRITABLE); - if ( !fb.skipNulls || fb.val != null ) - { - fb.valSet = true; - } - } - } + @Override + public Object terminatePartial(AggregationBuffer agg) throws HiveException { + throw new HiveException("terminatePartial not supported"); + } - @Override - public Object terminatePartial(AggregationBuffer agg) throws HiveException - { - throw new HiveException("terminatePartial not supported"); - } + @Override + public void merge(AggregationBuffer agg, Object partial) throws HiveException { + throw new HiveException("merge not supported"); + } - @Override - public void merge(AggregationBuffer agg, Object partial) throws HiveException - { - throw new HiveException("merge not supported"); - } + @Override + public Object terminate(AggregationBuffer agg) throws HiveException { + return ((FirstValueBuffer) agg).val; + } - @Override - public Object terminate(AggregationBuffer agg) throws HiveException - { - return ((FirstValueBuffer) agg).val; - } - - } + } } - Index: ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFLag.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFLag.java (revision 1507705) +++ ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFLag.java (working copy) @@ -19,6 +19,7 @@ package org.apache.hadoop.hive.ql.udf.generic; import java.util.ArrayList; +import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -26,20 +27,18 @@ import org.apache.hadoop.hive.ql.exec.WindowFunctionDescription; import org.apache.hadoop.hive.ql.metadata.HiveException; -@WindowFunctionDescription -( - description = @Description( - name = "lag", - value = "_FUNC_(expr, amt, default)" - ), - supportsWindow = false, - pivotResult = true +@WindowFunctionDescription ( + description = @Description ( + name = "lag", + value = "_FUNC_(expr, amt, default)"), + supportsWindow = false, + pivotResult = true, + impliesOrder = true ) public class GenericUDAFLag extends GenericUDAFLeadLag { static final Log LOG = LogFactory.getLog(GenericUDAFLag.class.getName()); - @Override protected String functionName() { return "Lag"; @@ -51,17 +50,16 @@ } public static class GenericUDAFLagEvaluator extends GenericUDAFLeadLagEvaluator { - @Override protected LeadLagBuffer getNewLLBuffer() throws HiveException { - return new LagBuffer(); + return new LagBuffer(); } } static class LagBuffer implements LeadLagBuffer { - ArrayList values; + List values; int lagAmt; - ArrayList lagValues; + List lagValues; int lastRowIdx; public void initialize(int lagAmt) { @@ -73,7 +71,7 @@ public void addRow(Object currValue, Object defaultValue) { int row = lastRowIdx + 1; - if ( row < lagAmt) { + if (row < lagAmt) { lagValues.add(defaultValue); } values.add(currValue); @@ -83,15 +81,14 @@ public Object terminate() { /* - * if partition is smaller than the lagAmt; - * the entire partition is in lagValues. + * if partition is smaller than the lagAmt; the entire partition is in lagValues. */ - if ( values.size() < lagAmt ) { + if (values.size() < lagAmt) { return lagValues; } int lastIdx = values.size() - 1; - for(int i = 0; i < lagAmt; i++) { + for (int i = 0; i < lagAmt; i++) { values.remove(lastIdx - i); } values.addAll(0, lagValues); Index: ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFLastValue.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFLastValue.java (revision 1507705) +++ ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFLastValue.java (working copy) @@ -34,131 +34,108 @@ import org.apache.hadoop.hive.serde2.typeinfo.TypeInfo; import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory; -@WindowFunctionDescription(description = @Description(name = "last_value", value = "_FUNC_(x)"), supportsWindow = true, pivotResult = false) -public class GenericUDAFLastValue extends AbstractGenericUDAFResolver -{ - static final Log LOG = LogFactory.getLog(GenericUDAFLastValue.class - .getName()); +@WindowFunctionDescription ( + description = @Description ( + name = "last_value", + value = "_FUNC_(x)" + ), + supportsWindow = true, + pivotResult = false, + impliesOrder = true +) +public class GenericUDAFLastValue extends AbstractGenericUDAFResolver { + static final Log LOG = LogFactory.getLog(GenericUDAFLastValue.class.getName()); - @Override - public GenericUDAFEvaluator getEvaluator(TypeInfo[] parameters) - throws SemanticException - { - if (parameters.length > 2) - { - throw new UDFArgumentTypeException(2, "At most 2 arguments expected"); - } - if ( parameters.length > 1 && !parameters[1].equals(TypeInfoFactory.booleanTypeInfo) ) - { - throw new UDFArgumentTypeException(1, "second argument must be a boolean expression"); - } - return createEvaluator(); - } + @Override + public GenericUDAFEvaluator getEvaluator(TypeInfo[] parameters) throws SemanticException { + if (parameters.length > 2) { + throw new UDFArgumentTypeException(2, "At most 2 arguments expected"); + } + if (parameters.length > 1 && !parameters[1].equals(TypeInfoFactory.booleanTypeInfo)) { + throw new UDFArgumentTypeException(1, "second argument must be a boolean expression"); + } + return createEvaluator(); + } - protected GenericUDAFLastValueEvaluator createEvaluator() - { - return new GenericUDAFLastValueEvaluator(); - } + protected GenericUDAFLastValueEvaluator createEvaluator() { + return new GenericUDAFLastValueEvaluator(); + } - static class LastValueBuffer implements AggregationBuffer - { - Object val; - boolean firstRow; - boolean skipNulls; + static class LastValueBuffer implements AggregationBuffer { + Object val; + boolean firstRow; + boolean skipNulls; - LastValueBuffer() - { - init(); - } + LastValueBuffer() { + init(); + } - void init() - { - val = null; - firstRow = true; - skipNulls = false; - } + void init() { + val = null; + firstRow = true; + skipNulls = false; + } - } + } - public static class GenericUDAFLastValueEvaluator extends - GenericUDAFEvaluator - { - ObjectInspector inputOI; - ObjectInspector outputOI; + public static class GenericUDAFLastValueEvaluator extends GenericUDAFEvaluator { + ObjectInspector inputOI; + ObjectInspector outputOI; - @Override - public ObjectInspector init(Mode m, ObjectInspector[] parameters) - throws HiveException - { - super.init(m, parameters); - if (m != Mode.COMPLETE) - { - throw new HiveException( - "Only COMPLETE mode supported for Rank function"); - } - inputOI = parameters[0]; - outputOI = ObjectInspectorUtils.getStandardObjectInspector(inputOI, - ObjectInspectorCopyOption.WRITABLE); - return outputOI; - } + @Override + public ObjectInspector init(Mode m, ObjectInspector[] parameters) throws HiveException { + super.init(m, parameters); + if (m != Mode.COMPLETE) { + throw new HiveException("Only COMPLETE mode supported for Rank function"); + } + inputOI = parameters[0]; + outputOI = ObjectInspectorUtils.getStandardObjectInspector(inputOI, + ObjectInspectorCopyOption.WRITABLE); + return outputOI; + } - @Override - public AggregationBuffer getNewAggregationBuffer() throws HiveException - { - return new LastValueBuffer(); - } + @Override + public AggregationBuffer getNewAggregationBuffer() throws HiveException { + return new LastValueBuffer(); + } - @Override - public void reset(AggregationBuffer agg) throws HiveException - { - ((LastValueBuffer) agg).init(); - } + @Override + public void reset(AggregationBuffer agg) throws HiveException { + ((LastValueBuffer) agg).init(); + } - @Override - public void iterate(AggregationBuffer agg, Object[] parameters) - throws HiveException - { - LastValueBuffer lb = (LastValueBuffer) agg; - if (lb.firstRow ) - { - lb.firstRow = false; - if ( parameters.length == 2 ) - { - lb.skipNulls = PrimitiveObjectInspectorUtils.getBoolean( - parameters[1], - PrimitiveObjectInspectorFactory.writableBooleanObjectInspector); - } - } + @Override + public void iterate(AggregationBuffer agg, Object[] parameters) throws HiveException { + LastValueBuffer lb = (LastValueBuffer) agg; + if (lb.firstRow) { + lb.firstRow = false; + if (parameters.length == 2) { + lb.skipNulls = PrimitiveObjectInspectorUtils.getBoolean(parameters[1], + PrimitiveObjectInspectorFactory.writableBooleanObjectInspector); + } + } + if (!lb.skipNulls || lb.val != null) { + lb.val = parameters[0]; + } + } - if ( !lb.skipNulls || lb.val != null ) - { - lb.val = parameters[0]; - } - } + @Override + public Object terminatePartial(AggregationBuffer agg) throws HiveException { + throw new HiveException("terminatePartial not supported"); + } - @Override - public Object terminatePartial(AggregationBuffer agg) - throws HiveException - { - throw new HiveException("terminatePartial not supported"); - } + @Override + public void merge(AggregationBuffer agg, Object partial) throws HiveException { + throw new HiveException("merge not supported"); + } - @Override - public void merge(AggregationBuffer agg, Object partial) - throws HiveException - { - throw new HiveException("merge not supported"); - } + @Override + public Object terminate(AggregationBuffer agg) throws HiveException { + LastValueBuffer lb = (LastValueBuffer) agg; + return ObjectInspectorUtils.copyToStandardObject(lb.val, inputOI, + ObjectInspectorCopyOption.WRITABLE); - @Override - public Object terminate(AggregationBuffer agg) throws HiveException - { - LastValueBuffer lb = (LastValueBuffer) agg; - return ObjectInspectorUtils.copyToStandardObject(lb.val, inputOI, - ObjectInspectorCopyOption.WRITABLE); + } + } - } - } - } - Index: ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFLead.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFLead.java (revision 1507705) +++ ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFLead.java (working copy) @@ -19,6 +19,7 @@ package org.apache.hadoop.hive.ql.udf.generic; import java.util.ArrayList; +import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -26,20 +27,18 @@ import org.apache.hadoop.hive.ql.exec.WindowFunctionDescription; import org.apache.hadoop.hive.ql.metadata.HiveException; -@WindowFunctionDescription -( - description = @Description( - name = "lead", - value = "_FUNC_(expr, amt, default)" - ), - supportsWindow = false, - pivotResult = true +@WindowFunctionDescription ( + description = @Description ( + name = "lead", + value = "_FUNC_(expr, amt, default)"), + supportsWindow = false, + pivotResult = true, + impliesOrder = true ) public class GenericUDAFLead extends GenericUDAFLeadLag { static final Log LOG = LogFactory.getLog(GenericUDAFLead.class.getName()); - @Override protected String functionName() { return "Lead"; @@ -47,20 +46,20 @@ @Override protected GenericUDAFLeadLagEvaluator createLLEvaluator() { - return new GenericUDAFLeadEvaluator(); + return new GenericUDAFLeadEvaluator(); } public static class GenericUDAFLeadEvaluator extends GenericUDAFLeadLagEvaluator { @Override protected LeadLagBuffer getNewLLBuffer() throws HiveException { - return new LeadBuffer(); + return new LeadBuffer(); } } static class LeadBuffer implements LeadLagBuffer { - ArrayList values; + List values; int leadAmt; Object[] leadWindow; int nextPosInWindow; @@ -77,7 +76,7 @@ public void addRow(Object leadExprValue, Object defaultValue) { int row = lastRowIdx + 1; int leadRow = row - leadAmt; - if ( leadRow >= 0 ) { + if (leadRow >= 0) { values.add(leadExprValue); } leadWindow[nextPosInWindow] = defaultValue; @@ -87,13 +86,13 @@ public Object terminate() { /* - * if there are fewer than leadAmt values in leadWindow; start reading from the first position. - * Otherwise the window starts from nextPosInWindow. + * if there are fewer than leadAmt values in leadWindow; start reading from the first + * position. Otherwise the window starts from nextPosInWindow. */ - if ( lastRowIdx < leadAmt ) { + if (lastRowIdx < leadAmt) { nextPosInWindow = 0; } - for(int i=0; i < leadAmt; i++) { + for (int i = 0; i < leadAmt; i++) { values.add(leadWindow[nextPosInWindow]); nextPosInWindow = (nextPosInWindow + 1) % leadAmt; } Index: ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFPercentRank.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFPercentRank.java (revision 1507705) +++ ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFPercentRank.java (working copy) @@ -19,6 +19,7 @@ package org.apache.hadoop.hive.ql.udf.generic; import java.util.ArrayList; +import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -31,8 +32,7 @@ import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory; import org.apache.hadoop.io.IntWritable; -@WindowFunctionDescription -( +@WindowFunctionDescription ( description = @Description( name = "percent_rank", value = "_FUNC_(x) PERCENT_RANK is similar to CUME_DIST, but it uses rank values rather " + @@ -42,43 +42,35 @@ supportsWindow = false, pivotResult = true ) -public class GenericUDAFPercentRank extends GenericUDAFRank -{ - static final Log LOG = LogFactory.getLog(GenericUDAFPercentRank.class.getName()); +public class GenericUDAFPercentRank extends GenericUDAFRank { + static final Log LOG = LogFactory.getLog(GenericUDAFPercentRank.class.getName()); - @Override - protected GenericUDAFRankEvaluator createEvaluator() - { - return new GenericUDAFPercentRankEvaluator(); - } + @Override + protected GenericUDAFRankEvaluator createEvaluator() { + return new GenericUDAFPercentRankEvaluator(); + } - public static class GenericUDAFPercentRankEvaluator extends GenericUDAFRankEvaluator - { - @Override - public ObjectInspector init(Mode m, ObjectInspector[] parameters) throws HiveException - { - super.init(m, parameters); - return ObjectInspectorFactory.getStandardListObjectInspector(PrimitiveObjectInspectorFactory.writableDoubleObjectInspector); - } + public static class GenericUDAFPercentRankEvaluator extends GenericUDAFRankEvaluator { + @Override + public ObjectInspector init(Mode m, ObjectInspector[] parameters) throws HiveException { + super.init(m, parameters); + return ObjectInspectorFactory + .getStandardListObjectInspector(PrimitiveObjectInspectorFactory.writableDoubleObjectInspector); + } - @Override - public Object terminate(AggregationBuffer agg) throws HiveException - { - ArrayList ranks = ((RankBuffer) agg).rowNums; - double sz = ranks.size(); - if ( sz > 1 ) { + @Override + public Object terminate(AggregationBuffer agg) throws HiveException { + List ranks = ((RankBuffer) agg).rowNums; + double sz = ranks.size(); + if (sz > 1) { sz = sz - 1; } - ArrayList pranks = new ArrayList(ranks.size()); - - for(IntWritable i : ranks) - { - double pr = ((double)i.get() - 1)/sz; - pranks.add(new DoubleWritable(pr)); - } - - return pranks; - } - } + List pranks = new ArrayList(ranks.size()); + for (IntWritable i : ranks) { + double pr = ((double) i.get() - 1) / sz; + pranks.add(new DoubleWritable(pr)); + } + return pranks; + } + } } - Index: ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFRank.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFRank.java (revision 1507705) +++ ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFRank.java (working copy) @@ -19,6 +19,7 @@ package org.apache.hadoop.hive.ql.udf.generic; import java.util.ArrayList; +import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -37,156 +38,128 @@ import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoUtils; import org.apache.hadoop.io.IntWritable; -@WindowFunctionDescription -( - description = @Description( - name = "rank", - value = "_FUNC_(x)" - ), - supportsWindow = false, - pivotResult = true -) -public class GenericUDAFRank extends AbstractGenericUDAFResolver -{ - static final Log LOG = LogFactory.getLog(GenericUDAFRank.class.getName()); +@WindowFunctionDescription(description = @Description(name = "rank", value = "_FUNC_(x)"), supportsWindow = false, pivotResult = true, impliesOrder = true) +public class GenericUDAFRank extends AbstractGenericUDAFResolver { + static final Log LOG = LogFactory.getLog(GenericUDAFRank.class.getName()); - @Override - public GenericUDAFEvaluator getEvaluator(TypeInfo[] parameters) throws SemanticException - { - if (parameters.length < 1) - { - throw new UDFArgumentTypeException(parameters.length - 1, "One or more arguments are expected."); - } - for(int i=0; i type or complex type containing map<>."); - } - } - return createEvaluator(); - } + @Override + public GenericUDAFEvaluator getEvaluator(TypeInfo[] parameters) throws SemanticException { + if (parameters.length < 1) { + throw new UDFArgumentTypeException(parameters.length - 1, + "One or more arguments are expected."); + } + for (int i = 0; i < parameters.length; i++) { + ObjectInspector oi = TypeInfoUtils.getStandardJavaObjectInspectorFromTypeInfo(parameters[i]); + if (!ObjectInspectorUtils.compareSupported(oi)) { + throw new UDFArgumentTypeException(i, + "Cannot support comparison of map<> type or complex type containing map<>."); + } + } + return createEvaluator(); + } - protected GenericUDAFRankEvaluator createEvaluator() - { - return new GenericUDAFRankEvaluator(); - } + protected GenericUDAFRankEvaluator createEvaluator() { + return new GenericUDAFRankEvaluator(); + } - static class RankBuffer implements AggregationBuffer - { - ArrayList rowNums; - int currentRowNum; - Object[] currVal; - int currentRank; - int numParams; + static class RankBuffer implements AggregationBuffer { + List rowNums; + int currentRowNum; + Object[] currVal; + int currentRank; + int numParams; - RankBuffer(int numParams) - { - this.numParams = numParams; - init(); - } + RankBuffer(int numParams) { + this.numParams = numParams; + init(); + } - void init() - { - rowNums = new ArrayList(); - currentRowNum = 0; - currentRank = 0; - currVal = new Object[numParams]; - } + void init() { + rowNums = new ArrayList(); + currentRowNum = 0; + currentRank = 0; + currVal = new Object[numParams]; + } - void incrRowNum() { currentRowNum++; } + void incrRowNum() { + currentRowNum++; + } - void addRank() - { - rowNums.add(new IntWritable(currentRank)); - } - } + void addRank() { + rowNums.add(new IntWritable(currentRank)); + } + } - public static class GenericUDAFRankEvaluator extends GenericUDAFEvaluator - { - ObjectInspector[] inputOI; - ObjectInspector[] outputOI; + public static class GenericUDAFRankEvaluator extends GenericUDAFEvaluator { + ObjectInspector[] inputOI; + ObjectInspector[] outputOI; - @Override - public ObjectInspector init(Mode m, ObjectInspector[] parameters) throws HiveException - { - super.init(m, parameters); - if (m != Mode.COMPLETE) - { - throw new HiveException( - "Only COMPLETE mode supported for Rank function"); - } - inputOI = parameters; - outputOI = new ObjectInspector[inputOI.length]; - for(int i=0; i < inputOI.length; i++) - { - outputOI[i] = ObjectInspectorUtils.getStandardObjectInspector(inputOI[i], ObjectInspectorCopyOption.JAVA); - } - return ObjectInspectorFactory.getStandardListObjectInspector(PrimitiveObjectInspectorFactory.writableIntObjectInspector); - } + @Override + public ObjectInspector init(Mode m, ObjectInspector[] parameters) throws HiveException { + super.init(m, parameters); + if (m != Mode.COMPLETE) { + throw new HiveException("Only COMPLETE mode supported for Rank function"); + } + inputOI = parameters; + outputOI = new ObjectInspector[inputOI.length]; + for (int i = 0; i < inputOI.length; i++) { + outputOI[i] = ObjectInspectorUtils.getStandardObjectInspector(inputOI[i], + ObjectInspectorCopyOption.JAVA); + } + return ObjectInspectorFactory + .getStandardListObjectInspector(PrimitiveObjectInspectorFactory.writableIntObjectInspector); + } - @Override - public AggregationBuffer getNewAggregationBuffer() throws HiveException - { - return new RankBuffer(inputOI.length); - } + @Override + public AggregationBuffer getNewAggregationBuffer() throws HiveException { + return new RankBuffer(inputOI.length); + } - @Override - public void reset(AggregationBuffer agg) throws HiveException - { - ((RankBuffer) agg).init(); - } + @Override + public void reset(AggregationBuffer agg) throws HiveException { + ((RankBuffer) agg).init(); + } - @Override - public void iterate(AggregationBuffer agg, Object[] parameters) throws HiveException - { - RankBuffer rb = (RankBuffer) agg; - int c = GenericUDAFRank.compare(rb.currVal, outputOI, parameters, inputOI); - rb.incrRowNum(); - if ( rb.currentRowNum == 1 || c != 0 ) - { - nextRank(rb); - rb.currVal = GenericUDAFRank.copyToStandardObject(parameters, inputOI, ObjectInspectorCopyOption.JAVA); - } - rb.addRank(); - } + @Override + public void iterate(AggregationBuffer agg, Object[] parameters) throws HiveException { + RankBuffer rb = (RankBuffer) agg; + int c = GenericUDAFRank.compare(rb.currVal, outputOI, parameters, inputOI); + rb.incrRowNum(); + if (rb.currentRowNum == 1 || c != 0) { + nextRank(rb); + rb.currVal = GenericUDAFRank.copyToStandardObject(parameters, inputOI, + ObjectInspectorCopyOption.JAVA); + } + rb.addRank(); + } - /* - * Called when the value in the partition has changed. Update the currentRank - */ - protected void nextRank(RankBuffer rb) - { - rb.currentRank = rb.currentRowNum; - } + /* + * Called when the value in the partition has changed. Update the currentRank + */ + protected void nextRank(RankBuffer rb) { + rb.currentRank = rb.currentRowNum; + } - @Override - public Object terminatePartial(AggregationBuffer agg) throws HiveException - { - throw new HiveException("terminatePartial not supported"); - } + @Override + public Object terminatePartial(AggregationBuffer agg) throws HiveException { + throw new HiveException("terminatePartial not supported"); + } - @Override - public void merge(AggregationBuffer agg, Object partial) throws HiveException - { - throw new HiveException("merge not supported"); - } + @Override + public void merge(AggregationBuffer agg, Object partial) throws HiveException { + throw new HiveException("merge not supported"); + } - @Override - public Object terminate(AggregationBuffer agg) throws HiveException - { - return ((RankBuffer) agg).rowNums; - } + @Override + public Object terminate(AggregationBuffer agg) throws HiveException { + return ((RankBuffer) agg).rowNums; + } - } + } - public static int compare(Object[] o1, ObjectInspector[] oi1, Object[] o2, - ObjectInspector[] oi2) - { + public static int compare(Object[] o1, ObjectInspector[] oi1, Object[] o2, ObjectInspector[] oi2) { int c = 0; - for (int i = 0; i < oi1.length; i++) - { + for (int i = 0; i < oi1.length; i++) { c = ObjectInspectorUtils.compare(o1[i], oi1[i], o2[i], oi2[i]); if (c != 0) { return c; @@ -195,18 +168,13 @@ return c; } - public static Object[] copyToStandardObject(Object[] o, - ObjectInspector[] oi, - ObjectInspectorCopyOption objectInspectorOption) - { + public static Object[] copyToStandardObject(Object[] o, ObjectInspector[] oi, + ObjectInspectorCopyOption objectInspectorOption) { Object[] out = new Object[o.length]; - for (int i = 0; i < oi.length; i++) - { - out[i] = ObjectInspectorUtils.copyToStandardObject(o[i], oi[i], - objectInspectorOption); + for (int i = 0; i < oi.length; i++) { + out[i] = ObjectInspectorUtils.copyToStandardObject(o[i], oi[i], objectInspectorOption); } return out; } } - Index: ql/src/test/org/apache/hadoop/hive/ql/exec/TestFunctionRegistry.java =================================================================== --- ql/src/test/org/apache/hadoop/hive/ql/exec/TestFunctionRegistry.java (revision 1507705) +++ ql/src/test/org/apache/hadoop/hive/ql/exec/TestFunctionRegistry.java (working copy) @@ -18,20 +18,19 @@ package org.apache.hadoop.hive.ql.exec; +import java.lang.reflect.Method; +import java.util.LinkedList; import java.util.List; -import java.util.LinkedList; -import java.lang.reflect.Method; import junit.framework.TestCase; +import org.apache.hadoop.hive.serde2.io.DoubleWritable; +import org.apache.hadoop.hive.serde2.io.HiveDecimalWritable; +import org.apache.hadoop.hive.serde2.io.TimestampWritable; import org.apache.hadoop.hive.serde2.typeinfo.TypeInfo; -import org.apache.hadoop.hive.serde.serdeConstants; import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory; -import org.apache.hadoop.hive.serde2.io.DoubleWritable; -import org.apache.hadoop.hive.serde2.io.HiveDecimalWritable; +import org.apache.hadoop.io.BytesWritable; import org.apache.hadoop.io.IntWritable; -import org.apache.hadoop.io.BytesWritable; -import org.apache.hadoop.hive.serde2.io.TimestampWritable; public class TestFunctionRegistry extends TestCase { @@ -44,7 +43,7 @@ public void mismatch(TimestampWritable x, HiveDecimalWritable y) {} public void mismatch(BytesWritable x, DoubleWritable y) {} } - + @Override protected void setUp() { } @@ -61,14 +60,14 @@ implicit(TypeInfoFactory.timestampTypeInfo, TypeInfoFactory.decimalTypeInfo, false); } - private void verify(Class udf, String name, TypeInfo ta, TypeInfo tb, + private void verify(Class udf, String name, TypeInfo ta, TypeInfo tb, Class a, Class b, boolean throwException) { List args = new LinkedList(); args.add(ta); args.add(tb); Method result = null; - + try { result = FunctionRegistry.getMethodInternal(udf, name, false, args); } catch (UDFArgumentException e) { @@ -116,13 +115,13 @@ } public void testCommonClass() { - common(TypeInfoFactory.intTypeInfo, TypeInfoFactory.decimalTypeInfo, + common(TypeInfoFactory.intTypeInfo, TypeInfoFactory.decimalTypeInfo, TypeInfoFactory.decimalTypeInfo); - common(TypeInfoFactory.stringTypeInfo, TypeInfoFactory.decimalTypeInfo, + common(TypeInfoFactory.stringTypeInfo, TypeInfoFactory.decimalTypeInfo, TypeInfoFactory.stringTypeInfo); - common(TypeInfoFactory.doubleTypeInfo, TypeInfoFactory.decimalTypeInfo, + common(TypeInfoFactory.doubleTypeInfo, TypeInfoFactory.decimalTypeInfo, TypeInfoFactory.decimalTypeInfo); - common(TypeInfoFactory.doubleTypeInfo, TypeInfoFactory.stringTypeInfo, + common(TypeInfoFactory.doubleTypeInfo, TypeInfoFactory.stringTypeInfo, TypeInfoFactory.stringTypeInfo); } @@ -131,16 +130,21 @@ } public void testCommonClassComparison() { - comparison(TypeInfoFactory.intTypeInfo, TypeInfoFactory.decimalTypeInfo, + comparison(TypeInfoFactory.intTypeInfo, TypeInfoFactory.decimalTypeInfo, TypeInfoFactory.decimalTypeInfo); - comparison(TypeInfoFactory.stringTypeInfo, TypeInfoFactory.decimalTypeInfo, + comparison(TypeInfoFactory.stringTypeInfo, TypeInfoFactory.decimalTypeInfo, TypeInfoFactory.decimalTypeInfo); - comparison(TypeInfoFactory.doubleTypeInfo, TypeInfoFactory.decimalTypeInfo, + comparison(TypeInfoFactory.doubleTypeInfo, TypeInfoFactory.decimalTypeInfo, TypeInfoFactory.decimalTypeInfo); - comparison(TypeInfoFactory.doubleTypeInfo, TypeInfoFactory.stringTypeInfo, + comparison(TypeInfoFactory.doubleTypeInfo, TypeInfoFactory.stringTypeInfo, TypeInfoFactory.doubleTypeInfo); } + public void testImpliedWindow() { + assertTrue(FunctionRegistry.udafsImplyOrder.contains("rank")); + assertFalse(FunctionRegistry.udafsImplyOrder.contains("min")); + } + @Override protected void tearDown() { }