Search in sources :

Example 1 with GenericUDFBridge

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

the class IndexPredicateAnalyzer method getColumnExpr.

// Check if ExprNodeColumnDesc is wrapped in expr.
// If so, peel off. Otherwise return itself.
private ExprNodeDesc getColumnExpr(ExprNodeDesc expr) {
    if (expr instanceof ExprNodeColumnDesc) {
        return expr;
    }
    ExprNodeGenericFuncDesc funcDesc = null;
    if (expr instanceof ExprNodeGenericFuncDesc) {
        funcDesc = (ExprNodeGenericFuncDesc) expr;
    }
    if (null == funcDesc) {
        return expr;
    }
    GenericUDF udf = funcDesc.getGenericUDF();
    // check if its a simple cast expression.
    if ((udf instanceof GenericUDFBridge || udf instanceof GenericUDFToBinary || udf instanceof GenericUDFToChar || udf instanceof GenericUDFToVarchar || udf instanceof GenericUDFToDecimal || udf instanceof GenericUDFToDate || udf instanceof GenericUDFToUnixTimeStamp || udf instanceof GenericUDFToUtcTimestamp) && funcDesc.getChildren().size() == 1 && funcDesc.getChildren().get(0) instanceof ExprNodeColumnDesc) {
        return expr.getChildren().get(0);
    }
    return expr;
}
Also used : GenericUDFToChar(org.apache.hadoop.hive.ql.udf.generic.GenericUDFToChar) GenericUDF(org.apache.hadoop.hive.ql.udf.generic.GenericUDF) ExprNodeColumnDesc(org.apache.hadoop.hive.ql.plan.ExprNodeColumnDesc) GenericUDFToDecimal(org.apache.hadoop.hive.ql.udf.generic.GenericUDFToDecimal) GenericUDFToUnixTimeStamp(org.apache.hadoop.hive.ql.udf.generic.GenericUDFToUnixTimeStamp) ExprNodeGenericFuncDesc(org.apache.hadoop.hive.ql.plan.ExprNodeGenericFuncDesc) GenericUDFToBinary(org.apache.hadoop.hive.ql.udf.generic.GenericUDFToBinary) GenericUDFToDate(org.apache.hadoop.hive.ql.udf.generic.GenericUDFToDate) GenericUDFToUtcTimestamp(org.apache.hadoop.hive.ql.udf.generic.GenericUDFToUtcTimestamp) GenericUDFBridge(org.apache.hadoop.hive.ql.udf.generic.GenericUDFBridge) GenericUDFToVarchar(org.apache.hadoop.hive.ql.udf.generic.GenericUDFToVarchar)

Example 2 with GenericUDFBridge

use of org.apache.hadoop.hive.ql.udf.generic.GenericUDFBridge in project drill by axbaretto.

the class HiveFunctionRegistry method matchAndCreateUDFHolder.

private HiveFuncHolder matchAndCreateUDFHolder(String udfName, Class<? extends UDF> udfClazz, MajorType[] argTypes, ObjectInspector[] argOIs) {
    try {
        GenericUDF udfInstance = new GenericUDFBridge(udfName, false, /* is operator */
        udfClazz.getName());
        ObjectInspector returnOI = udfInstance.initialize(argOIs);
        return new HiveFuncHolder(udfName, udfClazz, argTypes, returnOI, Types.optional(ObjectInspectorHelper.getDrillType(returnOI)), nonDeterministicUDFs.contains(udfClazz));
    } catch (Exception e) {
    /*ignore this*/
    }
    return null;
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) GenericUDF(org.apache.hadoop.hive.ql.udf.generic.GenericUDF) GenericUDFBridge(org.apache.hadoop.hive.ql.udf.generic.GenericUDFBridge) UserException(org.apache.drill.common.exceptions.UserException)

Example 3 with GenericUDFBridge

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

the class HiveParserSqlFunctionConverter method getName.

// TODO: this is not valid. Function names for built-in UDFs are specified in
// FunctionRegistry, and only happen to match annotations. For user UDFs, the
// name is what user specifies at creation time (annotation can be absent,
// different, or duplicate some other function).
private static String getName(GenericUDF hiveUDF) {
    String udfName = null;
    if (hiveUDF instanceof GenericUDFBridge) {
        udfName = hiveUDF.getUdfName();
    } else {
        Class<? extends GenericUDF> udfClass = hiveUDF.getClass();
        Description udfAnnotation = udfClass.getAnnotation(Description.class);
        if (udfAnnotation != null) {
            udfName = udfAnnotation.name();
            if (udfName != null) {
                String[] aliases = udfName.split(",");
                if (aliases.length > 0) {
                    udfName = aliases[0];
                }
            }
        }
        if (udfName == null || udfName.isEmpty()) {
            udfName = hiveUDF.getClass().getName();
            int indx = udfName.lastIndexOf(".");
            if (indx >= 0) {
                indx += 1;
                udfName = udfName.substring(indx);
            }
        }
    }
    return udfName;
}
Also used : Description(org.apache.hadoop.hive.ql.exec.Description) GenericUDFBridge(org.apache.hadoop.hive.ql.udf.generic.GenericUDFBridge)

Example 4 with GenericUDFBridge

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

the class Registry method registerUDF.

private FunctionInfo registerUDF(String functionName, FunctionType functionType, Class<? extends UDF> UDFClass, boolean isOperator, String displayName, FunctionResource... resources) {
    validateClass(UDFClass, UDF.class);
    validateDescription(UDFClass);
    FunctionInfo fI = new FunctionInfo(functionType, displayName, new GenericUDFBridge(displayName, isOperator, UDFClass.getName()), resources);
    addFunction(functionName, fI);
    return fI;
}
Also used : GenericUDFBridge(org.apache.hadoop.hive.ql.udf.generic.GenericUDFBridge)

Example 5 with GenericUDFBridge

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

the class KafkaScanTrimmer method getColumnExpr.

@SuppressWarnings("Duplicates")
private static ExprNodeDesc getColumnExpr(ExprNodeDesc expr) {
    if (expr instanceof ExprNodeColumnDesc) {
        return expr;
    }
    ExprNodeGenericFuncDesc funcDesc = null;
    if (expr instanceof ExprNodeGenericFuncDesc) {
        funcDesc = (ExprNodeGenericFuncDesc) expr;
    }
    if (null == funcDesc) {
        return expr;
    }
    GenericUDF udf = funcDesc.getGenericUDF();
    // check if its a simple cast expression.
    if ((udf instanceof GenericUDFBridge || udf instanceof GenericUDFToBinary || udf instanceof GenericUDFToChar || udf instanceof GenericUDFToVarchar || udf instanceof GenericUDFToDecimal || udf instanceof GenericUDFToDate || udf instanceof GenericUDFToUnixTimeStamp || udf instanceof GenericUDFToUtcTimestamp) && funcDesc.getChildren().size() == 1 && funcDesc.getChildren().get(0) instanceof ExprNodeColumnDesc) {
        return expr.getChildren().get(0);
    }
    return expr;
}
Also used : GenericUDFToChar(org.apache.hadoop.hive.ql.udf.generic.GenericUDFToChar) GenericUDF(org.apache.hadoop.hive.ql.udf.generic.GenericUDF) ExprNodeColumnDesc(org.apache.hadoop.hive.ql.plan.ExprNodeColumnDesc) GenericUDFToDecimal(org.apache.hadoop.hive.ql.udf.generic.GenericUDFToDecimal) GenericUDFToUnixTimeStamp(org.apache.hadoop.hive.ql.udf.generic.GenericUDFToUnixTimeStamp) ExprNodeGenericFuncDesc(org.apache.hadoop.hive.ql.plan.ExprNodeGenericFuncDesc) GenericUDFToBinary(org.apache.hadoop.hive.ql.udf.generic.GenericUDFToBinary) GenericUDFToDate(org.apache.hadoop.hive.ql.udf.generic.GenericUDFToDate) GenericUDFToUtcTimestamp(org.apache.hadoop.hive.ql.udf.generic.GenericUDFToUtcTimestamp) GenericUDFBridge(org.apache.hadoop.hive.ql.udf.generic.GenericUDFBridge) GenericUDFToVarchar(org.apache.hadoop.hive.ql.udf.generic.GenericUDFToVarchar)

Aggregations

GenericUDFBridge (org.apache.hadoop.hive.ql.udf.generic.GenericUDFBridge)22 GenericUDF (org.apache.hadoop.hive.ql.udf.generic.GenericUDF)12 ExprNodeColumnDesc (org.apache.hadoop.hive.ql.plan.ExprNodeColumnDesc)10 ExprNodeGenericFuncDesc (org.apache.hadoop.hive.ql.plan.ExprNodeGenericFuncDesc)10 ArrayList (java.util.ArrayList)7 ExprNodeDesc (org.apache.hadoop.hive.ql.plan.ExprNodeDesc)7 Test (org.junit.Test)6 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)5 UDF (org.apache.hadoop.hive.ql.exec.UDF)4 GenericUDFToUnixTimeStamp (org.apache.hadoop.hive.ql.udf.generic.GenericUDFToUnixTimeStamp)4 TypeInfo (org.apache.hadoop.hive.serde2.typeinfo.TypeInfo)4 UDFArgumentException (org.apache.hadoop.hive.ql.exec.UDFArgumentException)3 VectorExpression (org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression)3 SemanticException (org.apache.hadoop.hive.ql.parse.SemanticException)3 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)3 Description (org.apache.hadoop.hive.ql.exec.Description)2 ExprNodeEvaluator (org.apache.hadoop.hive.ql.exec.ExprNodeEvaluator)2 VectorizedRowBatch (org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch)2 UDFYear (org.apache.hadoop.hive.ql.udf.UDFYear)2 GenericUDFToBinary (org.apache.hadoop.hive.ql.udf.generic.GenericUDFToBinary)2