use of org.apache.flink.table.functions.hive.HiveGenericUDAF in project flink by apache.
the class HiveParserUtils method getGenericUDAFEvaluator.
// Returns the GenericUDAFEvaluator for the aggregation. This is called once for each GroupBy
// aggregation.
// TODO: Requiring a GenericUDAFEvaluator means we only support hive UDAFs. Need to avoid this
// to support flink UDAFs.
public static GenericUDAFEvaluator getGenericUDAFEvaluator(String aggName, ArrayList<ExprNodeDesc> aggParameters, HiveParserASTNode aggTree, boolean isDistinct, boolean isAllColumns, SqlOperatorTable opTable) throws SemanticException {
ArrayList<ObjectInspector> originalParameterTypeInfos = getWritableObjectInspector(aggParameters);
GenericUDAFEvaluator result = FunctionRegistry.getGenericUDAFEvaluator(aggName, originalParameterTypeInfos, isDistinct, isAllColumns);
if (result == null) {
// this happens for temp functions
SqlOperator sqlOperator = getSqlOperator(aggName, opTable, SqlFunctionCategory.USER_DEFINED_FUNCTION);
if (sqlOperator instanceof HiveAggSqlFunction) {
HiveGenericUDAF hiveGenericUDAF = (HiveGenericUDAF) ((HiveAggSqlFunction) sqlOperator).makeFunction(new Object[0], new LogicalType[0]);
result = hiveGenericUDAF.createEvaluator(originalParameterTypeInfos.toArray(new ObjectInspector[0]));
}
}
if (null == result) {
String reason = "Looking for UDAF Evaluator\"" + aggName + "\" with parameters " + originalParameterTypeInfos;
throw new SemanticException(HiveParserErrorMsg.getMsg(ErrorMsg.INVALID_FUNCTION_SIGNATURE, aggTree.getChild(0), reason));
}
return result;
}
use of org.apache.flink.table.functions.hive.HiveGenericUDAF 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));
}
}
Aggregations