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;
}
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();
}
}
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);
}
}
Aggregations