use of org.apache.flink.table.types.inference.TypeInference in project flink by apache.
the class SqlAggFunctionVisitor method createSqlAggFunction.
private SqlAggFunction createSqlAggFunction(CallExpression call) {
final FunctionDefinition definition = call.getFunctionDefinition();
// legacy
if (definition instanceof AggregateFunctionDefinition) {
return createLegacySqlAggregateFunction(call.getFunctionIdentifier().orElse(null), (AggregateFunctionDefinition) definition);
} else if (definition instanceof TableAggregateFunctionDefinition) {
return createLegacySqlTableAggregateFunction(call.getFunctionIdentifier().orElse(null), (TableAggregateFunctionDefinition) definition);
}
// new stack
final DataTypeFactory dataTypeFactory = ShortcutUtils.unwrapContext(relBuilder).getCatalogManager().getDataTypeFactory();
final TypeInference typeInference = definition.getTypeInference(dataTypeFactory);
return BridgingSqlAggFunction.of(dataTypeFactory, ShortcutUtils.unwrapTypeFactory(relBuilder), SqlKind.OTHER_FUNCTION, ContextResolvedFunction.fromCallExpression(call), typeInference);
}
use of org.apache.flink.table.types.inference.TypeInference 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.types.inference.TypeInference in project flink by apache.
the class LastDatedValueFunction method getTypeInference.
// --------------------------------------------------------------------------------------------
// Planning
// --------------------------------------------------------------------------------------------
/**
* Declares the {@link TypeInference} of this function. It specifies:
*
* <ul>
* <li>which argument types are supported when calling this function,
* <li>which {@link DataType#getConversionClass()} should be used when calling the JVM method
* {@link #accumulate(Accumulator, Object, LocalDate)} during runtime,
* <li>a similar strategy how to derive an accumulator type,
* <li>and a similar strategy how to derive the output type.
* </ul>
*/
@Override
public TypeInference getTypeInference(DataTypeFactory typeFactory) {
return TypeInference.newBuilder().inputTypeStrategy(InputTypeStrategies.sequence(InputTypeStrategies.ANY, InputTypeStrategies.explicit(DataTypes.DATE()))).accumulatorTypeStrategy(callContext -> {
final DataType argDataType = callContext.getArgumentDataTypes().get(0);
final DataType accDataType = DataTypes.STRUCTURED(Accumulator.class, DataTypes.FIELD("value", argDataType), DataTypes.FIELD("date", DataTypes.DATE()));
return Optional.of(accDataType);
}).outputTypeStrategy(callContext -> {
final DataType argDataType = callContext.getArgumentDataTypes().get(0);
final DataType outputDataType = DataTypes.ROW(DataTypes.FIELD("value", argDataType), DataTypes.FIELD("date", DataTypes.DATE()));
return Optional.of(outputDataType);
}).build();
}
use of org.apache.flink.table.types.inference.TypeInference in project flink by apache.
the class BridgingSqlAggFunction method of.
/**
* Creates an instance of a aggregate function during translation.
*/
public static BridgingSqlAggFunction of(FlinkContext context, FlinkTypeFactory typeFactory, ContextResolvedFunction resolvedFunction) {
final DataTypeFactory dataTypeFactory = context.getCatalogManager().getDataTypeFactory();
final TypeInference typeInference = resolvedFunction.getDefinition().getTypeInference(dataTypeFactory);
return of(dataTypeFactory, typeFactory, SqlKind.OTHER_FUNCTION, resolvedFunction, typeInference);
}
use of org.apache.flink.table.types.inference.TypeInference in project flink by apache.
the class BridgingSqlFunction method of.
/**
* Creates an instance of a scalar or table function during translation.
*/
public static BridgingSqlFunction of(FlinkContext context, FlinkTypeFactory typeFactory, ContextResolvedFunction resolvedFunction) {
final DataTypeFactory dataTypeFactory = context.getCatalogManager().getDataTypeFactory();
final TypeInference typeInference = resolvedFunction.getDefinition().getTypeInference(dataTypeFactory);
return of(dataTypeFactory, typeFactory, SqlKind.OTHER_FUNCTION, resolvedFunction, typeInference);
}
Aggregations