Class DataTypeUtils
- java.lang.Object
-
- org.apache.flink.table.types.utils.DataTypeUtils
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static DataTypealignStructuredTypes(DataTypeFactory factory, DataType dataType)Aligns theDataTypeand its nested conversion classes with the givenStructuredType.getImplementationClass().static DataTypeappendRowFields(DataType dataType, List<DataTypes.Field> fields)Appends the given list of fields to an existing row data type.static DataTypecreateProctimeDataType()Returns a PROCTIME data type.static ResolvedSchemaexpandCompositeTypeToSchema(DataType dataType)Expands a compositeDataTypeto a correspondingResolvedSchema.static List<DataType>flattenToDataTypes(DataType dataType)Returns the data types of the flat representation in the first level of the given data type.static List<String>flattenToNames(DataType dataType)Returns the names of the flat representation of the given data type.static List<String>flattenToNames(DataType dataType, List<String> existingNames)static DataTypefromResolvedSchemaPreservingTimeAttributes(ResolvedSchema resolvedSchema)ResolvedSchema.toPhysicalRowDataType()erases time attributes.static Optional<DataType>getField(DataType compositeType, int index)Retrieves a nested field from a composite type at given position.static Optional<DataType>getField(DataType compositeType, String name)Retrieves a nested field from a composite type with given name.static booleanisDefaultClass(DataType dataType)Checks whether this data type uses theLogicalType.getDefaultConversion()defined by the logical type.static booleanisDefaultClassNested(DataType dataType)Checks whether this data type and its children use theLogicalType.getDefaultConversion()defined by the logical type.static booleanisInternal(DataType dataType)Checks whether a given data type is an internal data structure.static booleanisInternal(DataType dataType, boolean autobox)Checks whether a given data type is an internal data structure.static DataTyperemoveTimeAttribute(DataType dataType)Removes time attributes from theDataType.static DataTypereplaceLogicalType(DataType dataType, LogicalType replacement)Replaces theLogicalTypeof aDataType, i.e., it keeps the bridging class.static DataTypetoInternalDataType(DataType dataType)static DataTypetoInternalDataType(LogicalType logicalType)Creates aDataTypefrom the givenLogicalTypewith internal data structures.static DataTypetransform(DataTypeFactory factory, DataType typeToTransform, TypeTransformation... transformations)Transforms the given data type to a different data type using the given transformations.static DataTypetransform(DataType typeToTransform, TypeTransformation... transformations)Transforms the given data type to a different data type using the given transformations.static voidvalidateInputDataType(DataType dataType)TheDataTypeclass can only partially verify the conversion class.static voidvalidateOutputDataType(DataType dataType)TheDataTypeclass can only partially verify the conversion class.
-
-
-
Method Detail
-
removeTimeAttribute
public static DataType removeTimeAttribute(DataType dataType)
Removes time attributes from theDataType. As everywhere else in the code base, this method does not support nested time attributes for now.
-
createProctimeDataType
public static DataType createProctimeDataType()
Returns a PROCTIME data type.
-
fromResolvedSchemaPreservingTimeAttributes
public static DataType fromResolvedSchemaPreservingTimeAttributes(ResolvedSchema resolvedSchema)
ResolvedSchema.toPhysicalRowDataType()erases time attributes. This method keeps them during conversion for very specific use cases mostly in Table API.
-
appendRowFields
public static DataType appendRowFields(DataType dataType, List<DataTypes.Field> fields)
Appends the given list of fields to an existing row data type.
-
expandCompositeTypeToSchema
public static ResolvedSchema expandCompositeTypeToSchema(DataType dataType)
Expands a compositeDataTypeto a correspondingResolvedSchema. Useful for flattening a column or mapping a physical to logical type of a table sourceThrows an exception for a non composite type. You can use
LogicalTypeChecks.isCompositeType(LogicalType)to check that.It does not expand an atomic type on purpose, because that operation depends on the context. E.g. in case of a
FLATTENfunction such operation is not allowed, whereas when mapping a physical type to logical the field name should be derived from the logical schema.- Parameters:
dataType- Data type to expand. Must be a composite type.- Returns:
- A corresponding table schema.
-
getField
public static Optional<DataType> getField(DataType compositeType, int index)
Retrieves a nested field from a composite type at given position.Throws an exception for a non composite type. You can use
LogicalTypeChecks.isCompositeType(LogicalType)to check that.- Parameters:
compositeType- Data type to expand. Must be a composite type.index- Index of the field to retrieve.- Returns:
- The field at the given position.
-
getField
public static Optional<DataType> getField(DataType compositeType, String name)
Retrieves a nested field from a composite type with given name.Throws an exception for a non composite type. You can use
LogicalTypeChecks.isCompositeType(LogicalType)to check that.- Parameters:
compositeType- Data type to expand. Must be a composite type.name- Name of the field to retrieve.- Returns:
- The field with the given name.
-
flattenToDataTypes
public static List<DataType> flattenToDataTypes(DataType dataType)
Returns the data types of the flat representation in the first level of the given data type.
-
flattenToNames
public static List<String> flattenToNames(DataType dataType)
Returns the names of the flat representation of the given data type. In case ofStructuredType, the list also includes the super type fields.
-
flattenToNames
public static List<String> flattenToNames(DataType dataType, List<String> existingNames)
- See Also:
flattenToNames(DataType)
-
replaceLogicalType
public static DataType replaceLogicalType(DataType dataType, LogicalType replacement)
Replaces theLogicalTypeof aDataType, i.e., it keeps the bridging class.
-
toInternalDataType
public static DataType toInternalDataType(LogicalType logicalType)
Creates aDataTypefrom the givenLogicalTypewith internal data structures.
-
isInternal
public static boolean isInternal(DataType dataType)
Checks whether a given data type is an internal data structure.
-
isInternal
public static boolean isInternal(DataType dataType, boolean autobox)
Checks whether a given data type is an internal data structure.
-
isDefaultClassNested
public static boolean isDefaultClassNested(DataType dataType)
Checks whether this data type and its children use theLogicalType.getDefaultConversion()defined by the logical type.
-
isDefaultClass
public static boolean isDefaultClass(DataType dataType)
Checks whether this data type uses theLogicalType.getDefaultConversion()defined by the logical type.
-
validateInputDataType
public static void validateInputDataType(DataType dataType)
TheDataTypeclass can only partially verify the conversion class. This method can perform the final check when we know if the data type should be used for input.
-
validateOutputDataType
public static void validateOutputDataType(DataType dataType)
TheDataTypeclass can only partially verify the conversion class. This method can perform the final check when we know if the data type should be used for output.
-
transform
public static DataType transform(DataType typeToTransform, TypeTransformation... transformations)
Transforms the given data type to a different data type using the given transformations.
-
transform
public static DataType transform(@Nullable DataTypeFactory factory, DataType typeToTransform, TypeTransformation... transformations)
Transforms the given data type to a different data type using the given transformations.The transformations will be called in the given order. In case of constructed or composite types, a transformation will be applied transitively to children first.
Both the
DataType.getLogicalType()andDataType.getConversionClass()can be transformed.- Parameters:
factory-DataTypeFactoryif availabletypeToTransform- data type to be transformed.transformations- the transformations to transform data type to another type.- Returns:
- the new data type
-
alignStructuredTypes
public static DataType alignStructuredTypes(DataTypeFactory factory, DataType dataType)
Aligns theDataTypeand its nested conversion classes with the givenStructuredType.getImplementationClass().By default, a data type is created from a
LogicalTypeand uses default conversion classes. But for conversion to the implementation class, the data type must reflect the correct expected classes (e.g.List<Integer>instead ofInteger[]) for all attributes.
-
-