Yibo-Dong opened a new issue, #19270:
URL: https://github.com/apache/iceberg/issues/19270
### Apache Iceberg version
main (development)
### Query engine
Spark
### Please describe the bug 🐞
When a dropped partition field is added back to a v2 table, Iceberg reuses
the old field's ID and name without checking whether the current spec already
uses them. In (1) the field was dropped while the table was v1, so the new spec
has two fields with ID 1000, and every read and write of the table fails. In
(2) the old name belongs to another field, so `ADD PARTITION FIELD` fails.
Reproduced on `main` (3bfa3e4, 2026-12-01) and 1.12.0, Spark 3.5.5.
### Reproduction
```sql
-- (1) drop the partition field while v1, upgrade to v2, add it back
CREATE TABLE local.db.t (id INT, p INT) USING iceberg PARTITIONED BY (p)
TBLPROPERTIES ('format-version'='1');
ALTER TABLE local.db.t DROP PARTITION FIELD p;
ALTER TABLE local.db.t SET TBLPROPERTIES ('format-version'='2');
ALTER TABLE local.db.t ADD PARTITION FIELD p;
SELECT * FROM local.db.t;
-- (2) v2: the old name of identity(p) is now used by another field
CREATE TABLE local.db.u (p INT, q INT) USING iceberg;
ALTER TABLE local.db.u ADD PARTITION FIELD identity(p) AS old_alias;
ALTER TABLE local.db.u DROP PARTITION FIELD old_alias;
ALTER TABLE local.db.u ADD PARTITION FIELD identity(q) AS old_alias;
ALTER TABLE local.db.u ADD PARTITION FIELD identity(p);
-- control: (1) on a table that is v2 from the start
CREATE TABLE local.db.c (id INT, p INT) USING iceberg PARTITIONED BY (p)
TBLPROPERTIES ('format-version'='2');
ALTER TABLE local.db.c DROP PARTITION FIELD p;
ALTER TABLE local.db.c ADD PARTITION FIELD p;
INSERT INTO local.db.c VALUES (1, 1);
SELECT * FROM local.db.c;
```
### Expected
| Query | Result |
|---|---|
| (1) `SELECT` on `t` | succeeds |
| (2) last `ADD PARTITION FIELD` on `u` | succeeds |
| `c` (control) | `1 1` |
### Actual
| Query | Result |
|---|---|
| (1) `SELECT` on `t` | `IllegalArgumentException: Multiple entries with
same key: 1000=1000: p: optional int and 1000=1000: p_1000: optional int` |
| (2) last `ADD PARTITION FIELD` on `u` | `IllegalArgumentException: Cannot
add duplicate partition field name: null` |
| `c` (control) | `1 1` |
### 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
- [x] I cannot contribute a fix for this bug at this time
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]