Index: ql/src/test/org/apache/hadoop/hive/ql/exec/TestFunctionRegistry.java =================================================================== --- ql/src/test/org/apache/hadoop/hive/ql/exec/TestFunctionRegistry.java (revision 1508590) +++ ql/src/test/org/apache/hadoop/hive/ql/exec/TestFunctionRegistry.java (working copy) @@ -22,6 +22,7 @@ import java.util.LinkedList; import java.util.List; +import junit.framework.Assert; import junit.framework.TestCase; import org.apache.hadoop.hive.serde2.io.DateWritable; @@ -146,4 +147,12 @@ @Override protected void tearDown() { } + + public void testIsRankingFunction() { + Assert.assertTrue(FunctionRegistry.isRankingFunction("rank")); + Assert.assertTrue(FunctionRegistry.isRankingFunction("dense_rank")); + Assert.assertTrue(FunctionRegistry.isRankingFunction("percent_rank")); + Assert.assertTrue(FunctionRegistry.isRankingFunction("cume_dist")); + Assert.assertFalse(FunctionRegistry.isRankingFunction("min")); + } } 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 1508590) +++ ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFRank.java (working copy) @@ -44,7 +44,8 @@ value = "_FUNC_(x)" ), supportsWindow = false, - pivotResult = true + pivotResult = true, + rankingFunction = true ) public class GenericUDAFRank extends AbstractGenericUDAFResolver { 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 1508590) +++ ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFPercentRank.java (working copy) @@ -40,7 +40,8 @@ "(rank of row in its partition - 1) / (number of rows in the partition - 1)" ), supportsWindow = false, - pivotResult = true + pivotResult = true, + rankingFunction = true ) public class GenericUDAFPercentRank extends GenericUDAFRank { 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 1508590) +++ ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFDenseRank.java (working copy) @@ -34,7 +34,8 @@ "that the next person came in third." ), supportsWindow = false, - pivotResult = true + pivotResult = true, + rankingFunction = true ) public class GenericUDAFDenseRank extends GenericUDAFRank { 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 1508590) +++ ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFCumeDist.java (working copy) @@ -43,7 +43,8 @@ " and including x in the specified order/ N" ), supportsWindow = false, - pivotResult = true + pivotResult = true, + rankingFunction = true ) public class GenericUDAFCumeDist extends GenericUDAFRank { Index: ql/src/java/org/apache/hadoop/hive/ql/parse/PTFTranslator.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/parse/PTFTranslator.java (revision 1508590) +++ ql/src/java/org/apache/hadoop/hive/ql/parse/PTFTranslator.java (working copy) @@ -425,8 +425,7 @@ } } - if (RANKING_FUNCS.contains(spec.getName())) - { + if (FunctionRegistry.isRankingFunction(spec.getName())){ setupRankingArgs(wdwTFnDef, def, spec); } @@ -785,19 +784,6 @@ return combinedOrdExprs; } - - /* - * Ranking Functions helpers - */ - - protected static final ArrayList RANKING_FUNCS = new ArrayList(); - static { - RANKING_FUNCS.add("rank"); - RANKING_FUNCS.add("dense_rank"); - RANKING_FUNCS.add("percent_rank"); - RANKING_FUNCS.add("cume_dist"); - }; - private void setupRankingArgs(WindowTableFunctionDef wdwTFnDef, WindowFunctionDef wFnDef, WindowFunctionSpec wSpec) Index: ql/src/java/org/apache/hadoop/hive/ql/exec/WindowFunctionDescription.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/exec/WindowFunctionDescription.java (revision 1508590) +++ ql/src/java/org/apache/hadoop/hive/ql/exec/WindowFunctionDescription.java (working copy) @@ -50,5 +50,11 @@ * for all the rows. */ boolean pivotResult() default false; + + /** + * Used in translations process to validate arguments + * @return true if ranking function + */ + boolean rankingFunction() default false; } Index: ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java (revision 1508590) +++ ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java (working copy) @@ -1480,4 +1480,23 @@ mFunctions.put(name.toLowerCase(), tInfo); } + /** + * Use this to check if function is ranking function + * + * @param name + * name of a function + * @return true if function is a UDAF, has WindowFunctionDescription annotation and the annotations + * confirms a ranking function, false otherwise + */ + public static boolean isRankingFunction(String name){ + FunctionInfo info = mFunctions.get(name.toLowerCase()); + GenericUDAFResolver res = info.getGenericUDAFResolver(); + if (res != null){ + WindowFunctionDescription desc = res.getClass().getAnnotation(WindowFunctionDescription.class); + if (desc != null){ + return desc.rankingFunction(); + } + } + return false; + } }