Search in sources :

Example 1 with HiveAggSqlFunction

use of org.apache.flink.table.planner.functions.utils.HiveAggSqlFunction 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;
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) GenericUDAFEvaluator(org.apache.hadoop.hive.ql.udf.generic.GenericUDAFEvaluator) SqlOperator(org.apache.calcite.sql.SqlOperator) HiveGenericUDAF(org.apache.flink.table.functions.hive.HiveGenericUDAF) LogicalType(org.apache.flink.table.types.logical.LogicalType) NlsString(org.apache.calcite.util.NlsString) HiveAggSqlFunction(org.apache.flink.table.planner.functions.utils.HiveAggSqlFunction) SemanticException(org.apache.hadoop.hive.ql.parse.SemanticException)

Example 2 with HiveAggSqlFunction

use of org.apache.flink.table.planner.functions.utils.HiveAggSqlFunction in project flink by apache.

the class FunctionCatalogOperatorTable method convertToSqlFunction.

private Optional<SqlFunction> convertToSqlFunction(@Nullable SqlFunctionCategory category, ContextResolvedFunction resolvedFunction) {
    final FunctionDefinition definition = resolvedFunction.getDefinition();
    final FunctionIdentifier identifier = resolvedFunction.getIdentifier().orElse(null);
    // legacy
    if (definition instanceof AggregateFunctionDefinition) {
        AggregateFunctionDefinition def = (AggregateFunctionDefinition) definition;
        if (isHiveFunc(def.getAggregateFunction())) {
            return Optional.of(new HiveAggSqlFunction(identifier, def.getAggregateFunction(), typeFactory));
        } else {
            return convertAggregateFunction(identifier, (AggregateFunctionDefinition) definition);
        }
    } else if (definition instanceof ScalarFunctionDefinition) {
        ScalarFunctionDefinition def = (ScalarFunctionDefinition) definition;
        return convertScalarFunction(identifier, def);
    } else if (definition instanceof TableFunctionDefinition && category != null && category.isTableFunction()) {
        TableFunctionDefinition def = (TableFunctionDefinition) definition;
        if (isHiveFunc(def.getTableFunction())) {
            DataType returnType = fromLegacyInfoToDataType(new GenericTypeInfo<>(Row.class));
            return Optional.of(new HiveTableSqlFunction(identifier, def.getTableFunction(), returnType, typeFactory, new DeferredTypeFlinkTableFunction(def.getTableFunction(), returnType), HiveTableSqlFunction.operandTypeChecker(identifier.toString(), def.getTableFunction())));
        } else {
            return convertTableFunction(identifier, (TableFunctionDefinition) definition);
        }
    }
    // new stack
    return convertToBridgingSqlFunction(category, resolvedFunction);
}
Also used : FunctionIdentifier(org.apache.flink.table.functions.FunctionIdentifier) ScalarFunctionDefinition(org.apache.flink.table.functions.ScalarFunctionDefinition) DeferredTypeFlinkTableFunction(org.apache.flink.table.planner.plan.schema.DeferredTypeFlinkTableFunction) AggregateFunctionDefinition(org.apache.flink.table.functions.AggregateFunctionDefinition) TableFunctionDefinition(org.apache.flink.table.functions.TableFunctionDefinition) DataType(org.apache.flink.table.types.DataType) TypeConversions.fromLegacyInfoToDataType(org.apache.flink.table.types.utils.TypeConversions.fromLegacyInfoToDataType) BuiltInFunctionDefinition(org.apache.flink.table.functions.BuiltInFunctionDefinition) AggregateFunctionDefinition(org.apache.flink.table.functions.AggregateFunctionDefinition) TableFunctionDefinition(org.apache.flink.table.functions.TableFunctionDefinition) ScalarFunctionDefinition(org.apache.flink.table.functions.ScalarFunctionDefinition) FunctionDefinition(org.apache.flink.table.functions.FunctionDefinition) Row(org.apache.flink.types.Row) HiveAggSqlFunction(org.apache.flink.table.planner.functions.utils.HiveAggSqlFunction) HiveTableSqlFunction(org.apache.flink.table.planner.functions.utils.HiveTableSqlFunction)

Aggregations

HiveAggSqlFunction (org.apache.flink.table.planner.functions.utils.HiveAggSqlFunction)2 SqlOperator (org.apache.calcite.sql.SqlOperator)1 NlsString (org.apache.calcite.util.NlsString)1 AggregateFunctionDefinition (org.apache.flink.table.functions.AggregateFunctionDefinition)1 BuiltInFunctionDefinition (org.apache.flink.table.functions.BuiltInFunctionDefinition)1 FunctionDefinition (org.apache.flink.table.functions.FunctionDefinition)1 FunctionIdentifier (org.apache.flink.table.functions.FunctionIdentifier)1 ScalarFunctionDefinition (org.apache.flink.table.functions.ScalarFunctionDefinition)1 TableFunctionDefinition (org.apache.flink.table.functions.TableFunctionDefinition)1 HiveGenericUDAF (org.apache.flink.table.functions.hive.HiveGenericUDAF)1 HiveTableSqlFunction (org.apache.flink.table.planner.functions.utils.HiveTableSqlFunction)1 DeferredTypeFlinkTableFunction (org.apache.flink.table.planner.plan.schema.DeferredTypeFlinkTableFunction)1 DataType (org.apache.flink.table.types.DataType)1 LogicalType (org.apache.flink.table.types.logical.LogicalType)1 TypeConversions.fromLegacyInfoToDataType (org.apache.flink.table.types.utils.TypeConversions.fromLegacyInfoToDataType)1 Row (org.apache.flink.types.Row)1 SemanticException (org.apache.hadoop.hive.ql.parse.SemanticException)1 GenericUDAFEvaluator (org.apache.hadoop.hive.ql.udf.generic.GenericUDAFEvaluator)1 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)1