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