merge-on-read UPDATE fails after dropping a partition field and its source column
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- java, spark
- Domain
- data-engineering
Research direction
The failure comes from StructProjection.create, called by buildPartitionProjections in SparkPositionDeltaWrite.java (BaseDeltaWriter), which looks up partition field 1000 in a schema where the source column is gone. Start by reading StructProjection.java around line 175 and the partition-projection setup in SparkPositionDeltaWrite.java near line 471, then reproduce with the SQL in the issue. Done means the merge-on-read UPDATE succeeds and returns (1, 110) and (2, 20), with a regression test for dropped partition source columns.
Written by the indexing model from the issue text.
Description
Apache Iceberg version
main (development)
Query engine
Spark
Please describe the bug 🐞
After a partition field is dropped and then its source column is dropped, a merge-on-read UPDATE on the table fails while constructing the position-delta writer. The same UPDATE succeeds with copy-on-write, and it also succeeds in merge-on-read mode if the source column is kept.
Reproduction
-- merge-on-read: fails
CREATE TABLE local.candidate (id INT, p STRING, v INT)
USING iceberg
PARTITIONED BY (p)
TBLPROPERTIES ('format-version'='2');
INSERT INTO local.candidate VALUES (1, 'a', 10), (2, 'b', 20);
ALTER TABLE local.candidate DROP PARTITION FIELD p;
ALTER TABLE local.candidate DROP COLUMN p;
ALTER TABLE local.candidate SET TBLPROPERTIES ('write.update.mode'='merge-on-read');
UPDATE local.candidate SET v = v + 100 WHERE id = 1;
SELECT id, v FROM local.candidate ORDER BY id;
-- control, copy-on-write: succeeds
CREATE TABLE local.control (id INT, p STRING, v INT)
USING iceberg
PARTITIONED BY (p)
TBLPROPERTIES ('format-version'='2');
INSERT INTO local.control VALUES (1, 'a', 10), (2, 'b', 20);
ALTER TABLE local.control DROP PARTITION FIELD p;
ALTER TABLE local.control DROP COLUMN p;
UPDATE local.control SET v = v + 100 WHERE id = 1;
SELECT id, v FROM local.control ORDER BY id;
Expected
Both UPDATE statements succeed and both tables contain (1, 110) and (2, 20).
Actual
The copy-on-write control returns (1, 110), (2, 20). The merge-on-read UPDATE fails and the table is left at (1, 10), (2, 20):
java.lang.IllegalArgumentException: Cannot find field 1000: p: optional unknown in struct<>
at org.apache.iceberg.util.StructProjection.<init>(StructProjection.java:175)
at org.apache.iceberg.util.StructProjection.<init>(StructProjection.java:103)
at org.apache.iceberg.util.StructProjection.create(StructProjection.java:72)
at org.apache.iceberg.spark.source.SparkPositionDeltaWrite$BaseDeltaWriter.buildPartitionProjections(SparkPositionDeltaWrite.java:471)
at org.apache.iceberg.spark.source.SparkPositionDeltaWrite$DeleteAndDataDeltaWriter.<init>(SparkPositionDeltaWrite.java:674)
at org.apache.iceberg.spark.source.SparkPositionDeltaWrite$UnpartitionedDeltaWriter.<init>(SparkPositionDeltaWrite.java:738)
at org.apache.iceberg.spark.source.SparkPositionDeltaWrite$PositionDeltaWriteFactory.createWriter(SparkPositionDeltaWrite.java:445)
...
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
- Dominant language
- Java
- Stars
- 9.5k
- Forks
- 3.7k
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 170
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from apache/iceberg
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Spark: Test INSERT targets with computed IDENTIFIER expressionsPossibly taken @shivadarshan-devadiga claimed this 15 days ago. Openimprovement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
[Core] TestAvroPartitionStatsHandler fails on Windows due to unclosed partition statistics scanPossibly taken @Ankitkj1999 claimed this 17 days ago. Open
Difficulty 1/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
Core: TableMetadata.Builder allows adding encryption keys to v1/v2 tablesPossibly taken @yusufyildiz34 claimed this 37 days ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
apache/iceberg#18632 · 1 comment ·
Maintainers usually reply within 1 day
-
Kafka: Filter empty strings and whitespace in IcebergSinkConfig stringToListPossibly taken @mohamed-elbrik claimed this 42 days ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
Similar issues
-
Difficulty 1/5 1-3 hours Newbie friendliness 92/100
HexaHexes/neoforge-mod-template#124 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
OpenLiberty/open-liberty#36410 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
erkamyaman/rust-anything#1153 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Card-Forge/forge#13173 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day