Search in sources :

Example 36 with GenericUDF

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

the class ExprNodeDescUtils method foldConstant.

private static ExprNodeConstantDesc foldConstant(ExprNodeGenericFuncDesc func) {
    GenericUDF udf = func.getGenericUDF();
    if (!FunctionRegistry.isConsistentWithinQuery(udf)) {
        return null;
    }
    try {
        // resources may not be available at compile time.
        if (udf instanceof GenericUDFBridge) {
            UDF internal = ReflectionUtils.newInstance(((GenericUDFBridge) udf).getUdfClass(), null);
            if (internal.getRequiredFiles() != null || internal.getRequiredJars() != null) {
                return null;
            }
        } else {
            if (udf.getRequiredFiles() != null || udf.getRequiredJars() != null) {
                return null;
            }
        }
        if (func.getChildren() != null) {
            for (ExprNodeDesc child : func.getChildren()) {
                if (child instanceof ExprNodeConstantDesc) {
                    continue;
                }
                if (child instanceof ExprNodeGenericFuncDesc) {
                    if (foldConstant((ExprNodeGenericFuncDesc) child) != null) {
                        continue;
                    }
                }
                return null;
            }
        }
        ExprNodeEvaluator evaluator = ExprNodeEvaluatorFactory.get(func);
        ObjectInspector output = evaluator.initialize(null);
        Object constant = evaluator.evaluate(null);
        Object java = ObjectInspectorUtils.copyToStandardJavaObject(constant, output);
        return new ExprNodeConstantDesc(java);
    } catch (Exception e) {
        return null;
    }
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) GenericUDF(org.apache.hadoop.hive.ql.udf.generic.GenericUDF) UDF(org.apache.hadoop.hive.ql.exec.UDF) GenericUDF(org.apache.hadoop.hive.ql.udf.generic.GenericUDF) ExprNodeEvaluator(org.apache.hadoop.hive.ql.exec.ExprNodeEvaluator) GenericUDFBridge(org.apache.hadoop.hive.ql.udf.generic.GenericUDFBridge) SemanticException(org.apache.hadoop.hive.ql.parse.SemanticException)

Aggregations

GenericUDF (org.apache.hadoop.hive.ql.udf.generic.GenericUDF)36 ExprNodeDesc (org.apache.hadoop.hive.ql.plan.ExprNodeDesc)26 ExprNodeGenericFuncDesc (org.apache.hadoop.hive.ql.plan.ExprNodeGenericFuncDesc)26 ArrayList (java.util.ArrayList)20 ExprNodeColumnDesc (org.apache.hadoop.hive.ql.plan.ExprNodeColumnDesc)19 ExprNodeConstantDesc (org.apache.hadoop.hive.ql.plan.ExprNodeConstantDesc)13 Test (org.junit.Test)13 GenericUDFBridge (org.apache.hadoop.hive.ql.udf.generic.GenericUDFBridge)7 VectorExpression (org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression)6 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)6 ExprNodeFieldDesc (org.apache.hadoop.hive.ql.plan.ExprNodeFieldDesc)5 GenericUDFBaseCompare (org.apache.hadoop.hive.ql.udf.generic.GenericUDFBaseCompare)5 List (java.util.List)4 DynamicValueVectorExpression (org.apache.hadoop.hive.ql.exec.vector.expressions.DynamicValueVectorExpression)4 SemanticException (org.apache.hadoop.hive.ql.parse.SemanticException)4 GenericUDFOPAnd (org.apache.hadoop.hive.ql.udf.generic.GenericUDFOPAnd)4 LinkedList (java.util.LinkedList)3 SelectOperator (org.apache.hadoop.hive.ql.exec.SelectOperator)3 UDF (org.apache.hadoop.hive.ql.exec.UDF)3 UDFArgumentException (org.apache.hadoop.hive.ql.exec.UDFArgumentException)3