Search in sources :

Example 1 with GenericUDAFResolver2

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

the class HiveFunctionDefinitionFactory method createFunctionDefinitionFromHiveFunction.

/**
 * Create a FunctionDefinition from a Hive function's class name. Called directly by {@link
 * org.apache.flink.table.module.hive.HiveModule}.
 */
public FunctionDefinition createFunctionDefinitionFromHiveFunction(String name, String functionClassName) {
    Class clazz;
    try {
        clazz = Thread.currentThread().getContextClassLoader().loadClass(functionClassName);
        LOG.info("Successfully loaded Hive udf '{}' with class '{}'", name, functionClassName);
    } catch (ClassNotFoundException e) {
        throw new TableException(String.format("Failed to initiate an instance of class %s.", functionClassName), e);
    }
    if (UDF.class.isAssignableFrom(clazz)) {
        LOG.info("Transforming Hive function '{}' into a HiveSimpleUDF", name);
        return new HiveSimpleUDF(new HiveFunctionWrapper<>(functionClassName), hiveShim);
    } else if (GenericUDF.class.isAssignableFrom(clazz)) {
        LOG.info("Transforming Hive function '{}' into a HiveGenericUDF", name);
        return new HiveGenericUDF(new HiveFunctionWrapper<>(functionClassName), hiveShim);
    } else if (GenericUDTF.class.isAssignableFrom(clazz)) {
        LOG.info("Transforming Hive function '{}' into a HiveGenericUDTF", name);
        HiveGenericUDTF udtf = new HiveGenericUDTF(new HiveFunctionWrapper<>(functionClassName), hiveShim);
        return new TableFunctionDefinition(name, udtf, GenericTypeInfo.of(Row.class));
    } else if (GenericUDAFResolver2.class.isAssignableFrom(clazz) || UDAF.class.isAssignableFrom(clazz)) {
        HiveGenericUDAF udaf;
        if (GenericUDAFResolver2.class.isAssignableFrom(clazz)) {
            LOG.info("Transforming Hive function '{}' into a HiveGenericUDAF without UDAF bridging", name);
            udaf = new HiveGenericUDAF(new HiveFunctionWrapper<>(functionClassName), false, hiveShim);
        } else {
            LOG.info("Transforming Hive function '{}' into a HiveGenericUDAF with UDAF bridging", name);
            udaf = new HiveGenericUDAF(new HiveFunctionWrapper<>(functionClassName), true, hiveShim);
        }
        return new AggregateFunctionDefinition(name, udaf, GenericTypeInfo.of(Object.class), GenericTypeInfo.of(GenericUDAFEvaluator.AggregationBuffer.class));
    } else {
        throw new IllegalArgumentException(String.format("HiveFunctionDefinitionFactory cannot initiate FunctionDefinition for class %s", functionClassName));
    }
}
Also used : GenericUDAFResolver2(org.apache.hadoop.hive.ql.udf.generic.GenericUDAFResolver2) TableException(org.apache.flink.table.api.TableException) GenericUDAFEvaluator(org.apache.hadoop.hive.ql.udf.generic.GenericUDAFEvaluator) HiveGenericUDAF(org.apache.flink.table.functions.hive.HiveGenericUDAF) TableFunctionDefinition(org.apache.flink.table.functions.TableFunctionDefinition) GenericUDF(org.apache.hadoop.hive.ql.udf.generic.GenericUDF) HiveGenericUDF(org.apache.flink.table.functions.hive.HiveGenericUDF) AggregateFunctionDefinition(org.apache.flink.table.functions.AggregateFunctionDefinition) HiveGenericUDTF(org.apache.flink.table.functions.hive.HiveGenericUDTF) HiveSimpleUDF(org.apache.flink.table.functions.hive.HiveSimpleUDF) Row(org.apache.flink.types.Row) HiveGenericUDF(org.apache.flink.table.functions.hive.HiveGenericUDF) HiveFunctionWrapper(org.apache.flink.table.functions.hive.HiveFunctionWrapper)

Example 2 with GenericUDAFResolver2

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

Example 3 with GenericUDAFResolver2

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

the class Registry method getGenericUDAFEvaluator.

/**
 * Get the GenericUDAF evaluator for the name and argumentClasses.
 *
 * @param name         the name of the UDAF
 * @param argumentOIs
 * @param isDistinct
 * @param isAllColumns
 * @return The UDAF evaluator
 */
@SuppressWarnings("deprecation")
public GenericUDAFEvaluator getGenericUDAFEvaluator(String name, List<ObjectInspector> argumentOIs, boolean isWindowing, boolean isDistinct, boolean isAllColumns, boolean respectNulls) throws SemanticException {
    GenericUDAFResolver udafResolver = getGenericUDAFResolver(name);
    if (udafResolver == null) {
        return null;
    }
    GenericUDAFEvaluator udafEvaluator;
    ObjectInspector[] args = new ObjectInspector[argumentOIs.size()];
    // generics + arrays.
    for (int ii = 0; ii < argumentOIs.size(); ++ii) {
        args[ii] = argumentOIs.get(ii);
    }
    GenericUDAFParameterInfo paramInfo = new SimpleGenericUDAFParameterInfo(args, isWindowing, isDistinct, isAllColumns, respectNulls);
    if (udafResolver instanceof GenericUDAFResolver2) {
        udafEvaluator = ((GenericUDAFResolver2) udafResolver).getEvaluator(paramInfo);
    } else {
        udafEvaluator = udafResolver.getEvaluator(paramInfo.getParameters());
    }
    return udafEvaluator;
}
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) GenericUDAFEvaluator(org.apache.hadoop.hive.ql.udf.generic.GenericUDAFEvaluator) 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

GenericUDAFResolver2 (org.apache.hadoop.hive.ql.udf.generic.GenericUDAFResolver2)3 GenericUDAFEvaluator (org.apache.hadoop.hive.ql.udf.generic.GenericUDAFEvaluator)2 GenericUDAFParameterInfo (org.apache.hadoop.hive.ql.udf.generic.GenericUDAFParameterInfo)2 GenericUDAFResolver (org.apache.hadoop.hive.ql.udf.generic.GenericUDAFResolver)2 SimpleGenericUDAFParameterInfo (org.apache.hadoop.hive.ql.udf.generic.SimpleGenericUDAFParameterInfo)2 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)2 TableException (org.apache.flink.table.api.TableException)1 AggregateFunctionDefinition (org.apache.flink.table.functions.AggregateFunctionDefinition)1 TableFunctionDefinition (org.apache.flink.table.functions.TableFunctionDefinition)1 HiveFunctionWrapper (org.apache.flink.table.functions.hive.HiveFunctionWrapper)1 HiveGenericUDAF (org.apache.flink.table.functions.hive.HiveGenericUDAF)1 HiveGenericUDF (org.apache.flink.table.functions.hive.HiveGenericUDF)1 HiveGenericUDTF (org.apache.flink.table.functions.hive.HiveGenericUDTF)1 HiveSimpleUDF (org.apache.flink.table.functions.hive.HiveSimpleUDF)1 Row (org.apache.flink.types.Row)1 GenericUDF (org.apache.hadoop.hive.ql.udf.generic.GenericUDF)1