Search in sources :

Example 1 with HiveGenericUDTF

use of org.apache.flink.table.functions.hive.HiveGenericUDTF 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)

Aggregations

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 GenericUDAFEvaluator (org.apache.hadoop.hive.ql.udf.generic.GenericUDAFEvaluator)1 GenericUDAFResolver2 (org.apache.hadoop.hive.ql.udf.generic.GenericUDAFResolver2)1 GenericUDF (org.apache.hadoop.hive.ql.udf.generic.GenericUDF)1