ggangadharan opened a new pull request, #6990:
URL: https://github.com/apache/hive/pull/6990
### What changes were proposed in this pull request?
<!--
Please clarify what changes you are proposing. The purpose of this section
is to outline the changes and how this PR fixes the issue.
If possible, please consider writing useful notes for better and faster
reviews in your PR. See the examples below.
1. If you refactor some codes with changing classes, showing the class
hierarchy will help reviewers.
2. If you fix some SQL features, you can provide some references of other
DBMSes.
3. If there is design documentation, please add the link.
4. If there is a discussion in the mailing list, please add the link.
-->
Hive keeps the full filter as the residual predicate and re-applies it after
the scan. That makes it safe to push a **wider** filter to Iceberg, but pushing
a **narrower** one loses rows. This PR makes sure the pushed filter is never
narrower than the original.
- `HiveIcebergStorageHandler.decomposePredicate`
- Iceberg cannot evaluate these virtual columns: `FILE__PATH`,
`PARTITION__SPEC__ID`, `PARTITION__HASH`, `PARTITION__NAME`,
`ROW__LINEAGE__ID`, `LAST__UPDATED__SEQUENCE__NUMBER`.
- An operand that reads one of them is now left out **only when it is a
conjunct of a top-level `AND`**.
- For any other root (`OR`, `NOT`, `BETWEEN`, `IN`, a comparison, ...)
that reads such a column, nothing is pushed.
- The set of non-pushable virtual columns is now a static constant instead
of being built on every call. The predicate is cloned only when something is
pushed, and the column list is computed once per node.
- `DeleteSemanticAnalyzer`
- A `DELETE` is no longer converted into a metadata delete when its scan
filter reads a virtual column.
- The metadata-delete condition is built from the pushed filter, which
leaves those conjuncts out.
This follows the approach proposed by @deniskuzZ in #6971.
### Why are the changes needed?
<!--
Please clarify why the changes are needed. For instance,
1. If you propose a new API, clarify the use case for a new API.
2. If you fix a bug, you can clarify why it is a bug.
-->
`decomposePredicate` removed every operand that read a virtual column from
**any** predicate root, without checking that the root is an `AND`.
- **OR:** removing a disjunct narrows the pushed filter. Iceberg prunes data
files that hold qualifying rows, and the residual filter cannot bring them
back. On a table with 3 data files of 2 rows each, `select a from ice_vc where
a = 1 or partition__spec__id = 0` returned 2 of 6 rows. Three-way ORs and `NOT
(... AND ...)`, which Hive rewrites into an OR, have the same problem.
- **BETWEEN:** removing the column operand leaves 3 of the 4 operands, and
the query fails with `ArrayIndexOutOfBoundsException: Index 3 out of bounds for
length 3` in `GenericUDFBetween.getDisplayString`.
- **IN and comparisons:** the pushed predicate is malformed, e.g. `(0) IN
(1)`. Results were correct only because the conversion to a search argument
failed.
- **DELETE / UPDATE under OR:** too few rows were deleted or updated, for
both merge-on-read and copy-on-write.
- **DELETE under AND:** the metadata delete used the narrowed filter.
`delete from t where a = 1 and partition__spec__id = 1` dropped the whole data
file holding `a = 1`, although no row has spec id 1.
- **Conflict detection:** the conflict-detection filter
(`SessionStateUtil.setConflictDetectionFilter`) was narrowed the same way, so
it covered too few files.
### Does this PR introduce _any_ user-facing change?
<!--
Note that it means *any* user-facing change including all aspects such as
the documentation fix.
If yes, please clarify the previous behavior and the change this PR proposes
- provide the console output, description, screenshot and/or a reproducible
example to show the behavior difference if possible.
If possible, please also clarify if this is a user-facing change compared to
the released Hive versions or within the unreleased branches such as master.
If no, write 'No'.
-->
Yes, these are correctness fixes:
- A filter that reads a virtual column outside a top-level `AND` returns all
qualifying rows. Previously, rows were silently lost.
- `DELETE` / `UPDATE` with such a filter affect all qualifying rows.
- A `DELETE` that ANDs a virtual column deletes only the matching rows.
- `BETWEEN` on a virtual column no longer fails.
- Such filters no longer prune Iceberg data files.
- A `DELETE` whose filter reads a virtual column runs as a regular delete
instead of a metadata-only delete.
- Filters where virtual columns appear only as `AND` conjuncts still prune
as before.
### How was this patch tested?
<!--
If tests were added, say they were added here. Please make sure to add some
test cases that check the changes thoroughly including negative and positive
cases if possible.
If it was tested in a way different from regular unit tests, please clarify
how you tested step by step, ideally copy and paste-able, so that other
reviewers can test and check, and descendants can verify in the future.
If tests were not added, please describe why they were not added and/or why
it was difficult to add.
-->
**New qtest `iceberg_virtual_column_pushdown.q`
(`TestIcebergLlapLocalCliDriver`).** Each insert writes one data file, and
`RECORDS_IN_Map_1` shows how many rows of the scanned files were read. Running
it without the fix reproduces every failure:
| Query (table of 3 files x 2 rows) | Without fix | With fix |
|---|---|---|
| `a = 1 or file__path is not null` | 2 rows (2 read) | 6 rows (6 read) |
| `a = 1 or partition__spec__id = 0` | 2 rows (2 read) | 6 rows (6 read) |
| `a = 1 or a = 10 or partition__spec__id = 0` | 4 rows (4 read) | 6 rows (6
read) |
| `not (a < 10 and partition__spec__id = 1)` | 4 rows (4 read) | 6 rows (6
read) |
| `partition__spec__id between 0 and 1` | `ArrayIndexOutOfBoundsException` |
6 rows |
| `partition__spec__id in (0, 1)` | 6 rows | 6 rows |
| `a = 1 and file__path is not null` | 1 row (2 read) | 1 row (2 read),
still prunes |
| `DELETE ... a = 1 and partition__spec__id = 1` (MoR and CoW) | row `1`
deleted | nothing deleted |
| `DELETE ... a = 1 or partition__spec__id = 0` (MoR and CoW) | row `2`
remains | no rows remain |
| `UPDATE ... set b = 'y' where a = 1 or partition__spec__id = 0` | only row
`1` updated | both rows updated |
**New unit tests in `TestHiveIcebergStorageHandler`:**
- `AND`: conjuncts that read virtual columns are left out, and nothing is
pushed when every conjunct reads one.
- `OR`, `BETWEEN`, `IN` and comparisons that read a virtual column: nothing
is pushed.
- A filter without virtual columns: the whole filter is pushed, as a copy.
- In every case the residual is the original predicate.
**Existing tests (all pass, no output changes):**
- `TestHiveIcebergSelects#testFilterOnPartitionName`
- 64 Iceberg qtests covering DELETE/UPDATE/MERGE, copy-on-write, metadata
delete, virtual columns, row lineage and compaction:
- `TestIcebergCliDriver` (41): e.g. `metadata_delete`, `delete_iceberg_*`,
`update_iceberg_*`, `merge_iceberg_*`, `*_copy_on_write_*`,
`query_iceberg_virtualcol`, `row_lineage`, `iceberg_v3_dml_distribution`,
`iceberg_v3_deletion_vectors`
- `TestIcebergLlapLocalCliDriver` (7): e.g.
`iceberg_row_mode_virtual_columns`, `iceberg_merge_delete_files`,
`llap_iceberg_read_orc_deletes`
- `TestIcebergLlapLocalCompactorCliDriver` (16):
`iceberg_major_compaction_*` and `iceberg_minor_compaction_*`, including
partition evolution, plus `iceberg_row_lineage_compactions`
To reproduce locally:
```
mvn test -pl iceberg/iceberg-handler -Dtest=TestHiveIcebergStorageHandler
cd itests/qtest-iceberg
mvn test -Dtest=TestIcebergLlapLocalCliDriver
-Dqfile=iceberg_virtual_column_pushdown.q
```
--
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]