Search in sources :

Example 1 with BuiltInFunctionDefinition

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

the class FunctionCatalogOperatorTable method verifyFunctionKind.

/**
 * Verifies which kinds of functions are allowed to be returned from the catalog given the
 * context information.
 */
private boolean verifyFunctionKind(@Nullable SqlFunctionCategory category, ContextResolvedFunction resolvedFunction) {
    final FunctionDefinition definition = resolvedFunction.getDefinition();
    // built-in functions without implementation are handled separately
    if (definition instanceof BuiltInFunctionDefinition) {
        final BuiltInFunctionDefinition builtInFunction = (BuiltInFunctionDefinition) definition;
        if (!builtInFunction.hasRuntimeImplementation()) {
            return false;
        }
    }
    final FunctionKind kind = definition.getKind();
    if (kind == FunctionKind.TABLE) {
        return true;
    } else if (kind == FunctionKind.SCALAR || kind == FunctionKind.AGGREGATE || kind == FunctionKind.TABLE_AGGREGATE) {
        if (category != null && category.isTableFunction()) {
            throw new ValidationException(String.format("Function '%s' cannot be used as a table function.", resolvedFunction));
        }
        return true;
    }
    return false;
}
Also used : ValidationException(org.apache.flink.table.api.ValidationException) BuiltInFunctionDefinition(org.apache.flink.table.functions.BuiltInFunctionDefinition) 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) FunctionKind(org.apache.flink.table.functions.FunctionKind)

Example 2 with BuiltInFunctionDefinition

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

the class FunctionDefinitionConvertRule method convert.

@Override
public Optional<RexNode> convert(CallExpression call, ConvertContext context) {
    final FunctionDefinition definition = call.getFunctionDefinition();
    // built-in functions without implementation are handled separately
    if (definition instanceof BuiltInFunctionDefinition) {
        final BuiltInFunctionDefinition builtInFunction = (BuiltInFunctionDefinition) definition;
        if (!builtInFunction.hasRuntimeImplementation()) {
            return Optional.empty();
        }
    }
    final TypeInference typeInference = definition.getTypeInference(context.getDataTypeFactory());
    if (typeInference.getOutputTypeStrategy() == TypeStrategies.MISSING) {
        return Optional.empty();
    }
    switch(definition.getKind()) {
        case SCALAR:
        case TABLE:
            final List<RexNode> args = call.getChildren().stream().map(context::toRexNode).collect(Collectors.toList());
            final BridgingSqlFunction sqlFunction = BridgingSqlFunction.of(context.getDataTypeFactory(), context.getTypeFactory(), SqlKind.OTHER_FUNCTION, ContextResolvedFunction.fromCallExpression(call), typeInference);
            return Optional.of(context.getRelBuilder().call(sqlFunction, args));
        default:
            return Optional.empty();
    }
}
Also used : TypeInference(org.apache.flink.table.types.inference.TypeInference) BuiltInFunctionDefinition(org.apache.flink.table.functions.BuiltInFunctionDefinition) BridgingSqlFunction(org.apache.flink.table.planner.functions.bridging.BridgingSqlFunction) BuiltInFunctionDefinition(org.apache.flink.table.functions.BuiltInFunctionDefinition) FunctionDefinition(org.apache.flink.table.functions.FunctionDefinition) RexNode(org.apache.calcite.rex.RexNode)

Example 3 with BuiltInFunctionDefinition

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

Aggregations

BuiltInFunctionDefinition (org.apache.flink.table.functions.BuiltInFunctionDefinition)3 FunctionDefinition (org.apache.flink.table.functions.FunctionDefinition)3 AggregateFunctionDefinition (org.apache.flink.table.functions.AggregateFunctionDefinition)2 ScalarFunctionDefinition (org.apache.flink.table.functions.ScalarFunctionDefinition)2 TableFunctionDefinition (org.apache.flink.table.functions.TableFunctionDefinition)2 RexNode (org.apache.calcite.rex.RexNode)1 ValidationException (org.apache.flink.table.api.ValidationException)1 FunctionKind (org.apache.flink.table.functions.FunctionKind)1 TableAggregateFunctionDefinition (org.apache.flink.table.functions.TableAggregateFunctionDefinition)1 BridgingSqlFunction (org.apache.flink.table.planner.functions.bridging.BridgingSqlFunction)1 TypeInference (org.apache.flink.table.types.inference.TypeInference)1