Search in sources :

Example 1 with FunctionIdentifier

use of org.apache.flink.table.functions.FunctionIdentifier in project flink by apache.

the class SqlAggFunctionVisitor method createLegacySqlTableAggregateFunction.

private SqlAggFunction createLegacySqlTableAggregateFunction(@Nullable FunctionIdentifier identifier, TableAggregateFunctionDefinition definition) {
    final TableAggregateFunction<?, ?> aggFunc = definition.getTableAggregateFunction();
    final FunctionIdentifier adjustedIdentifier;
    if (identifier != null) {
        adjustedIdentifier = identifier;
    } else {
        adjustedIdentifier = FunctionIdentifier.of(generateInlineFunctionName(aggFunc));
    }
    return new AggSqlFunction(adjustedIdentifier, aggFunc.toString(), aggFunc, fromLegacyInfoToDataType(definition.getResultTypeInfo()), fromLegacyInfoToDataType(definition.getAccumulatorTypeInfo()), ShortcutUtils.unwrapTypeFactory(relBuilder), false, scala.Option.empty());
}
Also used : FunctionIdentifier(org.apache.flink.table.functions.FunctionIdentifier) AggSqlFunction(org.apache.flink.table.planner.functions.utils.AggSqlFunction)

Example 2 with FunctionIdentifier

use of org.apache.flink.table.functions.FunctionIdentifier in project flink by apache.

the class SqlAggFunctionVisitor method createLegacySqlAggregateFunction.

private SqlAggFunction createLegacySqlAggregateFunction(@Nullable FunctionIdentifier identifier, AggregateFunctionDefinition definition) {
    final AggregateFunction<?, ?> aggFunc = definition.getAggregateFunction();
    final FunctionIdentifier adjustedIdentifier;
    if (identifier != null) {
        adjustedIdentifier = identifier;
    } else {
        adjustedIdentifier = FunctionIdentifier.of(generateInlineFunctionName(aggFunc));
    }
    return new AggSqlFunction(adjustedIdentifier, aggFunc.toString(), aggFunc, fromLegacyInfoToDataType(definition.getResultTypeInfo()), fromLegacyInfoToDataType(definition.getAccumulatorTypeInfo()), ShortcutUtils.unwrapTypeFactory(relBuilder), aggFunc.getRequirements().contains(FunctionRequirement.OVER_WINDOW_ONLY), scala.Option.empty());
}
Also used : FunctionIdentifier(org.apache.flink.table.functions.FunctionIdentifier) AggSqlFunction(org.apache.flink.table.planner.functions.utils.AggSqlFunction)

Example 3 with FunctionIdentifier

use of org.apache.flink.table.functions.FunctionIdentifier in project flink by apache.

the class LegacyScalarFunctionConvertRule method convert.

@Override
public Optional<RexNode> convert(CallExpression call, ConvertContext context) {
    FunctionDefinition def = call.getFunctionDefinition();
    if (def instanceof ScalarFunctionDefinition) {
        ScalarFunction scalaFunc = ((ScalarFunctionDefinition) def).getScalarFunction();
        FunctionIdentifier identifier = call.getFunctionIdentifier().orElse(FunctionIdentifier.of(generateInlineFunctionName(scalaFunc)));
        SqlFunction sqlFunction = UserDefinedFunctionUtils.createScalarSqlFunction(identifier, scalaFunc.toString(), scalaFunc, context.getTypeFactory());
        return Optional.of(context.getRelBuilder().call(sqlFunction, toRexNodes(context, call.getChildren())));
    }
    return Optional.empty();
}
Also used : FunctionIdentifier(org.apache.flink.table.functions.FunctionIdentifier) ScalarFunctionDefinition(org.apache.flink.table.functions.ScalarFunctionDefinition) ScalarFunction(org.apache.flink.table.functions.ScalarFunction) ScalarFunctionDefinition(org.apache.flink.table.functions.ScalarFunctionDefinition) FunctionDefinition(org.apache.flink.table.functions.FunctionDefinition) SqlFunction(org.apache.calcite.sql.SqlFunction)

Example 4 with FunctionIdentifier

use of org.apache.flink.table.functions.FunctionIdentifier in project flink by apache.

the class RexNodeJsonDeserializer method deserializeCatalogFunction.

private static SqlOperator deserializeCatalogFunction(JsonNode jsonNode, SqlSyntax syntax, SerdeContext serdeContext) {
    final CatalogPlanRestore restoreStrategy = serdeContext.getConfiguration().get(PLAN_RESTORE_CATALOG_OBJECTS);
    final FunctionIdentifier identifier = FunctionIdentifier.of(ObjectIdentifierJsonDeserializer.deserialize(jsonNode.required(FIELD_NAME_CATALOG_NAME).asText(), serdeContext));
    switch(restoreStrategy) {
        case ALL:
            {
                final Optional<SqlOperator> lookupOperator = lookupOptionalSqlOperator(identifier, syntax, serdeContext, false);
                if (lookupOperator.isPresent()) {
                    return lookupOperator.get();
                } else if (jsonNode.has(FIELD_NAME_CLASS)) {
                    return deserializeFunctionClass(jsonNode, serdeContext);
                }
                throw missingFunctionFromCatalog(identifier, false);
            }
        case ALL_ENFORCED:
            {
                if (jsonNode.has(FIELD_NAME_CLASS)) {
                    return deserializeFunctionClass(jsonNode, serdeContext);
                }
                final Optional<SqlOperator> lookupOperator = lookupOptionalSqlOperator(identifier, syntax, serdeContext, false);
                if (lookupOperator.map(RexNodeJsonDeserializer::isTemporary).orElse(false)) {
                    return lookupOperator.get();
                }
                throw lookupDisabled(identifier);
            }
        case IDENTIFIER:
            final Optional<SqlOperator> lookupOperator = lookupOptionalSqlOperator(identifier, syntax, serdeContext, true);
            if (lookupOperator.isPresent()) {
                return lookupOperator.get();
            } else {
                throw missingFunctionFromCatalog(identifier, true);
            }
        default:
            throw new TableException("Unsupported restore strategy: " + restoreStrategy);
    }
}
Also used : FunctionIdentifier(org.apache.flink.table.functions.FunctionIdentifier) TableException(org.apache.flink.table.api.TableException) Optional(java.util.Optional) BuiltInSqlOperator(org.apache.flink.table.planner.functions.sql.BuiltInSqlOperator) SqlOperator(org.apache.calcite.sql.SqlOperator) CatalogPlanRestore(org.apache.flink.table.api.config.TableConfigOptions.CatalogPlanRestore)

Example 5 with FunctionIdentifier

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

FunctionIdentifier (org.apache.flink.table.functions.FunctionIdentifier)5 FunctionDefinition (org.apache.flink.table.functions.FunctionDefinition)2 ScalarFunctionDefinition (org.apache.flink.table.functions.ScalarFunctionDefinition)2 AggSqlFunction (org.apache.flink.table.planner.functions.utils.AggSqlFunction)2 Optional (java.util.Optional)1 SqlFunction (org.apache.calcite.sql.SqlFunction)1 SqlOperator (org.apache.calcite.sql.SqlOperator)1 TableException (org.apache.flink.table.api.TableException)1 CatalogPlanRestore (org.apache.flink.table.api.config.TableConfigOptions.CatalogPlanRestore)1 AggregateFunctionDefinition (org.apache.flink.table.functions.AggregateFunctionDefinition)1 BuiltInFunctionDefinition (org.apache.flink.table.functions.BuiltInFunctionDefinition)1 ScalarFunction (org.apache.flink.table.functions.ScalarFunction)1 TableFunctionDefinition (org.apache.flink.table.functions.TableFunctionDefinition)1 BuiltInSqlOperator (org.apache.flink.table.planner.functions.sql.BuiltInSqlOperator)1 HiveAggSqlFunction (org.apache.flink.table.planner.functions.utils.HiveAggSqlFunction)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 TypeConversions.fromLegacyInfoToDataType (org.apache.flink.table.types.utils.TypeConversions.fromLegacyInfoToDataType)1 Row (org.apache.flink.types.Row)1