feat(connector): Add support for widening nested fields - #28454
feat(connector): Add support for widening nested fields#28454Shreya-ibm wants to merge 1 commit into
Conversation
Reviewer's GuideExtends ALTER COLUMN SET DATA TYPE from identifiers to qualified nested field paths, routes those updates through the metadata and connector APIs, and implements Iceberg struct-field widening with compatible reads of legacy data. Tests cover parsing, dispatch, cross-format schema evolution, old and new data, and narrowing rejection. Sequence diagram for nested field type wideningsequenceDiagram
participant User
participant Parser
participant SetColumnTypeTask
participant MetadataManager
participant IcebergMetadata
participant IcebergTable
User->>Parser: ALTER TABLE ... ALTER COLUMN struct_col.field SET DATA TYPE BIGINT
Parser->>SetColumnTypeTask: SetColumnType(qualifiedName)
SetColumnTypeTask->>MetadataManager: setFieldType(table, column, fieldPath, type)
MetadataManager->>IcebergMetadata: setFieldType(session, table, column, fieldPath, type)
IcebergMetadata->>IcebergTable: updateSchema().updateColumn(fieldName, BIGINT).commit()
IcebergTable-->>User: Schema updated
Flow diagram for top-level and nested type alteration dispatchflowchart TD
A[ALTER COLUMN qualifiedName SET DATA TYPE] --> B[Parse column path]
B --> C[Resolve root column handle]
C --> D{Path has nested fields?}
D -->|No| E[Metadata.setColumnType]
D -->|Yes| F[Metadata.setFieldType]
E --> G[ConnectorMetadata.setColumnType]
F --> H[ConnectorMetadata.setFieldType]
H --> I[Iceberg resolves struct field path]
I --> J[Iceberg commits widened field type]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
Codenotify: Notifying subscribers in CODENOTIFY files for diff c19af73...78163a7.
|
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergPageSourceProvider.java" line_range="399-397" />
<code_context>
.ifPresent(value -> defaultValues.put(column.getId(), value));
}
else {
- Type type = column.getType();
- if (!parquetField.get().isPrimitive()) {
- MessageType parquetMessageType = new MessageType("", parquetField.get());
- Schema icebergSchema = ParquetSchemaUtil.convert(parquetMessageType);
- type = toPrestoType(icebergSchema.columns().get(0).type(), typeManager);
- }
- internalFields.add(constructField(type, lookupColumnByName(messageColumnIO, AvroSchemaUtil.makeCompatibleName(parquetField.get().getName()))));
+ internalFields.add(constructField(column.getType(), lookupColumnByName(messageColumnIO, AvroSchemaUtil.makeCompatibleName(parquetField.get().getName()))));
}
}
</code_context>
<issue_to_address>
**issue (broader_impact):** After a nested Iceberg field is widened, this passes the current widened row type directly to the Parquet reader even when the file was written with the old nested physical type. Existing Parquet files therefore decode an INT32 nested value using the BIGINT field definition, causing old rows to fail to read or be decoded incorrectly.
**Triggers:** When reading Parquet data written before a nested INTEGER-to-BIGINT schema evolution.
**Suggested fix:** Retain the physical Parquet-to-Iceberg type conversion for non-primitive fields, or add an explicit schema-evolution coercion from the file's nested physical type to the current requested type.
</issue_to_address>| @@ -396,13 +394,7 @@ private ConnectorPageSourceWithRowPositions createParquetPageSource( | |||
| .ifPresent(value -> defaultValues.put(column.getId(), value)); | |||
| } | |||
There was a problem hiding this comment.
issue (broader_impact): After a nested Iceberg field is widened, this passes the current widened row type directly to the Parquet reader even when the file was written with the old nested physical type. Existing Parquet files therefore decode an INT32 nested value using the BIGINT field definition, causing old rows to fail to read or be decoded incorrectly.
Triggers: When reading Parquet data written before a nested INTEGER-to-BIGINT schema evolution.
Suggested fix: Retain the physical Parquet-to-Iceberg type conversion for non-primitive fields, or add an explicit schema-evolution coercion from the file's nested physical type to the current requested type.
Description
Adds support for widening nested fields in Iceberg struct columns using
ALTER TABLE ... ALTER COLUMN ... SET DATA TYPE.Example:
ALTER TABLE table_name ALTER COLUMN struct_col.field SET DATA TYPE BIGINT;Context
Fixes: #81606
Partially fixes: #75595
This branch adds support for nested field type widening while preserving the existing top-level type-widening behavior.
The implementation also ensures that existing data written before the schema evolution remains readable after widening.
Release Notes
Summary by Sourcery
Enable widening of nested Iceberg struct fields through ALTER TABLE while preserving existing top-level type evolution behavior.
New Features:
Bug Fixes:
Tests: