Neuw84 opened a new issue, #19333:
URL: https://github.com/apache/iceberg/issues/19333

   ### Apache Iceberg version
   
   main (development), at d991c9fc1
   
   ### Query engine
   
   None (generic reader); Spark shows the same result
   
   ### Please describe the bug 🐞
   
   An equality delete on a field nested in an optional struct, with a null key, 
does not delete rows where the parent struct itself is null.
   
   The spec allows equality fields under optional structs and defines how nulls 
work there:
   
   > columns nested under optional structs are allowed (if a parent struct 
column is null it implies the leaf column is null)
   
   So for a table `id int, st struct<k int, s string>`, a row with `st = null` 
has `st.k = null`, and an equality delete with `st.k = null` should delete it.
   
   **Repro**
   
   1. Create a format v2 table `id int, st struct<k int, s string>`.
   2. Write data rows where some have `st = null`, some have `st = {k: null, s: 
...}`, and some have a non-null `st.k`.
   3. Write an equality delete file with `equalityFieldIds = [id of st.k]`, 
delete schema `table.schema().select("st.k")`, and one record whose `st` is a 
struct with `k = null`.
   4. Read the table with `IcebergGenerics.read(table)` or through Spark.
   
   Expected: rows with `st = {k: null}` and rows with `st = null` are both 
deleted.
   Actual: rows with `st = {k: null}` are deleted; rows with `st = null` are 
returned.
   
   **Cause**
   
   `DeleteFilter.applyEqDeletes` builds a `StructLikeSet` of the delete keys 
and wraps each data row in a `StructProjection` of the equality fields. For a 
row where `st` is null, `StructProjection.get` returns null for the nested 
projection (`if (nestedStruct == null) return null;`), so the projected key is 
`{st: null}`. The delete key is `{st: {k: null}}`. The two do not compare 
equal, so the row is kept.
   
   A fix would need the key comparison to treat a null parent as a struct whose 
leaves are all null, either in `StructProjection` (for the equality-delete use 
only, since other callers rely on the null) or by normalizing the delete keys 
and projected rows in `DeleteFilter`.
   
   **Related**
   
   - #18620 / #19331 fix equality deletes on a nested field the query does not 
read. This gap is independent of that fix: it shows on `main` and with #19331, 
whether or not the struct is projected.
   - #19162 covers the same null-ancestor rule in scan planning 
(`DeleteFileIndex` pruning). This issue is about the row-level delete apply.
   
   ### Willingness to contribute
   
   - [x] I can contribute a fix for this bug independently
   


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