Search in sources :

Example 1 with ScalarFunctionDefinition

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

the class FunctionCatalog method registerTempSystemScalarFunction.

// --------------------------------------------------------------------------------------------
// Legacy function handling before FLIP-65
// --------------------------------------------------------------------------------------------
/**
 * @deprecated Use {@link #registerTemporarySystemFunction(String, FunctionDefinition, boolean)}
 *     instead.
 */
@Deprecated
public void registerTempSystemScalarFunction(String name, ScalarFunction function) {
    UserDefinedFunctionHelper.prepareInstance(config, function);
    registerTempSystemFunction(name, new ScalarFunctionDefinition(name, function));
}
Also used : ScalarFunctionDefinition(org.apache.flink.table.functions.ScalarFunctionDefinition)

Example 2 with ScalarFunctionDefinition

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

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

the class FunctionCatalog method registerTempCatalogScalarFunction.

/**
 * @deprecated Use {@link #registerTemporaryCatalogFunction(UnresolvedIdentifier,
 *     FunctionDefinition, boolean)} instead.
 */
@Deprecated
public void registerTempCatalogScalarFunction(ObjectIdentifier oi, ScalarFunction function) {
    UserDefinedFunctionHelper.prepareInstance(config, function);
    registerTempCatalogFunction(oi, new ScalarFunctionDefinition(oi.getObjectName(), function));
}
Also used : ScalarFunctionDefinition(org.apache.flink.table.functions.ScalarFunctionDefinition)

Example 4 with ScalarFunctionDefinition

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

the class RexNodeJsonSerializer method serializeBridgingSqlFunction.

private static void serializeBridgingSqlFunction(String summaryName, ContextResolvedFunction resolvedFunction, JsonGenerator gen, SerializerProvider serializerProvider, boolean serializeCatalogObjects) throws IOException {
    final FunctionDefinition definition = resolvedFunction.getDefinition();
    if (definition instanceof ScalarFunctionDefinition || definition instanceof TableFunctionDefinition || definition instanceof TableAggregateFunctionDefinition || definition instanceof AggregateFunctionDefinition) {
        throw legacyException(summaryName);
    }
    if (definition instanceof BuiltInFunctionDefinition) {
        final BuiltInFunctionDefinition builtInFunction = (BuiltInFunctionDefinition) definition;
        gen.writeStringField(FIELD_NAME_INTERNAL_NAME, builtInFunction.getQualifiedName());
    } else if (resolvedFunction.isAnonymous()) {
        serializeInlineFunction(summaryName, definition, gen);
    } else if (resolvedFunction.isTemporary()) {
        serializeTemporaryFunction(resolvedFunction, gen, serializerProvider);
    } else {
        assert resolvedFunction.isPermanent();
        serializePermanentFunction(resolvedFunction, gen, serializerProvider, serializeCatalogObjects);
    }
}
Also used : ScalarFunctionDefinition(org.apache.flink.table.functions.ScalarFunctionDefinition) AggregateFunctionDefinition(org.apache.flink.table.functions.AggregateFunctionDefinition) TableAggregateFunctionDefinition(org.apache.flink.table.functions.TableAggregateFunctionDefinition) TableAggregateFunctionDefinition(org.apache.flink.table.functions.TableAggregateFunctionDefinition) BuiltInFunctionDefinition(org.apache.flink.table.functions.BuiltInFunctionDefinition) TableFunctionDefinition(org.apache.flink.table.functions.TableFunctionDefinition) BuiltInFunctionDefinition(org.apache.flink.table.functions.BuiltInFunctionDefinition) AggregateFunctionDefinition(org.apache.flink.table.functions.AggregateFunctionDefinition) TableAggregateFunctionDefinition(org.apache.flink.table.functions.TableAggregateFunctionDefinition) TableFunctionDefinition(org.apache.flink.table.functions.TableFunctionDefinition) ScalarFunctionDefinition(org.apache.flink.table.functions.ScalarFunctionDefinition) FunctionDefinition(org.apache.flink.table.functions.FunctionDefinition)

Example 5 with ScalarFunctionDefinition

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

ScalarFunctionDefinition (org.apache.flink.table.functions.ScalarFunctionDefinition)5 FunctionDefinition (org.apache.flink.table.functions.FunctionDefinition)3 AggregateFunctionDefinition (org.apache.flink.table.functions.AggregateFunctionDefinition)2 BuiltInFunctionDefinition (org.apache.flink.table.functions.BuiltInFunctionDefinition)2 FunctionIdentifier (org.apache.flink.table.functions.FunctionIdentifier)2 TableFunctionDefinition (org.apache.flink.table.functions.TableFunctionDefinition)2 SqlFunction (org.apache.calcite.sql.SqlFunction)1 ScalarFunction (org.apache.flink.table.functions.ScalarFunction)1 TableAggregateFunctionDefinition (org.apache.flink.table.functions.TableAggregateFunctionDefinition)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