Skip to content

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

Open
rahulsmahadev wants to merge 5 commits into
apache:mainfrom
rahulsmahadev:spark-4.2-column-id-validation
Open

rahulsmahadev wants to merge 5 commits 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
@szehon-ho

Copy link
Copy Markdown
Member

Could we update TestIncrementallyConstructedQueries.testIncrementalQueryWithExternalDropAndAddColumnSameNameSameType to expect INCOMPATIBLE_TABLE_CHANGE_AFTER_ANALYSIS.COLUMNS_MISMATCH? Spark 4.2 CI currently fails for two catalog configurations because salary correctly changes from field ID 2 to 3. Updating that test would also provide end-to-end coverage beyond the schema-conversion test.

Dropping and re-adding salary gives it a new field ID, which Spark 4.2 now
detects through the column IDs, so the stale DataFrame fails with
INCOMPATIBLE_TABLE_CHANGE_AFTER_ANALYSIS.COLUMNS_MISMATCH.
@rahulsmahadev

Copy link
Copy Markdown
Contributor Author

Updated testIncrementalQuery... to expect COLUMNS_MISMATCH ('salary field ID has changed from 2 to 3') in latest committ . It passes for both catalogs, and I also merged the latest main.

… tests

Spark columns and struct fields now carry Iceberg field IDs, so the column
added by ALTER TABLE is expected with its ID, and metadata table partition
types are compared without IDs because the expected types are parsed from
DDL.

This branch has not been deployed

No deployments
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.

2 participants