Search in sources :

Example 11 with LogicalTypeRoot

use of org.apache.flink.table.types.logical.LogicalTypeRoot in project flink by apache.

the class LogicalTypeMerging method createCommonTimestampType.

private static LogicalType createCommonTimestampType(LogicalType resultType, LogicalType type) {
    // same types
    if (type.equals(resultType)) {
        return resultType;
    }
    final LogicalTypeRoot resultTypeRoot = resultType.getTypeRoot();
    final LogicalTypeRoot typeRoot = type.getTypeRoot();
    final int precision = combinePrecision(resultType, type);
    // same type roots
    if (typeRoot == resultTypeRoot) {
        return createTimestampType(resultTypeRoot, precision);
    }
    // generalize to zoned type
    if (typeRoot == TIMESTAMP_WITH_TIME_ZONE || resultTypeRoot == TIMESTAMP_WITH_TIME_ZONE) {
        return createTimestampType(TIMESTAMP_WITH_TIME_ZONE, precision);
    } else if (typeRoot == TIMESTAMP_WITH_LOCAL_TIME_ZONE || resultTypeRoot == TIMESTAMP_WITH_LOCAL_TIME_ZONE) {
        return createTimestampType(TIMESTAMP_WITH_LOCAL_TIME_ZONE, precision);
    }
    return createTimestampType(TIMESTAMP_WITHOUT_TIME_ZONE, precision);
}
Also used : LogicalTypeRoot(org.apache.flink.table.types.logical.LogicalTypeRoot)

Example 12 with LogicalTypeRoot

use of org.apache.flink.table.types.logical.LogicalTypeRoot 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)

Aggregations

LogicalTypeRoot (org.apache.flink.table.types.logical.LogicalTypeRoot)12 LogicalType (org.apache.flink.table.types.logical.LogicalType)8 ArrayList (java.util.ArrayList)3 Nullable (javax.annotation.Nullable)3 DateType (org.apache.flink.table.types.logical.DateType)2 DayTimeIntervalType (org.apache.flink.table.types.logical.DayTimeIntervalType)2 DecimalType (org.apache.flink.table.types.logical.DecimalType)2 DoubleType (org.apache.flink.table.types.logical.DoubleType)2 LegacyTypeInformationType (org.apache.flink.table.types.logical.LegacyTypeInformationType)2 AbstractList (java.util.AbstractList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1 Internal (org.apache.flink.annotation.Internal)1 CatalogException (org.apache.flink.table.catalog.exceptions.CatalogException)1