Java Code Examples for org.apache.flink.table.types.logical.LogicalType#equals()
The following examples show how to use
org.apache.flink.table.types.logical.LogicalType#equals() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LogicalTypeGeneralization.java From flink with Apache License 2.0 | 6 votes |
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); }
Example 2
Source File: LogicalTypeMerging.java From flink with Apache License 2.0 | 6 votes |
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); }
Example 3
Source File: LogicalTypeGeneralization.java From flink with Apache License 2.0 | 5 votes |
private static @Nullable LogicalType findExactlySameType(List<LogicalType> normalizedTypes) { final LogicalType firstType = normalizedTypes.get(0); for (LogicalType type : normalizedTypes) { if (!type.equals(firstType)) { return null; } } return firstType; }
Example 4
Source File: LogicalTypeGeneralization.java From flink with Apache License 2.0 | 5 votes |
private static LogicalType createCommonExactNumericType(LogicalType resultType, LogicalType type) { // same EXACT_NUMERIC types if (type.equals(resultType)) { return resultType; } final LogicalTypeRoot resultTypeRoot = resultType.getTypeRoot(); final LogicalTypeRoot typeRoot = type.getTypeRoot(); // no DECIMAL types involved if (resultTypeRoot != DECIMAL && typeRoot != DECIMAL) { // type root contains order of precision if (getPrecision(type) > getPrecision(resultType)) { return type; } return resultType; } // determine DECIMAL with precision (p), scale (s) and number of whole digits (d): // d = max(p1 - s1, p2 - s2) // s <= max(s1, s2) // p = s + d final int p1 = getPrecision(resultType); final int p2 = getPrecision(type); final int s1 = getScale(resultType); final int s2 = getScale(type); final int maxPrecision = DecimalType.MAX_PRECISION; int d = Math.max(p1 - s1, p2 - s2); d = Math.min(d, maxPrecision); int s = Math.max(s1, s2); s = Math.min(s, maxPrecision - d); final int p = d + s; return new DecimalType(p, s); }
Example 5
Source File: AggregateOperationFactory.java From flink with Apache License 2.0 | 5 votes |
private ResolvedGroupWindow validateAndCreateSlideWindow( SlideWithSizeAndSlideOnTimeWithAlias window, String windowName, FieldReferenceExpression timeField) { ValueLiteralExpression windowSize = getAsValueLiteral(window.getSize(), "A sliding window expects a size value literal."); ValueLiteralExpression windowSlide = getAsValueLiteral(window.getSlide(), "A sliding window expects a slide value literal."); final LogicalType timeFieldType = timeField.getOutputDataType().getLogicalType(); final LogicalType windowSizeType = windowSize.getOutputDataType().getLogicalType(); final LogicalType windowSlideType = windowSlide.getOutputDataType().getLogicalType(); if (!hasRoot(windowSizeType, BIGINT) && !hasRoot(windowSizeType, INTERVAL_DAY_TIME)) { throw new ValidationException( "A sliding window expects a size literal of a day-time interval or BIGINT type."); } if (!windowSizeType.equals(windowSlideType)) { throw new ValidationException("A sliding window expects the same type of size and slide."); } validateWindowIntervalType(timeFieldType, windowSizeType); return ResolvedGroupWindow.slidingWindow( windowName, timeField, windowSize, windowSlide); }
Example 6
Source File: LogicalTypeMerging.java From flink with Apache License 2.0 | 5 votes |
private static @Nullable LogicalType findExactlySameType(List<LogicalType> normalizedTypes) { final LogicalType firstType = normalizedTypes.get(0); for (LogicalType type : normalizedTypes) { if (!type.equals(firstType)) { return null; } } return firstType; }
Example 7
Source File: LogicalTypeMerging.java From flink with Apache License 2.0 | 5 votes |
private static LogicalType createCommonExactNumericType(LogicalType resultType, LogicalType type) { // same EXACT_NUMERIC types if (type.equals(resultType)) { return resultType; } final LogicalTypeRoot resultTypeRoot = resultType.getTypeRoot(); final LogicalTypeRoot typeRoot = type.getTypeRoot(); // no DECIMAL types involved if (resultTypeRoot != DECIMAL && typeRoot != DECIMAL) { // type root contains order of precision if (getPrecision(type) > getPrecision(resultType)) { return type; } return resultType; } // determine DECIMAL with precision (p), scale (s) and number of whole digits (d): // d = max(p1 - s1, p2 - s2) // s <= max(s1, s2) // p = s + d final int p1 = getPrecision(resultType); final int p2 = getPrecision(type); final int s1 = getScale(resultType); final int s2 = getScale(type); final int maxPrecision = DecimalType.MAX_PRECISION; int d = Math.max(p1 - s1, p2 - s2); d = Math.min(d, maxPrecision); int s = Math.max(s1, s2); s = Math.min(s, maxPrecision - d); final int p = d + s; return new DecimalType(p, s); }
Example 8
Source File: AggregateOperationFactory.java From flink with Apache License 2.0 | 5 votes |
private ResolvedGroupWindow validateAndCreateSlideWindow( SlideWithSizeAndSlideOnTimeWithAlias window, String windowName, FieldReferenceExpression timeField) { ValueLiteralExpression windowSize = getAsValueLiteral(window.getSize(), "A sliding window expects a size value literal."); ValueLiteralExpression windowSlide = getAsValueLiteral(window.getSlide(), "A sliding window expects a slide value literal."); final LogicalType timeFieldType = timeField.getOutputDataType().getLogicalType(); final LogicalType windowSizeType = windowSize.getOutputDataType().getLogicalType(); final LogicalType windowSlideType = windowSlide.getOutputDataType().getLogicalType(); if (!hasRoot(windowSizeType, BIGINT) && !hasRoot(windowSizeType, INTERVAL_DAY_TIME)) { throw new ValidationException( "A sliding window expects a size literal of a day-time interval or BIGINT type."); } if (!windowSizeType.equals(windowSlideType)) { throw new ValidationException("A sliding window expects the same type of size and slide."); } validateWindowIntervalType(timeFieldType, windowSizeType); return ResolvedGroupWindow.slidingWindow( windowName, timeField, windowSize, windowSlide); }
Example 9
Source File: ComparableTypeStrategy.java From flink with Apache License 2.0 | 4 votes |
private boolean areRawTypesComparable(LogicalType firstType, LogicalType secondType) { return firstType.equals(secondType) && Comparable.class.isAssignableFrom(((RawType<?>) firstType).getOriginatingClass()); }
Example 10
Source File: ComparableTypeStrategy.java From flink with Apache License 2.0 | 4 votes |
private boolean areDistinctTypesComparable(LogicalType firstType, LogicalType secondType) { DistinctType firstDistinctType = (DistinctType) firstType; DistinctType secondDistinctType = (DistinctType) secondType; return firstType.equals(secondType) && areComparable(firstDistinctType.getSourceType(), secondDistinctType.getSourceType()); }
Example 11
Source File: ComparableTypeStrategy.java From flink with Apache License 2.0 | 4 votes |
private boolean areStructuredTypesComparable(LogicalType firstType, LogicalType secondType) { return firstType.equals(secondType) && hasRequiredComparision((StructuredType) firstType); }
Example 12
Source File: OrcSplitReaderUtil.java From flink with Apache License 2.0 | 4 votes |
/** * See {@code org.apache.flink.table.catalog.hive.util.HiveTypeUtil}. */ public static TypeDescription logicalTypeToOrcType(LogicalType type) { type = type.copy(true); switch (type.getTypeRoot()) { case CHAR: return TypeDescription.createChar().withMaxLength(((CharType) type).getLength()); case VARCHAR: int len = ((VarCharType) type).getLength(); if (len == VarCharType.MAX_LENGTH) { return TypeDescription.createString(); } else { return TypeDescription.createVarchar().withMaxLength(len); } case BOOLEAN: return TypeDescription.createBoolean(); case VARBINARY: if (type.equals(DataTypes.BYTES().getLogicalType())) { return TypeDescription.createBinary(); } else { throw new UnsupportedOperationException( "Not support other binary type: " + type); } case DECIMAL: DecimalType decimalType = (DecimalType) type; return TypeDescription.createDecimal() .withScale(decimalType.getScale()) .withPrecision(decimalType.getPrecision()); case TINYINT: return TypeDescription.createByte(); case SMALLINT: return TypeDescription.createShort(); case INTEGER: return TypeDescription.createInt(); case BIGINT: return TypeDescription.createLong(); case FLOAT: return TypeDescription.createFloat(); case DOUBLE: return TypeDescription.createDouble(); case DATE: return TypeDescription.createDate(); case TIMESTAMP_WITHOUT_TIME_ZONE: return TypeDescription.createTimestamp(); case ARRAY: ArrayType arrayType = (ArrayType) type; return TypeDescription.createList(logicalTypeToOrcType(arrayType.getElementType())); case MAP: MapType mapType = (MapType) type; return TypeDescription.createMap( logicalTypeToOrcType(mapType.getKeyType()), logicalTypeToOrcType(mapType.getValueType())); case ROW: RowType rowType = (RowType) type; TypeDescription struct = TypeDescription.createStruct(); for (int i = 0; i < rowType.getFieldCount(); i++) { struct.addField( rowType.getFieldNames().get(i), logicalTypeToOrcType(rowType.getChildren().get(i))); } return struct; default: throw new UnsupportedOperationException("Unsupported type: " + type); } }