use of org.apache.flink.table.types.inference.ArgumentTypeStrategy 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.ArgumentTypeStrategy in project flink by apache.
the class AndArgumentTypeStrategy method inferArgumentType.
@Override
public Optional<DataType> inferArgumentType(CallContext callContext, int argumentPos, boolean throwOnFailure) {
final DataType actualDataType = callContext.getArgumentDataTypes().get(argumentPos);
final LogicalType actualType = actualDataType.getLogicalType();
Optional<DataType> closestDataType = Optional.empty();
for (ArgumentTypeStrategy strategy : argumentStrategies) {
final Optional<DataType> inferredDataType = strategy.inferArgumentType(callContext, argumentPos, throwOnFailure);
// argument type does not match at all
if (!inferredDataType.isPresent()) {
return Optional.empty();
}
final LogicalType inferredType = inferredDataType.get().getLogicalType();
// a more specific, casted argument type is available
if (!supportsAvoidingCast(actualType, inferredType) && !closestDataType.isPresent()) {
closestDataType = inferredDataType;
}
}
if (closestDataType.isPresent()) {
return closestDataType;
}
return Optional.of(actualDataType);
}
use of org.apache.flink.table.types.inference.ArgumentTypeStrategy in project flink by apache.
the class OrArgumentTypeStrategy method inferArgumentType.
@Override
public Optional<DataType> inferArgumentType(CallContext callContext, int argumentPos, boolean throwOnFailure) {
final LogicalType actualType = callContext.getArgumentDataTypes().get(argumentPos).getLogicalType();
Optional<DataType> closestDataType = Optional.empty();
for (ArgumentTypeStrategy strategy : argumentStrategies) {
final Optional<DataType> inferredDataType = strategy.inferArgumentType(callContext, argumentPos, false);
// argument type does not match at all
if (!inferredDataType.isPresent()) {
continue;
}
final LogicalType inferredType = inferredDataType.get().getLogicalType();
// we prefer a strategy that does not require an implicit cast
if (supportsAvoidingCast(actualType, inferredType)) {
return inferredDataType;
} else // argument type requires a more specific, casted type
if (!closestDataType.isPresent()) {
closestDataType = inferredDataType;
}
}
if (closestDataType.isPresent()) {
return closestDataType;
}
// generate a helpful exception if possible
if (throwOnFailure) {
for (ArgumentTypeStrategy strategy : argumentStrategies) {
strategy.inferArgumentType(callContext, argumentPos, true);
}
}
return Optional.empty();
}
use of org.apache.flink.table.types.inference.ArgumentTypeStrategy in project flink by apache.
the class RepeatingSequenceInputTypeStrategy method inferInputTypes.
@Override
public Optional<List<DataType>> inferInputTypes(CallContext callContext, boolean throwOnFailure) {
final List<DataType> dataTypes = callContext.getArgumentDataTypes();
final List<DataType> inferredDataTypes = new ArrayList<>(dataTypes.size());
for (int i = 0; i < callContext.getArgumentDataTypes().size(); i++) {
final ArgumentTypeStrategy argumentStrategy = argumentStrategies.get(i % argumentStrategies.size());
final Optional<DataType> inferredDataType = argumentStrategy.inferArgumentType(callContext, i, throwOnFailure);
if (!inferredDataType.isPresent()) {
return Optional.empty();
}
inferredDataTypes.add(inferredDataType.get());
}
return Optional.of(inferredDataTypes);
}
use of org.apache.flink.table.types.inference.ArgumentTypeStrategy in project flink by apache.
the class SequenceInputTypeStrategy method inferInputTypes.
@Override
public Optional<List<DataType>> inferInputTypes(CallContext callContext, boolean throwOnFailure) {
final List<DataType> dataTypes = callContext.getArgumentDataTypes();
if (dataTypes.size() != argumentStrategies.size()) {
return Optional.empty();
}
final List<DataType> inferredDataTypes = new ArrayList<>(dataTypes.size());
for (int i = 0; i < argumentStrategies.size(); i++) {
final ArgumentTypeStrategy argumentTypeStrategy = argumentStrategies.get(i);
final Optional<DataType> inferredDataType = argumentTypeStrategy.inferArgumentType(callContext, i, throwOnFailure);
if (!inferredDataType.isPresent()) {
return Optional.empty();
}
inferredDataTypes.add(inferredDataType.get());
}
return Optional.of(inferredDataTypes);
}
Aggregations