Java Code Examples for org.apache.flink.table.types.DataType#getConversionClass()
The following examples show how to use
org.apache.flink.table.types.DataType#getConversionClass() .
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: DataFormatConverters.java From flink with Apache License 2.0 | 5 votes |
public ObjectArrayConverter(DataType elementType) { this.componentClass = (Class) elementType.getConversionClass(); this.elementType = LogicalTypeDataTypeConverter.fromDataTypeToLogicalType(elementType); this.elementConverter = DataFormatConverters.getConverterForDataType(elementType); this.elementSize = BinaryArray.calculateFixLengthPartSize(this.elementType); this.eleSer = InternalSerializers.create(this.elementType, new ExecutionConfig()); this.isEleIndentity = elementConverter instanceof IdentityConverter; }
Example 2
Source File: DataFormatConverters.java From flink with Apache License 2.0 | 5 votes |
public MapConverter(DataType keyTypeInfo, DataType valueTypeInfo) { this.keyType = LogicalTypeDataTypeConverter.fromDataTypeToLogicalType(keyTypeInfo); this.valueType = LogicalTypeDataTypeConverter.fromDataTypeToLogicalType(valueTypeInfo); this.keyConverter = DataFormatConverters.getConverterForDataType(keyTypeInfo); this.valueConverter = DataFormatConverters.getConverterForDataType(valueTypeInfo); this.keyElementSize = BinaryArray.calculateFixLengthPartSize(keyType); this.valueElementSize = BinaryArray.calculateFixLengthPartSize(valueType); this.keyComponentClass = keyTypeInfo.getConversionClass(); this.valueComponentClass = valueTypeInfo.getConversionClass(); this.isKeyValueIndentity = keyConverter instanceof IdentityConverter && valueConverter instanceof IdentityConverter; this.keySer = InternalSerializers.create(this.keyType, new ExecutionConfig()); this.valueSer = InternalSerializers.create(this.valueType, new ExecutionConfig()); }
Example 3
Source File: DataFormatConverters.java From flink with Apache License 2.0 | 5 votes |
public ObjectArrayConverter(DataType elementType) { this.componentClass = (Class) elementType.getConversionClass(); this.elementType = LogicalTypeDataTypeConverter.fromDataTypeToLogicalType(elementType); this.elementConverter = DataFormatConverters.getConverterForDataType(elementType); this.elementSize = BinaryArrayData.calculateFixLengthPartSize(this.elementType); this.eleSer = InternalSerializers.create(this.elementType, new ExecutionConfig()); this.isEleIndentity = elementConverter instanceof IdentityConverter; }
Example 4
Source File: DataFormatConverters.java From flink with Apache License 2.0 | 5 votes |
public MapConverter(DataType keyTypeInfo, DataType valueTypeInfo) { this.keyType = LogicalTypeDataTypeConverter.fromDataTypeToLogicalType(keyTypeInfo); this.valueType = LogicalTypeDataTypeConverter.fromDataTypeToLogicalType(valueTypeInfo); this.keyConverter = DataFormatConverters.getConverterForDataType(keyTypeInfo); this.valueConverter = DataFormatConverters.getConverterForDataType(valueTypeInfo); this.keyElementSize = BinaryArrayData.calculateFixLengthPartSize(keyType); this.valueElementSize = BinaryArrayData.calculateFixLengthPartSize(valueType); this.keyComponentClass = keyTypeInfo.getConversionClass(); this.valueComponentClass = valueTypeInfo.getConversionClass(); this.isKeyValueIndentity = keyConverter instanceof IdentityConverter && valueConverter instanceof IdentityConverter; this.keySer = InternalSerializers.create(this.keyType, new ExecutionConfig()); this.valueSer = InternalSerializers.create(this.valueType, new ExecutionConfig()); }
Example 5
Source File: ComparableInputTypeStrategyTests.java From flink with Apache License 2.0 | 5 votes |
private static DataType distinctType(String typeName, DataType sourceType) { return new AtomicDataType( DistinctType.newBuilder( ObjectIdentifier.of("cat", "db", typeName), sourceType.getLogicalType() ).build(), sourceType.getConversionClass()); }
Example 6
Source File: ArrayFieldReader.java From flink with Apache License 2.0 | 5 votes |
private Class<?> getElementClass(LogicalType elementType) { DataType dataType = TypeConversions.fromLogicalToDataType(elementType); if (elementType instanceof TimestampType) { // the default conversion class is java.time.LocalDateTime dataType = dataType.bridgedTo(Timestamp.class); } else if (elementType instanceof DateType) { // the default conversion class is java.time.LocalDate dataType = dataType.bridgedTo(Date.class); } else if (elementType instanceof TimeType) { // the default conversion class is java.time.LocalTime dataType = dataType.bridgedTo(Time.class); } return dataType.getConversionClass(); }
Example 7
Source File: TypeInfoDataTypeConverter.java From flink with Apache License 2.0 | 4 votes |
public static TypeInformation<?> fromDataTypeToTypeInfo(DataType dataType) { Class<?> clazz = dataType.getConversionClass(); if (clazz.isPrimitive()) { final TypeInformation<?> foundTypeInfo = primitiveDataTypeTypeInfoMap.get(clazz.getName()); if (foundTypeInfo != null) { return foundTypeInfo; } } LogicalType logicalType = fromDataTypeToLogicalType(dataType); switch (logicalType.getTypeRoot()) { case DECIMAL: DecimalType decimalType = (DecimalType) logicalType; return clazz == Decimal.class ? new DecimalTypeInfo(decimalType.getPrecision(), decimalType.getScale()) : new BigDecimalTypeInfo(decimalType.getPrecision(), decimalType.getScale()); case CHAR: case VARCHAR: // ignore precision return clazz == BinaryString.class ? BinaryStringTypeInfo.INSTANCE : BasicTypeInfo.STRING_TYPE_INFO; case BINARY: case VARBINARY: // ignore precision return PrimitiveArrayTypeInfo.BYTE_PRIMITIVE_ARRAY_TYPE_INFO; case INTERVAL_YEAR_MONTH: return TimeIntervalTypeInfo.INTERVAL_MONTHS; case INTERVAL_DAY_TIME: return TimeIntervalTypeInfo.INTERVAL_MILLIS; case ARRAY: if (dataType instanceof CollectionDataType && !isPrimitive(((CollectionDataType) dataType).getElementDataType().getLogicalType())) { return ObjectArrayTypeInfo.getInfoFor( fromDataTypeToTypeInfo(((CollectionDataType) dataType).getElementDataType())); } else { return TypeConversions.fromDataTypeToLegacyInfo(dataType); } case MAP: KeyValueDataType mapType = (KeyValueDataType) dataType; return new MapTypeInfo( fromDataTypeToTypeInfo(mapType.getKeyDataType()), fromDataTypeToTypeInfo(mapType.getValueDataType())); case MULTISET: return MultisetTypeInfo.getInfoFor( fromDataTypeToTypeInfo(((CollectionDataType) dataType).getElementDataType())); case ROW: if (BaseRow.class.isAssignableFrom(dataType.getConversionClass())) { return BaseRowTypeInfo.of((RowType) fromDataTypeToLogicalType(dataType)); } else if (Row.class == dataType.getConversionClass()) { FieldsDataType rowType = (FieldsDataType) dataType; RowType logicalRowType = (RowType) logicalType; return new RowTypeInfo( logicalRowType.getFieldNames().stream() .map(name -> rowType.getFieldDataTypes().get(name)) .map(TypeInfoDataTypeConverter::fromDataTypeToTypeInfo) .toArray(TypeInformation[]::new), logicalRowType.getFieldNames().toArray(new String[0])); } else { return TypeConversions.fromDataTypeToLegacyInfo(dataType); } default: return TypeConversions.fromDataTypeToLegacyInfo(dataType); } }
Example 8
Source File: LegacyTypeInfoDataTypeConverter.java From flink with Apache License 2.0 | 4 votes |
private static boolean canConvertToTimestampTypeInfoLenient(DataType dataType) { LogicalType logicalType = dataType.getLogicalType(); return hasRoot(logicalType, LogicalTypeRoot.TIMESTAMP_WITHOUT_TIME_ZONE) && dataType.getConversionClass() != LocalDateTime.class && LogicalTypeChecks.getPrecision(logicalType) <= 3; }
Example 9
Source File: LegacyTypeInfoDataTypeConverter.java From flink with Apache License 2.0 | 4 votes |
private static boolean canConvertToMultisetTypeInfo(DataType dataType) { return hasRoot(dataType.getLogicalType(), LogicalTypeRoot.MULTISET) && dataType.getConversionClass() == Map.class; }
Example 10
Source File: LegacyTypeInfoDataTypeConverter.java From flink with Apache License 2.0 | 4 votes |
private static boolean canConvertToMapTypeInfo(DataType dataType) { return hasRoot(dataType.getLogicalType(), LogicalTypeRoot.MAP) && dataType.getConversionClass() == Map.class; }
Example 11
Source File: TypeInfoDataTypeConverter.java From flink with Apache License 2.0 | 4 votes |
public static TypeInformation<?> fromDataTypeToTypeInfo(DataType dataType) { Class<?> clazz = dataType.getConversionClass(); if (clazz.isPrimitive()) { final TypeInformation<?> foundTypeInfo = primitiveDataTypeTypeInfoMap.get(clazz.getName()); if (foundTypeInfo != null) { return foundTypeInfo; } } LogicalType logicalType = fromDataTypeToLogicalType(dataType); switch (logicalType.getTypeRoot()) { case TIMESTAMP_WITHOUT_TIME_ZONE: TimestampType timestampType = (TimestampType) logicalType; int precision = timestampType.getPrecision(); if (timestampType.getKind() == TimestampKind.REGULAR) { return clazz == TimestampData.class ? new TimestampDataTypeInfo(precision) : (clazz == LocalDateTime.class ? ((3 == precision) ? Types.LOCAL_DATE_TIME : new LegacyLocalDateTimeTypeInfo(precision)) : ((3 == precision) ? Types.SQL_TIMESTAMP : new LegacyTimestampTypeInfo(precision))); } else { return TypeConversions.fromDataTypeToLegacyInfo(dataType); } case TIMESTAMP_WITH_LOCAL_TIME_ZONE: LocalZonedTimestampType lzTs = (LocalZonedTimestampType) logicalType; int precisionLzTs = lzTs.getPrecision(); return clazz == TimestampData.class ? new TimestampDataTypeInfo(precisionLzTs) : (clazz == Instant.class ? ((3 == precisionLzTs) ? Types.INSTANT : new LegacyInstantTypeInfo(precisionLzTs)) : TypeConversions.fromDataTypeToLegacyInfo(dataType)); case DECIMAL: DecimalType decimalType = (DecimalType) logicalType; return clazz == DecimalData.class ? new DecimalDataTypeInfo(decimalType.getPrecision(), decimalType.getScale()) : new BigDecimalTypeInfo(decimalType.getPrecision(), decimalType.getScale()); case CHAR: case VARCHAR: // ignore precision return clazz == StringData.class ? StringDataTypeInfo.INSTANCE : BasicTypeInfo.STRING_TYPE_INFO; case BINARY: case VARBINARY: // ignore precision return PrimitiveArrayTypeInfo.BYTE_PRIMITIVE_ARRAY_TYPE_INFO; case INTERVAL_YEAR_MONTH: return TimeIntervalTypeInfo.INTERVAL_MONTHS; case INTERVAL_DAY_TIME: return TimeIntervalTypeInfo.INTERVAL_MILLIS; case ARRAY: if (dataType instanceof CollectionDataType && !isPrimitive(((CollectionDataType) dataType).getElementDataType().getLogicalType())) { return ObjectArrayTypeInfo.getInfoFor( fromDataTypeToTypeInfo(((CollectionDataType) dataType).getElementDataType())); } else { return TypeConversions.fromDataTypeToLegacyInfo(dataType); } case MAP: KeyValueDataType mapType = (KeyValueDataType) dataType; return new MapTypeInfo( fromDataTypeToTypeInfo(mapType.getKeyDataType()), fromDataTypeToTypeInfo(mapType.getValueDataType())); case MULTISET: return MultisetTypeInfo.getInfoFor( fromDataTypeToTypeInfo(((CollectionDataType) dataType).getElementDataType())); case ROW: if (RowData.class.isAssignableFrom(dataType.getConversionClass())) { return RowDataTypeInfo.of((RowType) fromDataTypeToLogicalType(dataType)); } else if (Row.class == dataType.getConversionClass()) { RowType logicalRowType = (RowType) logicalType; return new RowTypeInfo( dataType.getChildren() .stream() .map(TypeInfoDataTypeConverter::fromDataTypeToTypeInfo) .toArray(TypeInformation[]::new), logicalRowType.getFieldNames().toArray(new String[0])); } else { return TypeConversions.fromDataTypeToLegacyInfo(dataType); } case RAW: if (logicalType instanceof RawType) { final RawType<?> rawType = (RawType<?>) logicalType; return createWrapperTypeInfo(rawType); } return TypeConversions.fromDataTypeToLegacyInfo(dataType); default: return TypeConversions.fromDataTypeToLegacyInfo(dataType); } }
Example 12
Source File: LegacyTypeInfoDataTypeConverter.java From flink with Apache License 2.0 | 4 votes |
public static TypeInformation<?> toLegacyTypeInfo(DataType dataType) { // time indicators first as their hashCode/equals is shared with those of regular timestamps if (canConvertToTimeAttributeTypeInfo(dataType)) { return convertToTimeAttributeTypeInfo((TimestampType) dataType.getLogicalType()); } // check in the map but relax the nullability constraint as every not null data type can be // stored in the corresponding nullable type information final TypeInformation<?> foundTypeInfo = dataTypeTypeInfoMap.get(dataType.nullable()); if (foundTypeInfo != null) { return foundTypeInfo; } // we are relaxing the constraint for DECIMAL, CHAR, VARCHAR, TIMESTAMP_WITHOUT_TIME_ZONE to // support value literals in legacy planner LogicalType logicalType = dataType.getLogicalType(); if (hasRoot(logicalType, LogicalTypeRoot.DECIMAL)) { return Types.BIG_DEC; } else if (hasRoot(logicalType, LogicalTypeRoot.CHAR)) { return Types.STRING; } else if (hasRoot(logicalType, LogicalTypeRoot.VARCHAR)) { return Types.STRING; } // relax the precision constraint as Timestamp can store the highest precision else if (hasRoot(logicalType, LogicalTypeRoot.TIMESTAMP_WITHOUT_TIME_ZONE) && dataType.getConversionClass() == Timestamp.class) { return Types.SQL_TIMESTAMP; } // relax the precision constraint as LocalDateTime can store the highest precision else if (hasRoot(logicalType, LogicalTypeRoot.TIMESTAMP_WITHOUT_TIME_ZONE) && dataType.getConversionClass() == LocalDateTime.class) { return Types.LOCAL_DATE_TIME; } // relax the precision constraint as LocalTime can store the highest precision else if (hasRoot(logicalType, LogicalTypeRoot.TIME_WITHOUT_TIME_ZONE) && dataType.getConversionClass() == LocalTime.class) { return Types.LOCAL_TIME; } else if (canConvertToLegacyTypeInfo(dataType)) { return convertToLegacyTypeInfo(dataType); } else if (canConvertToRowTypeInfo(dataType)) { return convertToRowTypeInfo((FieldsDataType) dataType); } // this could also match for basic array type info but this is covered by legacy type info else if (canConvertToObjectArrayTypeInfo(dataType)) { return convertToObjectArrayTypeInfo((CollectionDataType) dataType); } else if (canConvertToMultisetTypeInfo(dataType)) { return convertToMultisetTypeInfo((CollectionDataType) dataType); } else if (canConvertToMapTypeInfo(dataType)) { return convertToMapTypeInfo((KeyValueDataType) dataType); } // makes the raw type accessible in the legacy planner else if (canConvertToRawTypeInfo(dataType)) { return convertToRawTypeInfo(dataType); } throw new TableException( String.format( "Unsupported conversion from data type '%s' (conversion class: %s) to type information. Only data types " + "that originated from type information fully support a reverse conversion.", dataType, dataType.getConversionClass().getName())); }
Example 13
Source File: LegacyTypeInfoDataTypeConverter.java From flink with Apache License 2.0 | 4 votes |
private static boolean canConvertToMultisetTypeInfo(DataType dataType) { return hasRoot(dataType.getLogicalType(), LogicalTypeRoot.MULTISET) && dataType.getConversionClass() == Map.class; }
Example 14
Source File: LegacyTypeInfoDataTypeConverter.java From flink with Apache License 2.0 | 4 votes |
private static boolean canConvertToMapTypeInfo(DataType dataType) { return hasRoot(dataType.getLogicalType(), LogicalTypeRoot.MAP) && dataType.getConversionClass() == Map.class; }