use of org.apache.flink.table.types.logical.LogicalType 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.logical.LogicalType 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.logical.LogicalType in project flink by apache.
the class RootArgumentTypeStrategy 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();
if (Objects.equals(expectedNullability, Boolean.FALSE) && actualType.isNullable()) {
if (throwOnFailure) {
throw callContext.newValidationError("Unsupported argument type. Expected nullable type of root '%s' but actual type was '%s'.", expectedRoot, actualType);
}
return Optional.empty();
}
return findDataType(callContext, throwOnFailure, actualDataType, expectedRoot, expectedNullability);
}
use of org.apache.flink.table.types.logical.LogicalType in project flink by apache.
the class StringConcatTypeStrategy method inferType.
@Override
public Optional<DataType> inferType(CallContext callContext) {
final List<DataType> argumentDataTypes = callContext.getArgumentDataTypes();
final LogicalType type1 = argumentDataTypes.get(0).getLogicalType();
final LogicalType type2 = argumentDataTypes.get(1).getLogicalType();
int length = getLength(type1) + getLength(type2);
// handle overflow
if (length < 0) {
length = CharType.MAX_LENGTH;
}
final LogicalType minimumType;
if (type1.is(LogicalTypeFamily.CHARACTER_STRING) || type2.is(LogicalTypeFamily.CHARACTER_STRING)) {
minimumType = new CharType(false, length);
} else if (type1.is(LogicalTypeFamily.BINARY_STRING) || type2.is(LogicalTypeFamily.BINARY_STRING)) {
minimumType = new BinaryType(false, length);
} else {
return Optional.empty();
}
// deal with nullability handling and varying semantics
return findCommonType(Arrays.asList(type1, type2, minimumType)).map(TypeConversions::fromLogicalToDataType);
}
use of org.apache.flink.table.types.logical.LogicalType in project flink by apache.
the class DataTypeConversionClassTransformation method transform.
@Override
public DataType transform(DataType dataType) {
LogicalType logicalType = dataType.getLogicalType();
Class<?> conversionClass = conversions.get(logicalType.getTypeRoot());
if (conversionClass != null) {
return dataType.bridgedTo(conversionClass);
} else {
return dataType;
}
}
Aggregations