ggangadharan opened a new pull request, #7000:
URL: https://github.com/apache/hive/pull/7000
### 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-30289](https://issues.apache.org/jira/browse/HIVE-30289), follow-up to
[HIVE-30252](https://issues.apache.org/jira/browse/HIVE-30252) ([review
discussion](https://github.com/apache/hive/pull/6990#discussion_r4738286542)).
For a write to an Iceberg table, the conflict-detection filter is the OR of
the filters that the table's scans push down. This PR makes that filter cover
everything any scan of the table read.
**1. A scan that pushes no filter registers an always-true filter.**
- `HiveStoragePredicateHandler#noPredicatePushed(TableDesc)`: new default
no-op method.
- `OpProcFactory.TableScanPPD`: after predicate pushdown, for a scan of a
non-native table whose storage handler is a `HiveStoragePredicateHandler` and
whose `filterExpr` is null, calls `noPredicatePushed`. The filter is null when
there is no WHERE clause, no predicate reaches the scan, or the handler pushes
none of it. No plan changes.
- `HiveIcebergStorageHandler#noPredicatePushed` registers a constant TRUE
through `SessionStateUtil#setConflictDetectionFilter`.
- `SessionStateUtil`: TRUE absorbs the disjunction.
`getConflictDetectionFilter` returns empty for TRUE, so
`HiveIcebergOutputCommitter` (unchanged) sets no `conflictDetectionFilter`, and
Iceberg validates against the whole table. If the disjunction cannot be built,
the filter now becomes TRUE. Before, the filter was dropped, so a later scan
could narrow it again.
- `ExprNodeDescUtils#isTrue` is made public for reuse.
**2. A filter that reads a virtual column outside a top-level AND is pushed
widened instead of not at all.**
- `HiveIcebergStorageHandler#decomposePredicate` replaces every operand of
AND/OR that reads a virtual column with TRUE, then simplifies.
- For example, `(a = 1 AND partition__spec__id = 0) OR b = 10` pushes `a = 1
OR b = 10`, and `a = 1 OR file__path IS NOT NULL` still pushes nothing.
- This generalizes the HIVE-30252 rule (leave out conjuncts that read a
virtual column) to any nesting. Replacing an operand with TRUE only widens the
pushed filter, and the residual is still the entire filter, so results are
unchanged.
- Iceberg can still prune files, and the conflict-detection filter (the
pushed filter) stays accurate.
### 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.
-->
A scan that pushes no filter registered nothing. When a statement reads the
table in more than one scan, the conflict-detection filter covered only the
scans that pushed something. A concurrent commit to files read by the other
scans went undetected. Example, both sessions running concurrently:
```sql
-- session 1
UPDATE customers SET first_name = 'Changed' WHERE last_name = 'Donnel';
-- session 2: the subquery reads every file, but only last_name = 'Taylor'
was registered
UPDATE customers SET first_name = 'Changed'
WHERE last_name = 'Taylor' AND customer_id < (SELECT max(customer_id) FROM
customers);
```
Before this change both commit: session 2 is validated only against
`last_name = 'Taylor'`, although its subquery read Donnel's file. The same
happens when a scan's filter has a virtual column under OR (`... WHERE
customer_id = 1 OR file__path IS NOT NULL`), which pushes nothing since
HIVE-30252.
The opposite problem also existed. A single scan such as `WHERE (last_name =
'Taylor' AND partition__spec__id = 0) OR customer_id = 5` pushed nothing. So it
read every file and conflicted with any concurrent commit, even one that
touched none of the files it needs.
### 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.
- **Conflicts detected that weren't before:** a write whose statement reads
the target table in a scan that pushes no filter is now validated against the
whole table. A concurrent commit that went undetected before now fails it with
`ValidationException: Found conflicting files ...`, or triggers a retry if a
retry strategy is configured. This is the correct serializable behavior. The
gap for scans without a WHERE clause also exists in released versions.
- **Fewer files read and fewer false conflicts:** a filter with a virtual
column under OR now prunes files, and its conflict-detection filter no longer
covers the whole table. EXPLAIN shows the widened `filterExpr` on the
TableScan. Query results are unchanged. This part changes behavior introduced
by HIVE-30252, which is on master only.
### 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 tests:
- `TestConflictingDataFiles`: 3 tests, run on format versions 1-3. All of
them failed on master before this change and pass with it.
- `testConflictingUpdateWithSubqueryReadingWholeTable`: a subquery scan
without a filter. Before: no conflict detected.
- `testConflictingUpdateWithSubqueryPushingNothing`: a subquery whose
filter has a virtual column under OR. Before: no conflict detected.
- `testUpdatesWithVirtualColumnUnderOr`: the widened filter prunes, so the
updates don't conflict. Before: false conflict on v2/v3.
- `TestHiveIcebergStorageHandler`: widening cases, including nested AND/OR,
NOT, and a check that the input filter is not modified.
- `TestSessionStateUtil` (new): the disjunction of scan filters, and TRUE
registered before or after a filter.
- `iceberg_virtual_column_pushdown.q` extended:
- The EXPLAIN shows `filterExpr: ((b = 10) or (a = 1))`.
- The widened filter reads 2 of 3 files (`RECORDS_IN_Map_1: 4`).
- The residual filter keeps only the matching rows.
- An UPDATE with the widened filter changes only the matching row.
- Pre-existing output is unchanged.
Regression, Validated below all Passed :
- `TestConflictingDataFiles` (33 run), `TestOptimisticRetry` and
`TestConcurrentMultiTableTransactions` (33 run)
- `TestHiveIcebergCRUD` (525 run), `TestHiveIcebergVectorization` (15 run),
`TestHiveIcebergFilterFactory`
- 16 Iceberg qtests with unchanged golden files:
- `iceberg_row_mode_virtual_columns`, `llap_iceberg_read_orc_deletes`,
`query_iceberg_virtualcol`, `iceberg_v3_dml_distribution`
-
`{delete,update,merge}_iceberg_copy_on_write_{partitioned,unpartitioned}`,
`{delete,update,merge}_iceberg_partitioned_orc`
- `mv_iceberg_orc`, `mv_iceberg_orc4`, `mv_iceberg_orc8`
To reproduce:
```
mvn test -pl iceberg/iceberg-handler
-Dtest='TestConflictingDataFiles,TestHiveIcebergStorageHandler'
mvn test -pl ql -Dtest=TestSessionStateUtil
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]