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