Neuw84 opened a new pull request, #19331: URL: https://github.com/apache/iceberg/pull/19331
Fixes #18620. ### Problem When an equality delete uses a field nested in a struct, and the query does not read that struct, every row with a non-null struct is deleted (or, depending on the reader, every row). The Spark reproduction in the issue returns 0 of 5,760 expected rows. The generic reader shows the same bug: with the new test below it deletes all 10 rows whose struct is set, where only 3 match a delete. The cause is in `DeleteFilter.fileProjection`, shared by the generic, Spark, Flink and MR readers. It adds each equality field the query does not read to the read schema, so the delete can be applied. The code noted this with `TODO: support adding nested columns`: a nested field such as `st.k` was added as a top-level column. The reader then looks for a top-level column with that ID, which the data file and the delete file do not have, and reads a wrong value for the key on both sides, so the delete set and the rows compare equal. The `StructProjection` / `StructLikeSet` layer is not involved: when the struct is projected (`SELECT *`), the same deletes are applied correctly. ### Change - `DeleteFilter` adds a missing equality field together with its parent structs. If a parent struct is already in the read schema, the missing field is appended after the fields already read, so the positions the engine reads by do not change. A field nested in a list or map is rejected with an error, since the spec only allows struct parents for equality (identifier) fields. - The table-schema constructors index parents with `TypeUtil.indexParents`. A new protected constructor takes a parent lookup next to the field lookup. The existing lookup-only constructor (added for schema evolution in #15268) is deprecated, because it cannot place a nested field. - Spark 4.1 and 4.2 pass a `ParentLookup` over the current and historic schemas, matching `FieldLookup`. - Spark 3.5, 4.0, 4.1 and 4.2 `SparkBatch` no longer use Parquet batch reads when a task has an equality delete on a nested field: the vectorized Parquet reader does not read structs, and the read schema now holds one. This matches how ORC batch reads are already turned off for tasks with deletes. ### Tests - `DeleteReadTests` (run by the generic, Spark, Flink and MR reader suites): `testEqualityDeleteNestedField` (struct projected) and `testEqualityDeleteNestedFieldNotProjected` (only `id` read). `FileHelpers.writeDeleteFile` gains an overload that takes the equality field IDs, since the existing one only uses top-level columns. - `TestDeleteFilterProjection`: the read schema for a top-level field, a nested field with and without its parent projected, two fields of one struct, two levels of nesting, an already projected field, a field in a list (rejected), and the parent-lookup constructor. Before the fix, on `main` (d991c9fc1) with only the new tests added: | Reader | `testEqualityDeleteNestedField` (struct read) | `testEqualityDeleteNestedFieldNotProjected` (only `id` read) | |---|---|---| | Generic (`TestGenericReaderDeletes`) | passes | fails in all 4 parameterizations: 7 rows returned, 14 expected | | Spark 4.1 (`TestSparkReaderDeletes`) | passes | fails in all 6 parameterizations: 0 rows returned, 14 expected | With the fix (JDK 21, Scala 2.13 for Spark, 2.12 for Flink): | Suite | Tests | Failures | |---|---|---| | `TestGenericReaderDeletes` | 52 (1 skipped) | 0 | | `TestDeleteFilterProjection` | 8 | 0 | | Spark 4.2 `TestSparkReaderDeletes` | 156 (12 skipped) | 0 | | Spark 4.1 `TestSparkReaderDeletes` | 150 (8 skipped) | 0 | | Spark 4.0 `TestSparkReaderDeletes` | 138 (6 skipped) | 0 | | Spark 3.5 `TestSparkReaderDeletes` | 138 (6 skipped) | 0 | | Flink 1.20, 2.2, 2.3 `TestFlinkInputFormatReaderDeletes`, `TestIcebergSourceReaderDeletes` | 52 each (1 skipped) | 0 | | MR `TestInputFormatReaderDeletes` | 104 (2 skipped) | 0 | `checkstyleMain`/`checkstyleTest`, `spotlessCheck` and `revapi` pass for `iceberg-data`, and checkstyle and spotless pass for the four Spark modules. Without the `SparkBatch` change, the vectorized Parquet legs of the new Spark test failed with `UnsupportedOperationException: Vectorized reads are not supported yet for struct fields` once the struct was in the read schema. -- 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]
