use of org.apache.flink.table.types.logical.LegacyTypeInformationType in project flink by apache.
the class DataFormatConverters method getPrecision.
private static Tuple2<Integer, Integer> getPrecision(LogicalType logicalType) {
Tuple2<Integer, Integer> ps = new Tuple2<>();
if (logicalType instanceof DecimalType) {
DecimalType decimalType = (DecimalType) logicalType;
ps.f0 = decimalType.getPrecision();
ps.f1 = decimalType.getScale();
} else {
TypeInformation typeInfo = ((LegacyTypeInformationType) logicalType).getTypeInformation();
if (typeInfo instanceof BigDecimalTypeInfo) {
BigDecimalTypeInfo decimalType = (BigDecimalTypeInfo) typeInfo;
ps.f0 = decimalType.precision();
ps.f1 = decimalType.scale();
} else if (typeInfo instanceof DecimalDataTypeInfo) {
DecimalDataTypeInfo decimalType = (DecimalDataTypeInfo) typeInfo;
ps.f0 = decimalType.precision();
ps.f1 = decimalType.scale();
} else {
ps.f0 = DecimalDataUtils.DECIMAL_SYSTEM_DEFAULT.getPrecision();
ps.f1 = DecimalDataUtils.DECIMAL_SYSTEM_DEFAULT.getScale();
}
}
return ps;
}
use of org.apache.flink.table.types.logical.LegacyTypeInformationType in project flink by apache.
the class DecimalModTypeStrategy method inferType.
@Override
public Optional<DataType> inferType(CallContext callContext) {
final List<DataType> argumentDataTypes = callContext.getArgumentDataTypes();
final LogicalType dividend = argumentDataTypes.get(0).getLogicalType();
final LogicalType divisor = argumentDataTypes.get(1).getLogicalType();
// a hack to make legacy types possible until we drop them
if (dividend instanceof LegacyTypeInformationType) {
return Optional.of(argumentDataTypes.get(0));
}
if (divisor instanceof LegacyTypeInformationType) {
return Optional.of(argumentDataTypes.get(1));
}
if (!isDecimalComputation(dividend, divisor)) {
return Optional.empty();
}
final int dividendScale = getScale(dividend);
final int divisorScale = getScale(divisor);
if (dividendScale == 0 && divisorScale == 0) {
return Optional.of(argumentDataTypes.get(1));
}
final DecimalType decimalType = LogicalTypeMerging.findModuloDecimalType(getPrecision(dividend), dividendScale, getPrecision(divisor), divisorScale);
return Optional.of(fromLogicalToDataType(decimalType));
}
use of org.apache.flink.table.types.logical.LegacyTypeInformationType in project flink by apache.
the class FamilyArgumentTypeStrategy 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();
// a hack to make legacy types possible until we drop them
if (actualType instanceof LegacyTypeInformationType) {
return Optional.of(actualDataType);
}
if (Objects.equals(expectedNullability, Boolean.FALSE) && actualType.isNullable()) {
if (throwOnFailure) {
throw callContext.newValidationError("Unsupported argument type. Expected nullable type of family '%s' but actual type was '%s'.", expectedFamily, actualType);
}
return Optional.empty();
}
// type is part of the family
if (actualType.getTypeRoot().getFamilies().contains(expectedFamily)) {
return Optional.of(actualDataType);
}
// find a type for the family
final LogicalTypeRoot expectedRoot = familyToRoot.get(expectedFamily);
final Optional<DataType> inferredDataType;
if (expectedRoot == null) {
inferredDataType = Optional.empty();
} else {
inferredDataType = findDataType(callContext, false, actualDataType, expectedRoot, expectedNullability);
}
if (!inferredDataType.isPresent() && throwOnFailure) {
throw callContext.newValidationError("Unsupported argument type. Expected type of family '%s' but actual type was '%s'.", expectedFamily, actualType);
}
return inferredDataType;
}
use of org.apache.flink.table.types.logical.LegacyTypeInformationType in project flink by apache.
the class LegacyRawTypeTransformation method transform.
@Override
public DataType transform(DataType typeToTransform) {
LogicalType logicalType = typeToTransform.getLogicalType();
if (logicalType instanceof LegacyTypeInformationType && logicalType.getTypeRoot() == LogicalTypeRoot.RAW) {
TypeInformation<?> typeInfo = ((LegacyTypeInformationType<?>) logicalType).getTypeInformation();
DataType rawDataType = new AtomicDataType(new TypeInformationRawType<>(typeInfo));
return logicalType.isNullable() ? rawDataType : rawDataType.notNull();
}
return typeToTransform;
}
use of org.apache.flink.table.types.logical.LegacyTypeInformationType in project flink by apache.
the class DecimalTimesTypeStrategy method inferType.
@Override
public Optional<DataType> inferType(CallContext callContext) {
final List<DataType> argumentDataTypes = callContext.getArgumentDataTypes();
final LogicalType factor1 = argumentDataTypes.get(0).getLogicalType();
final LogicalType factor2 = argumentDataTypes.get(1).getLogicalType();
// a hack to make legacy types possible until we drop them
if (factor1 instanceof LegacyTypeInformationType) {
return Optional.of(argumentDataTypes.get(0));
}
if (factor2 instanceof LegacyTypeInformationType) {
return Optional.of(argumentDataTypes.get(1));
}
if (!isDecimalComputation(factor1, factor2)) {
return Optional.empty();
}
final DecimalType decimalType = LogicalTypeMerging.findMultiplicationDecimalType(getPrecision(factor1), getScale(factor1), getPrecision(factor2), getScale(factor2));
return Optional.of(fromLogicalToDataType(decimalType));
}
Aggregations