use of org.apache.flink.table.types.inference.TypeInference in project flink by splunk.
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 splunk.
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-mirror by flink-ci.
the class FunctionCatalogOperatorTable method convertToBridgingSqlFunction.
private Optional<SqlFunction> convertToBridgingSqlFunction(@Nullable SqlFunctionCategory category, ContextResolvedFunction resolvedFunction) {
final FunctionDefinition definition = resolvedFunction.getDefinition();
if (!verifyFunctionKind(category, resolvedFunction)) {
return Optional.empty();
}
final TypeInference typeInference;
try {
typeInference = definition.getTypeInference(dataTypeFactory);
} catch (Throwable t) {
throw new ValidationException(String.format("An error occurred in the type inference logic of function '%s'.", resolvedFunction), t);
}
if (typeInference.getOutputTypeStrategy() == TypeStrategies.MISSING) {
return Optional.empty();
}
final SqlFunction function;
if (definition.getKind() == FunctionKind.AGGREGATE || definition.getKind() == FunctionKind.TABLE_AGGREGATE) {
function = BridgingSqlAggFunction.of(dataTypeFactory, typeFactory, SqlKind.OTHER_FUNCTION, resolvedFunction, typeInference);
} else {
function = BridgingSqlFunction.of(dataTypeFactory, typeFactory, SqlKind.OTHER_FUNCTION, resolvedFunction, typeInference);
}
return Optional.of(function);
}
use of org.apache.flink.table.types.inference.TypeInference in project flink-mirror by flink-ci.
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);
}
use of org.apache.flink.table.types.inference.TypeInference in project flink-mirror by flink-ci.
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);
}
Aggregations