Search in sources :

Example 1 with TypeStrategy

use of org.apache.flink.table.types.inference.TypeStrategy in project flink by apache.

the class MappingTypeStrategy method inferType.

@Override
public Optional<DataType> inferType(CallContext callContext) {
    final List<LogicalType> actualTypes = callContext.getArgumentDataTypes().stream().map(DataType::getLogicalType).collect(Collectors.toList());
    for (Map.Entry<InputTypeStrategy, TypeStrategy> mapping : mappings.entrySet()) {
        final InputTypeStrategy inputStrategy = mapping.getKey();
        final TypeStrategy strategy = mapping.getValue();
        if (!inputStrategy.getArgumentCount().isValidCount(actualTypes.size())) {
            continue;
        }
        final Optional<List<DataType>> inferredDataTypes = inputStrategy.inferInputTypes(callContext, false);
        if (!inferredDataTypes.isPresent()) {
            continue;
        }
        final List<LogicalType> inferredTypes = inferredDataTypes.get().stream().map(DataType::getLogicalType).collect(Collectors.toList());
        if (supportsAvoidingCast(actualTypes, inferredTypes)) {
            return strategy.inferType(callContext);
        }
    }
    return Optional.empty();
}
Also used : InputTypeStrategy(org.apache.flink.table.types.inference.InputTypeStrategy) InputTypeStrategy(org.apache.flink.table.types.inference.InputTypeStrategy) TypeStrategy(org.apache.flink.table.types.inference.TypeStrategy) LogicalType(org.apache.flink.table.types.logical.LogicalType) List(java.util.List) Map(java.util.Map)

Aggregations

List (java.util.List)1 Map (java.util.Map)1 InputTypeStrategy (org.apache.flink.table.types.inference.InputTypeStrategy)1 TypeStrategy (org.apache.flink.table.types.inference.TypeStrategy)1 LogicalType (org.apache.flink.table.types.logical.LogicalType)1