riverandeye opened a new issue, #2778:
URL: https://github.com/apache/iceberg-go/issues/2778

   ## Summary
   
   A copy-on-write `Delete` (and a filtered `Overwrite`) rewrites every data 
file whose metrics say the filter *might* match, even when no row in the file 
matches. The result is a byte-for-byte equivalent copy of the file, a snapshot 
that removes and re-adds it, and a commit that can be rejected by concurrent 
deletes against a file it did not need to touch.
   
   ## Current behavior
   
   Table with one data file holding `name` = `a`, `NULL`, `c`, `d` (bounds `[a, 
d]`), copy-on-write delete mode, v2 or v3:
   
   ```go
   tbl.Delete(ctx, iceberg.EqualTo(iceberg.Reference("name"), "b"), nil)
   ```
   
   The new snapshot summary:
   
   | | added-data-files | added-records | deleted-data-files | deleted-records |
   |---|---|---|---|---|
   | iceberg-go (main) | 1 | 4 | 1 | 4 |
   | expected | 0 | 0 | 0 | 0 |
   
   The doc comment on `Delete` says this does not happen 
([transaction_delete.go#L318](https://github.com/apache/iceberg-go/blob/2add117bae2cd07cae35ac608e0d73437259c155/table/transaction_delete.go#L318),
 same text in 
[table.go#L364](https://github.com/apache/iceberg-go/blob/2add117bae2cd07cae35ac608e0d73437259c155/table/table.go#L364)):
   
   > Files where no rows match the filter are kept unchanged
   
   Cause:
   
   1. 
[`classifyFilesForFilteredDeletions`](https://github.com/apache/iceberg-go/blob/2add117bae2cd07cae35ac608e0d73437259c155/table/transaction_delete.go#L439)
 puts the file in the rewrite set because `b` is inside `[a, d]`: the inclusive 
evaluator says rows might match, the strict evaluator cannot say all rows match.
   2. 
[`rewriteFilesWithFilter`](https://github.com/apache/iceberg-go/blob/2add117bae2cd07cae35ac608e0d73437259c155/table/transaction_delete.go#L649-L698)
 then rewrites every file in that set and unconditionally calls 
`removeDataFile` + `appendDataFile` 
([L692-L695](https://github.com/apache/iceberg-go/blob/2add117bae2cd07cae35ac608e0d73437259c155/table/transaction_delete.go#L692-L695)),
 without checking whether any row was dropped.
   3. Every file in the set is also registered with the concurrent-delete 
validator 
([L153-L169](https://github.com/apache/iceberg-go/blob/2add117bae2cd07cae35ac608e0d73437259c155/table/transaction_delete.go#L153-L169)),
 so a concurrent merge-on-read delete against such a file fails the commit with 
`ErrConflictingDeleteFiles`.
   
   ## Expected behavior
   
   A file with no live row matching the filter is left in place, together with 
its deletes, and is not part of the conflict check. When no file changes, the 
delete commits the same empty snapshot that a filter matching no file's metrics 
already produces today.
   
   Spark copy-on-write `DELETE` behaves this way: the scan is narrowed at 
runtime to the files that hold matching rows 
([SparkCopyOnWriteScan#filter](https://github.com/apache/iceberg/blob/ce1ce419f90354a86ea7a8d7552f8418e4da7a1a/spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/source/SparkCopyOnWriteScan.java#L95)),
 and only those files are overwritten. A delete that matches no row still 
creates a snapshot with no file changes 
([TestDelete#testDeleteNonExistingRecords](https://github.com/apache/iceberg/blob/ce1ce419f90354a86ea7a8d7552f8418e4da7a1a/spark/v4.1/spark-extensions/src/test/java/org/apache/iceberg/spark/extensions/TestDelete.java#L489)).
   
   ## Proposed change
   
   Before rewriting a candidate file, scan it with the delete filter, applying 
its existing deletes, projecting only the filter columns and stopping at the 
first row. If no row comes back, keep the file: skip the rewrite, the 
remove/add, and the validator registration. This uses the same row semantics as 
a table scan with the filter, which is what the rewrite drops.
   


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