Search in sources :

Example 1 with InputTypeStrategy

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;
}
Also used : InputTypeStrategy(org.apache.flink.table.types.inference.InputTypeStrategy) ArgumentTypeStrategy(org.apache.flink.table.types.inference.ArgumentTypeStrategy)

Example 2 with InputTypeStrategy

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

Example 3 with InputTypeStrategy

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;
}
Also used : InputTypeStrategy(org.apache.flink.table.types.inference.InputTypeStrategy) LogicalType(org.apache.flink.table.types.logical.LogicalType) AbstractList(java.util.AbstractList) List(java.util.List)

Aggregations

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