Search in sources :

Example 1 with GenericUDAFCount

use of org.apache.hadoop.hive.ql.udf.generic.GenericUDAFCount in project flink by apache.

the class HiveParserSubQueryUtils method checkAggOrWindowing.

/*
     * is this expr a UDAF invocation; does it imply windowing
     * @return
     * 0 if implies neither
     * 1 if implies aggregation
     * 2 if implies count
     * 3 if implies windowing
     */
static int checkAggOrWindowing(HiveParserASTNode expressionTree) throws SemanticException {
    int exprTokenType = expressionTree.getToken().getType();
    if (exprTokenType == HiveASTParser.TOK_FUNCTION || exprTokenType == HiveASTParser.TOK_FUNCTIONDI || exprTokenType == HiveASTParser.TOK_FUNCTIONSTAR) {
        assert (expressionTree.getChildCount() != 0);
        if (expressionTree.getChild(expressionTree.getChildCount() - 1).getType() == HiveASTParser.TOK_WINDOWSPEC) {
            return 3;
        }
        if (expressionTree.getChild(0).getType() == HiveASTParser.Identifier) {
            String functionName = HiveParserBaseSemanticAnalyzer.unescapeIdentifier(expressionTree.getChild(0).getText());
            GenericUDAFResolver udafResolver = FunctionRegistry.getGenericUDAFResolver(functionName);
            if (udafResolver != null) {
                // corr subqueries.
                if (udafResolver instanceof GenericUDAFCount) {
                    return 2;
                }
                return 1;
            }
        }
    }
    int r = 0;
    for (int i = 0; i < expressionTree.getChildCount(); i++) {
        int c = checkAggOrWindowing((HiveParserASTNode) expressionTree.getChild(i));
        r = Math.max(r, c);
    }
    return r;
}
Also used : GenericUDAFResolver(org.apache.hadoop.hive.ql.udf.generic.GenericUDAFResolver) GenericUDAFCount(org.apache.hadoop.hive.ql.udf.generic.GenericUDAFCount)

Example 2 with GenericUDAFCount

use of org.apache.hadoop.hive.ql.udf.generic.GenericUDAFCount in project hive by apache.

the class SubQueryUtils method checkAggOrWindowing.

/*
   * is this expr a UDAF invocation; does it imply windowing
   * @return
   * 0 if implies neither
   * 1 if implies aggregation
   * 2 if implies count
   * 3 if implies windowing
   */
static int checkAggOrWindowing(ASTNode expressionTree) throws SemanticException {
    int exprTokenType = expressionTree.getToken().getType();
    if (exprTokenType == HiveParser.TOK_FUNCTION || exprTokenType == HiveParser.TOK_FUNCTIONDI || exprTokenType == HiveParser.TOK_FUNCTIONSTAR) {
        assert (expressionTree.getChildCount() != 0);
        if (expressionTree.getChild(expressionTree.getChildCount() - 1).getType() == HiveParser.TOK_WINDOWSPEC) {
            return 3;
        }
        if (expressionTree.getChild(0).getType() == HiveParser.Identifier) {
            String functionName = SemanticAnalyzer.unescapeIdentifier(expressionTree.getChild(0).getText());
            GenericUDAFResolver udafResolver = FunctionRegistry.getGenericUDAFResolver(functionName);
            if (udafResolver != null) {
                // corr subqueries.
                if (udafResolver instanceof GenericUDAFCount) {
                    return 2;
                }
                return 1;
            }
        }
    }
    int r = 0;
    for (int i = 0; i < expressionTree.getChildCount(); i++) {
        int c = checkAggOrWindowing((ASTNode) expressionTree.getChild(i));
        r = Math.max(r, c);
    }
    return r;
}
Also used : GenericUDAFResolver(org.apache.hadoop.hive.ql.udf.generic.GenericUDAFResolver) GenericUDAFCount(org.apache.hadoop.hive.ql.udf.generic.GenericUDAFCount)

Aggregations

GenericUDAFCount (org.apache.hadoop.hive.ql.udf.generic.GenericUDAFCount)2 GenericUDAFResolver (org.apache.hadoop.hive.ql.udf.generic.GenericUDAFResolver)2