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);
}
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;
}
Aggregations