Skip to content

Spark 4.2: Set Iceberg field IDs as Spark column IDs for DSv2 validation - #17958

Open
rahulsmahadev wants to merge 1 commit into
apache:mainfrom
rahulsmahadev:spark-4.2-column-id-validation
Open

Spark 4.2: Set Iceberg field IDs as Spark column IDs for DSv2 validation#17958
rahulsmahadev wants to merge 1 commit into
apache:mainfrom
rahulsmahadev:spark-4.2-column-id-validation

Conversation

@rahulsmahadev

Copy link
Copy Markdown
Contributor

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() from StructField.id(), and SparkTable.columns() goes through Spark's default CatalogV2Util.structTypeToV2Columns(schema(), true), which reads those IDs recursively for top-level and nested struct fields. Iceberg's TypeToSparkType did not set them, so Column.id() was always null.

This sets StructField.withId(Integer.toString(fieldId)) during Schema -> StructType conversion, using each field's Iceberg field ID. withId writes Spark's official field-ID metadata key and preserves existing StructField metadata; 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 in TestSparkSchemaUtil.

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.
@github-actions github-actions Bot added the spark label Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant