use of org.apache.flink.table.types.logical.LogicalType in project flink by apache.
the class DecimalPlusTypeStrategy method inferType.
@Override
public Optional<DataType> inferType(CallContext callContext) {
final List<DataType> argumentDataTypes = callContext.getArgumentDataTypes();
final LogicalType addend1 = argumentDataTypes.get(0).getLogicalType();
final LogicalType addend2 = argumentDataTypes.get(1).getLogicalType();
// a hack to make legacy types possible until we drop them
if (addend1 instanceof LegacyTypeInformationType) {
return Optional.of(argumentDataTypes.get(0));
}
if (addend2 instanceof LegacyTypeInformationType) {
return Optional.of(argumentDataTypes.get(1));
}
if (!isDecimalComputation(addend1, addend2)) {
return Optional.empty();
}
final DecimalType decimalType = LogicalTypeMerging.findAdditionDecimalType(getPrecision(addend1), getScale(addend1), getPrecision(addend2), getScale(addend2));
return Optional.of(fromLogicalToDataType(decimalType));
}
use of org.apache.flink.table.types.logical.LogicalType in project flink by apache.
the class MapInputTypeStrategy method inferInputTypes.
@Override
public Optional<List<DataType>> inferInputTypes(CallContext callContext, boolean throwOnFailure) {
List<DataType> argumentDataTypes = callContext.getArgumentDataTypes();
if (argumentDataTypes.size() == 0) {
return Optional.empty();
}
List<LogicalType> keyTypes = new ArrayList<>();
List<LogicalType> valueTypes = new ArrayList<>();
for (int i = 0; i < argumentDataTypes.size(); i++) {
LogicalType logicalType = argumentDataTypes.get(i).getLogicalType();
if (i % 2 == 0) {
keyTypes.add(logicalType);
} else {
valueTypes.add(logicalType);
}
}
Optional<LogicalType> commonKeyType = LogicalTypeMerging.findCommonType(keyTypes);
Optional<LogicalType> commonValueType = LogicalTypeMerging.findCommonType(valueTypes);
if (!commonKeyType.isPresent() || !commonValueType.isPresent()) {
return Optional.empty();
}
DataType keyType = TypeConversions.fromLogicalToDataType(commonKeyType.get());
DataType valueType = TypeConversions.fromLogicalToDataType(commonValueType.get());
return Optional.of(IntStream.range(0, argumentDataTypes.size()).mapToObj(idx -> {
if (idx % 2 == 0) {
return keyType;
} else {
return valueType;
}
}).collect(Collectors.toList()));
}
use of org.apache.flink.table.types.logical.LogicalType in project flink by apache.
the class CastInputTypeStrategy method inferInputTypes.
@Override
public Optional<List<DataType>> inferInputTypes(CallContext callContext, boolean throwOnFailure) {
// check for type literal
if (!callContext.isArgumentLiteral(1) || !callContext.getArgumentValue(1, DataType.class).isPresent()) {
return Optional.empty();
}
final List<DataType> argumentDataTypes = callContext.getArgumentDataTypes();
final LogicalType fromType = argumentDataTypes.get(0).getLogicalType();
final LogicalType toType = argumentDataTypes.get(1).getLogicalType();
// A hack to support legacy types. To be removed when we drop the legacy types.
if (fromType instanceof LegacyTypeInformationType) {
return Optional.of(argumentDataTypes);
}
if (!supportsExplicitCast(fromType, toType)) {
if (throwOnFailure) {
throw callContext.newValidationError("Unsupported cast from '%s' to '%s'.", fromType, toType);
}
return Optional.empty();
}
return Optional.of(argumentDataTypes);
}
use of org.apache.flink.table.types.logical.LogicalType in project flink by apache.
the class DataTypeExtractor method closestBridging.
/**
* Use closest class for data type if possible. Even though a hint might have provided some data
* type, in many cases, the conversion class can be enriched with the extraction type itself.
*/
private DataType closestBridging(DataType dataType, @Nullable Class<?> clazz) {
// no context class or conversion class is already more specific than context class
if (clazz == null || clazz.isAssignableFrom(dataType.getConversionClass())) {
return dataType;
}
final LogicalType logicalType = dataType.getLogicalType();
final boolean supportsConversion = logicalType.supportsInputConversion(clazz) || logicalType.supportsOutputConversion(clazz);
if (supportsConversion) {
return dataType.bridgedTo(clazz);
}
return dataType;
}
use of org.apache.flink.table.types.logical.LogicalType in project flink by apache.
the class AggDecimalPlusTypeStrategy method inferType.
@Override
public Optional<DataType> inferType(CallContext callContext) {
final List<DataType> argumentDataTypes = callContext.getArgumentDataTypes();
final LogicalType addend1 = argumentDataTypes.get(0).getLogicalType();
final LogicalType addend2 = argumentDataTypes.get(1).getLogicalType();
Preconditions.checkArgument(addend1.is(LogicalTypeRoot.DECIMAL), ERROR_MSG);
Preconditions.checkArgument(addend2.is(LogicalTypeRoot.DECIMAL), ERROR_MSG);
return Optional.of(fromLogicalToDataType(LogicalTypeMerging.findSumAggType(addend2)));
}
Aggregations