[Spark] Schema evolution fails when promoting 'unknown' type column to primitive type
Apache Iceberg version
1.11.0 (latest release)
Query engine
Spark
Please describe the bug 🐞
Iceberg v3 introduces the unknown data type to gracefully represent columns without physical storage (such as Spark's VOID / all-null columns). However, attempting to lazily evolve an unknown column into a concrete primitive type (e.g., STRING) using Spark SQL's ALTER TABLE ... ALTER COLUMN ... TYPE statement fails during logical plan execution.
TypePromotion.canPromote() in Iceberg currently does not handle promotions from UnknownType to primitive types during schema evolution validation, resulting in an IllegalArgumentException
Steps to Reproduce:
spark.sql("CREATE DATABASE IF NOT EXISTS ds2_standalone.iceberg_v3_qe")
spark.sql("DROP TABLE IF EXISTS ds2_standalone.iceberg_v3_qe.table1")
spark.sql("CREATE TABLE ds2_standalone.iceberg_v3_qe.table1 (id INT, payload VOID) USING ICEBERG TBLPROPERTIES ('format-version'='3')")
spark.sql("INSERT INTO ds2_standalone.iceberg_v3_qe.table1 (id) VALUES (1), (2)")
spark.sql("SELECT payload FROM ds2_standalone.iceberg_v3_qe.table1").show()
spark.sql("ALTER TABLE ds2_standalone.iceberg_v3_qe.table1 ALTER COLUMN payload TYPE STRING") ## Fails here!
Error:
The job crashes during logical plan execution with: java.lang.IllegalArgumentException: Unsupported table change: Cannot change column type: payload: unknown -> string
Willingness to contribute
- [ ] I can contribute a fix for this bug independently
- [ ] I would be willing to contribute a fix for this bug with guidance from the Iceberg community
- [ ] I cannot contribute a fix for this bug at this time
Hi @abjain123, are you currently working on a PR for this? If not, I'd be happy to take this up and work on a fix.
@adityaksolves I am not currently working on this. You can take this up!
Thanks @abjain123! I am picking this up.