Spark 4.2: Set Iceberg field IDs as Spark column IDs for DSv2 validation - #17958
Open
rahulsmahadev wants to merge 1 commit into
Open
Spark 4.2: Set Iceberg field IDs as Spark column IDs for DSv2 validation#17958rahulsmahadev wants to merge 1 commit into
rahulsmahadev wants to merge 1 commit into
Conversation
Set StructField.withId with each Iceberg field ID during Schema to StructType conversion, so SparkTable.columns() exposes stable Column.id() for top-level and nested struct fields and Spark 4.2's nested-field column-ID validation (SPARK-57544) works with Iceberg tables. Adds a TestSparkSchemaUtil test.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Exposes stable Iceberg field IDs to Spark as DSv2 column IDs, so Spark 4.2's column-ID validation for nested fields (SPARK-57544) works with Iceberg tables.
Spark 4.2 populates
Column.id()fromStructField.id(), andSparkTable.columns()goes through Spark's defaultCatalogV2Util.structTypeToV2Columns(schema(), true), which reads those IDs recursively for top-level and nested struct fields. Iceberg'sTypeToSparkTypedid not set them, soColumn.id()was always null.This sets
StructField.withId(Integer.toString(fieldId))duringSchema -> StructTypeconversion, using each field's Iceberg field ID.withIdwrites Spark's official field-ID metadata key and preserves existingStructFieldmetadata; it does not conflict with Iceberg's separate metadata-column marker. Named struct fields, including those nested inside arrays and maps, receive IDs through the existing recursive visitor; collection element/key/value pseudo-fields are not named Spark fields and are left unchanged. A test is added inTestSparkSchemaUtil.