Package io.delta.kernel.internal.util
Class ColumnMapping
Object
io.delta.kernel.internal.util.ColumnMapping
Utilities related to the column mapping feature.
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic voidblockIfColumnMappingEnabled(Row transactionState) Utility method to block writing into a table with column mapping enabled.static StructFieldconvertToPhysicalColumn(StructField logicalField, StructType fullSchema, ColumnMapping.ColumnMappingMode columnMappingMode) Converts a logical column to a physical column based on the table's column mapping mode.static StructTypeconvertToPhysicalSchema(StructType prunedSchema, StructType fullSchema, ColumnMapping.ColumnMappingMode columnMappingMode) Helper method that converts the logical schema (requested by the connector) to physical schema of the data stored in data files based on the table's column mapping mode.static intgetColumnId(StructField field) Returns the column id for a givenStructFieldgetColumnMappingMode(Map<String, String> configuration) Returns the column mapping mode from the given configuration.getLogicalColumnNameAndDataType(StructType schema, Column physicalColumn) Returns the logical column and data type for a given physical column based on the schema.getPhysicalColumnNameAndDataType(StructType schema, Column logicalColumn) Returns the physical column and data type for a given logical column based on the schema.static StringgetPhysicalName(StructField field) Returns the physical name for a givenStructFieldstatic booleanisColumnMappingModeEnabled(ColumnMapping.ColumnMappingMode columnMappingMode) updateColumnMappingMetadataIfNeeded(Metadata metadata, boolean isNewTable) Updates the column mapping metadata if needed based on the column mapping mode and whether the icebergCompatV2 is enabled.static void
-
Field Details
-
COLUMN_MAPPING_MODE_KEY
- See Also:
-
COLUMN_MAPPING_PHYSICAL_NAME_KEY
- See Also:
-
COLUMN_MAPPING_ID_KEY
- See Also:
-
COLUMN_MAPPING_NESTED_IDS_KEY
- See Also:
-
PARQUET_FIELD_ID_KEY
- See Also:
-
PARQUET_FIELD_NESTED_IDS_METADATA_KEY
- See Also:
-
COLUMN_MAPPING_MAX_COLUMN_ID_KEY
- See Also:
-
-
Method Details
-
getColumnMappingMode
public static ColumnMapping.ColumnMappingMode getColumnMappingMode(Map<String, String> configuration) Returns the column mapping mode from the given configuration.- Parameters:
configuration- Configuration- Returns:
- Column mapping mode. One of ("none", "name", "id")
-
convertToPhysicalSchema
public static StructType convertToPhysicalSchema(StructType prunedSchema, StructType fullSchema, ColumnMapping.ColumnMappingMode columnMappingMode) Helper method that converts the logical schema (requested by the connector) to physical schema of the data stored in data files based on the table's column mapping mode. Field-id column metadata is preserved when cmMode = ID, all column metadata is otherwise removed.We require
fullSchemain addition to the pruned schema we want to convert since we need the complete field metadata as it is stored in the schema in the _delta_log. We cannot be sure (and do not enforce) that this metadata is preserved by the connector.- Parameters:
prunedSchema- the logical read schema requested by the connectorfullSchema- the full delta schema (with complete metadata) as read from the _delta_logcolumnMappingMode- Column mapping mode
-
convertToPhysicalColumn
public static StructField convertToPhysicalColumn(StructField logicalField, StructType fullSchema, ColumnMapping.ColumnMappingMode columnMappingMode) Converts a logical column to a physical column based on the table's column mapping mode. The field-id metadata is preserved when cmMode = ID, all column metadata is otherwise removed.We require
fullSchemain addition to the logical field we want to convert since we need the complete field metadata as it is stored in the schema in the _delta_log. We cannot be sure (and do not enforce) that this metadata is preserved by the connector.- Parameters:
logicalField- the logical read column requested by the connectorfullSchema- the full delta schema (with complete metadata) as read from the _delta_logcolumnMappingMode- Column mapping mode
-
getPhysicalName
Returns the physical name for a givenStructField -
getColumnId
Returns the column id for a givenStructField -
verifyColumnMappingChange
-
isColumnMappingModeEnabled
-
updateColumnMappingMetadataIfNeeded
public static Optional<Metadata> updateColumnMappingMetadataIfNeeded(Metadata metadata, boolean isNewTable) Updates the column mapping metadata if needed based on the column mapping mode and whether the icebergCompatV2 is enabled. If column mapping/iceberg compat info is already present in the metadata, this method does nothing and returns an empty Optional. Callers can avoid updating the metadata if the metadata has not changed.- Parameters:
metadata- Current metadata.isNewTable- Whether this is part of a commit that sets the mapping mode on a new table.- Returns:
- Optional of the updated metadata if it has changed, Optional.empty() otherwise.
-
getPhysicalColumnNameAndDataType
public static Tuple2<Column,DataType> getPhysicalColumnNameAndDataType(StructType schema, Column logicalColumn) Returns the physical column and data type for a given logical column based on the schema. -
getLogicalColumnNameAndDataType
public static Tuple2<Column,DataType> getLogicalColumnNameAndDataType(StructType schema, Column physicalColumn) Returns the logical column and data type for a given physical column based on the schema. -
blockIfColumnMappingEnabled
Utility method to block writing into a table with column mapping enabled. Currently Kernel only supports the metadata updates on tables with column mapping enabled. Data writes into such tables using the data transformation APIs provided by the Kernel are not supported yet.
-