Search in sources :

Example 1 with GenericUDAFResolver

use of org.apache.hadoop.hive.ql.udf.generic.GenericUDAFResolver 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 GenericUDAFResolver

use of org.apache.hadoop.hive.ql.udf.generic.GenericUDAFResolver 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)

Example 3 with GenericUDAFResolver

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

the class SubQueryUtils method checkForSubqueries.

static void checkForSubqueries(ASTNode node, boolean disallow) throws SemanticException {
    // allow NOT but throw an error for rest
    if (node.getType() == HiveParser.TOK_SUBQUERY_EXPR && disallow) {
        throw new CalciteSubquerySemanticException(ErrorMsg.UNSUPPORTED_SUBQUERY_EXPRESSION.getMsg("Invalid subquery. Subquery in UDAF is not allowed."));
    }
    if (node.getType() == HiveParser.TOK_FUNCTION || node.getType() == HiveParser.TOK_FUNCTIONDI || node.getType() == HiveParser.TOK_FUNCTIONSTAR) {
        if (node.getChild(0).getType() == HiveParser.Identifier) {
            String functionName = SemanticAnalyzer.unescapeIdentifier(node.getChild(0).getText());
            GenericUDAFResolver udafResolver = FunctionRegistry.getGenericUDAFResolver(functionName);
            if (udafResolver != null) {
                disallow = disallow || true;
            }
        }
    }
    for (int i = 0; i < node.getChildCount(); i++) {
        checkForSubqueries((ASTNode) node.getChild(i), disallow);
    }
}
Also used : GenericUDAFResolver(org.apache.hadoop.hive.ql.udf.generic.GenericUDAFResolver) CalciteSubquerySemanticException(org.apache.hadoop.hive.ql.optimizer.calcite.CalciteSubquerySemanticException)

Example 4 with GenericUDAFResolver

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

the class AggregationBase method getEvaluator.

public static GenericUDAFEvaluator getEvaluator(String aggregationFunctionName, TypeInfo typeInfo) throws SemanticException {
    GenericUDAFResolver resolver = FunctionRegistry.getGenericUDAFResolver(aggregationFunctionName);
    TypeInfo[] parameters = new TypeInfo[] { typeInfo };
    GenericUDAFEvaluator evaluator = resolver.getEvaluator(parameters);
    return evaluator;
}
Also used : GenericUDAFEvaluator(org.apache.hadoop.hive.ql.udf.generic.GenericUDAFEvaluator) GenericUDAFResolver(org.apache.hadoop.hive.ql.udf.generic.GenericUDAFResolver) PrimitiveTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo) TypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfo)

Example 5 with GenericUDAFResolver

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

the class Registry method getGenericWindowingEvaluator.

public GenericUDAFEvaluator getGenericWindowingEvaluator(String functionName, List<ObjectInspector> argumentOIs, boolean isDistinct, boolean isAllColumns, boolean respectNulls) throws SemanticException {
    functionName = functionName.toLowerCase();
    WindowFunctionInfo info = getWindowFunctionInfo(functionName);
    if (info == null) {
        return null;
    }
    if (!functionName.equals(FunctionRegistry.LEAD_FUNC_NAME) && !functionName.equals(FunctionRegistry.LAG_FUNC_NAME)) {
        return getGenericUDAFEvaluator(functionName, argumentOIs, true, isDistinct, isAllColumns, respectNulls);
    }
    // this must be lead/lag UDAF
    ObjectInspector[] args = new ObjectInspector[argumentOIs.size()];
    GenericUDAFResolver udafResolver = info.getGenericUDAFResolver();
    GenericUDAFParameterInfo paramInfo = new SimpleGenericUDAFParameterInfo(argumentOIs.toArray(args), true, isDistinct, isAllColumns);
    return ((GenericUDAFResolver2) udafResolver).getEvaluator(paramInfo);
}
Also used : SimpleGenericUDAFParameterInfo(org.apache.hadoop.hive.ql.udf.generic.SimpleGenericUDAFParameterInfo) GenericUDAFResolver2(org.apache.hadoop.hive.ql.udf.generic.GenericUDAFResolver2) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) GenericUDAFParameterInfo(org.apache.hadoop.hive.ql.udf.generic.GenericUDAFParameterInfo) SimpleGenericUDAFParameterInfo(org.apache.hadoop.hive.ql.udf.generic.SimpleGenericUDAFParameterInfo) GenericUDAFResolver(org.apache.hadoop.hive.ql.udf.generic.GenericUDAFResolver)

Aggregations

GenericUDAFResolver (org.apache.hadoop.hive.ql.udf.generic.GenericUDAFResolver)6 GenericUDAFCount (org.apache.hadoop.hive.ql.udf.generic.GenericUDAFCount)2 GenericUDAFEvaluator (org.apache.hadoop.hive.ql.udf.generic.GenericUDAFEvaluator)2 GenericUDAFParameterInfo (org.apache.hadoop.hive.ql.udf.generic.GenericUDAFParameterInfo)2 GenericUDAFResolver2 (org.apache.hadoop.hive.ql.udf.generic.GenericUDAFResolver2)2 SimpleGenericUDAFParameterInfo (org.apache.hadoop.hive.ql.udf.generic.SimpleGenericUDAFParameterInfo)2 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)2 CalciteSubquerySemanticException (org.apache.hadoop.hive.ql.optimizer.calcite.CalciteSubquerySemanticException)1 PrimitiveTypeInfo (org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo)1 TypeInfo (org.apache.hadoop.hive.serde2.typeinfo.TypeInfo)1