use of org.apache.flink.table.types.inference.InputTypeStrategy in project flink by apache.
the class FunctionSignatureTemplate method toInputTypeStrategy.
InputTypeStrategy toInputTypeStrategy() {
final ArgumentTypeStrategy[] argumentStrategies = argumentTemplates.stream().map(FunctionArgumentTemplate::toArgumentTypeStrategy).toArray(ArgumentTypeStrategy[]::new);
final InputTypeStrategy strategy;
if (isVarArgs) {
if (argumentNames == null) {
strategy = InputTypeStrategies.varyingSequence(argumentStrategies);
} else {
strategy = InputTypeStrategies.varyingSequence(argumentNames, argumentStrategies);
}
} else {
if (argumentNames == null) {
strategy = InputTypeStrategies.sequence(argumentStrategies);
} else {
strategy = InputTypeStrategies.sequence(argumentNames, argumentStrategies);
}
}
return strategy;
}
use of org.apache.flink.table.types.inference.InputTypeStrategy 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();
}
use of org.apache.flink.table.types.inference.InputTypeStrategy in project flink by apache.
the class OrInputTypeStrategy method inferInputTypes.
@Override
public Optional<List<DataType>> inferInputTypes(CallContext callContext, boolean throwOnFailure) {
final List<LogicalType> actualTypes = callContext.getArgumentDataTypes().stream().map(DataType::getLogicalType).collect(Collectors.toList());
Optional<List<DataType>> closestDataTypes = Optional.empty();
for (InputTypeStrategy inputStrategy : inputStrategies) {
final Optional<List<DataType>> inferredDataTypes = inputStrategy.inferInputTypes(callContext, false);
// types do not match at all
if (!inferredDataTypes.isPresent()) {
continue;
}
final List<LogicalType> inferredTypes = inferredDataTypes.get().stream().map(DataType::getLogicalType).collect(Collectors.toList());
// types match
if (supportsAvoidingCast(actualTypes, inferredTypes)) {
return inferredDataTypes;
} else // type matches with some casting
if (!closestDataTypes.isPresent()) {
closestDataTypes = inferredDataTypes;
}
}
return closestDataTypes;
}
Aggregations