bvolpato-dd opened a new pull request, #15965:
URL: https://github.com/apache/iceberg/pull/15965

   ## Summary
   
   #13301 made `SnapshotScan.specs()` re-bind every historical partition spec 
to the time-travel snapshot's schema using strict `bind()`. If a later 
partition spec references a column that was added *after* the target snapshot, 
this throws `ValidationException` at plan time and the scan fails.
   
   Repro:
   
   1. Create a table, write data -- snapshot `S1`.
   2. `ALTER TABLE ... ADD COLUMN extra STRING`.
   3. `ALTER TABLE ... ADD PARTITION FIELD extra`.
   4. Write data -- snapshot `S2`.
   5. `table.newScan().useSnapshot(S1).planFiles()` -- fails with:
   
   ```
   org.apache.iceberg.exceptions.ValidationException: Cannot find source column 
for partition field: 1001: extra: identity(4)
       at 
org.apache.iceberg.PartitionSpec.checkCompatibility(PartitionSpec.java:656)
       at org.apache.iceberg.PartitionSpec$Builder.build(PartitionSpec.java:628)
       at 
org.apache.iceberg.UnboundPartitionSpec.bind(UnboundPartitionSpec.java:46)
       at org.apache.iceberg.SnapshotScan.specs(SnapshotScan.java:98)
       at org.apache.iceberg.DataTableScan.doPlanFiles(DataTableScan.java:77)
   ```
   
   Reproduces on format versions 1-4. It affects all `DataTableScan` consumers 
(Spark, Flink, Trino, core API) on any table that evolves its spec to include a 
column added after the target snapshot -- for example, disaster-recovery reads 
after a bad DDL.
   
   ## Fix
   
   Use `bind(snapshotSchema, true)` so missing source fields are tolerated 
during the re-bind. Files written with a spec that references a 
not-yet-existing column cannot appear in the target snapshot, so that spec is 
never actually used during planning -- it only needs to be constructible so the 
specs-by-id map can be built for the specs that *are* used. This matches the 
precedent already set by `BaseMetadataTable.build(true)` from #14089.
   
   ## Test plan
   
   - [x] New test `testTimeTravelAfterAddingPartitionFieldOnNewColumn` in 
`TestScansAndSchemaEvolution` -- fails on current `main`, passes with the fix, 
all 4 format versions.
   - [x] Existing `TestScansAndSchemaEvolution` suite still green.
   - [ ] Still validating the fix -- leaving as draft until I've thought 
through edge cases around transforms that depend on source type (bucket, 
truncate) when the source type is missing, and whether any downstream code 
assumes `specs()` returns fully-bound specs.


-- 
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]

Reply via email to