Repository navigation
Description
Search before asking
- I had searched in the issues and found no similar issues.
Please describe the bug 🐞
The Iceberg schema sync fails when the record key of an existing Iceberg target changes from required to nullable. Iceberg rejects the change with:
java.lang.IllegalArgumentException: Cannot add field id as an identifier field: not a required field
This was found with the Iceberg pluggable table format (xtable-iceberg-pluggable-tf) and the released 0.5.0 jars, on Spark 3.5 with Hudi 1.2.1, both locally and on S3. A Spark SQL UPDATE fails on a table that a Scala DataFrame created with a primitive (NOT NULL) key column. The failed Iceberg commit fails the Hudi commit.
DELETE, MERGE INTO and DataFrame upserts on the same table work, because they keep the key column required. A table created with CREATE TABLE in Spark SQL has a nullable key from the start and is not affected.
Cause
- When every record key field is required,
IcebergSchemaExtractor.toIcebergsets the record key as the Iceberg identifier fields. When a key field is nullable, it returns a schema without identifier fields. - The SQL
UPDATEwrites with the catalog schema, in whichidis nullable.IcebergSchemaSync.syncthen callsmakeColumnOptional("id"), but it does not update the identifier fields, soidis still an identifier field when the change is committed.
#366 handled a nullable key when the table is created. This is the case where the nullability changes on an existing table.
IcebergSchemaSync is used by IcebergConversionTarget for every Iceberg target, so a regular sync whose source key changes from required to nullable takes the same path. This was reproduced only through the pluggable table format so far.
Reproduce (Spark 3.5, hudi-spark3.5-bundle_2.12:1.2.1, iceberg-spark-runtime-3.5_2.12:1.9.2 and the 0.5.0 xtable-iceberg-pluggable-tf jars, as in the docs):
val basePath = "/tmp/trips"
Seq((1, "a", 100L, "sf"), (2, "b", 100L, "nyc")).toDF("id", "name", "ts", "city")
.write.format("hudi")
.option("hoodie.table.name", "trips")
.option("hoodie.datasource.write.recordkey.field", "id")
.option("hoodie.datasource.write.precombine.field", "ts")
.option("hoodie.datasource.write.partitionpath.field", "city")
.option("hoodie.table.format", "ICEBERG")
.option("hoodie.metadata.enable", "false")
.mode("append").save(basePath)
spark.sql("SET hoodie.metadata.enable=false")
spark.sql(s"CREATE TABLE trips USING hudi LOCATION '$basePath'")
spark.sql("UPDATE trips SET name = 'u1' WHERE id = 1")
// UpdateException: Failed to record the instant in Iceberg:
// Cannot add field id as an identifier field: not a required fieldPossible fix
In IcebergSchemaSync.sync, set the identifier fields of the latest schema (updateSchema.setIdentifierFields(...)) before the nullability updates run, so the identifier is dropped before the column becomes optional. A case in TestIcebergSchemaSync that changes a required record key to nullable would cover it.
The docs currently list this as a limitation of the Iceberg table format (#995).
Are you willing to submit PR?
- I am willing to submit a PR!
Code of Conduct
- I agree to follow this project's Code of Conduct
Activity