Search in sources :

Example 11 with LegacyTypeInformationType

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;
}
Also used : Tuple2(org.apache.flink.api.java.tuple.Tuple2) DecimalDataTypeInfo(org.apache.flink.table.runtime.typeutils.DecimalDataTypeInfo) DecimalType(org.apache.flink.table.types.logical.DecimalType) BigDecimalTypeInfo(org.apache.flink.table.runtime.typeutils.BigDecimalTypeInfo) LegacyTypeInformationType(org.apache.flink.table.types.logical.LegacyTypeInformationType) TypeInformation(org.apache.flink.api.common.typeinfo.TypeInformation)

Example 12 with LegacyTypeInformationType

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));
}
Also used : DataType(org.apache.flink.table.types.DataType) TypeConversions.fromLogicalToDataType(org.apache.flink.table.types.utils.TypeConversions.fromLogicalToDataType) LogicalType(org.apache.flink.table.types.logical.LogicalType) DecimalType(org.apache.flink.table.types.logical.DecimalType) LegacyTypeInformationType(org.apache.flink.table.types.logical.LegacyTypeInformationType)

Example 13 with LegacyTypeInformationType

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;
}
Also used : DataType(org.apache.flink.table.types.DataType) StrategyUtils.findDataType(org.apache.flink.table.types.inference.strategies.StrategyUtils.findDataType) LogicalType(org.apache.flink.table.types.logical.LogicalType) LogicalTypeRoot(org.apache.flink.table.types.logical.LogicalTypeRoot) LegacyTypeInformationType(org.apache.flink.table.types.logical.LegacyTypeInformationType)

Example 14 with LegacyTypeInformationType

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;
}
Also used : AtomicDataType(org.apache.flink.table.types.AtomicDataType) LogicalType(org.apache.flink.table.types.logical.LogicalType) DataType(org.apache.flink.table.types.DataType) AtomicDataType(org.apache.flink.table.types.AtomicDataType) LegacyTypeInformationType(org.apache.flink.table.types.logical.LegacyTypeInformationType)

Example 15 with LegacyTypeInformationType

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));
}
Also used : DataType(org.apache.flink.table.types.DataType) TypeConversions.fromLogicalToDataType(org.apache.flink.table.types.utils.TypeConversions.fromLogicalToDataType) LogicalType(org.apache.flink.table.types.logical.LogicalType) DecimalType(org.apache.flink.table.types.logical.DecimalType) LegacyTypeInformationType(org.apache.flink.table.types.logical.LegacyTypeInformationType)

Aggregations

LegacyTypeInformationType (org.apache.flink.table.types.logical.LegacyTypeInformationType)15 DataType (org.apache.flink.table.types.DataType)13 LogicalType (org.apache.flink.table.types.logical.LogicalType)13 DecimalType (org.apache.flink.table.types.logical.DecimalType)6 TypeConversions.fromLogicalToDataType (org.apache.flink.table.types.utils.TypeConversions.fromLogicalToDataType)6 TypeInformation (org.apache.flink.api.common.typeinfo.TypeInformation)3 BigDecimalTypeInfo (org.apache.flink.table.runtime.typeutils.BigDecimalTypeInfo)2 DecimalDataTypeInfo (org.apache.flink.table.runtime.typeutils.DecimalDataTypeInfo)2 BigDecimal (java.math.BigDecimal)1 Timestamp (java.sql.Timestamp)1 LocalDateTime (java.time.LocalDateTime)1 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)1 BasicArrayTypeInfo (org.apache.flink.api.common.typeinfo.BasicArrayTypeInfo)1 CompositeType (org.apache.flink.api.common.typeutils.CompositeType)1 Tuple (org.apache.flink.api.java.tuple.Tuple)1 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)1 PojoTypeInfo (org.apache.flink.api.java.typeutils.PojoTypeInfo)1 TupleTypeInfo (org.apache.flink.api.java.typeutils.TupleTypeInfo)1 TupleTypeInfoBase (org.apache.flink.api.java.typeutils.TupleTypeInfoBase)1 TableSchema (org.apache.flink.table.api.TableSchema)1