[ 
https://issues.apache.org/jira/browse/HIVE-30289?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Gopinath updated HIVE-30289:
----------------------------
    Description: 
h3. Problem

For a write to an Iceberg table, Hive builds the conflict-detection filter from 
the filters that the table's scans push down. 
HiveIcebergStorageHandler#decomposePredicate registers each scan's pushed 
predicate through SessionStateUtil#setConflictDetectionFilter, which ORs 
together the filters of every scan of the same table. 
HiveIcebergOutputCommitter then passes the result to Iceberg's 
conflictDetectionFilter(...).

A scan that pushes no filter registers nothing:
 * a scan without a WHERE clause never reaches decomposePredicate;
 * since HIVE-30252, a scan whose filter reads a virtual column outside a 
top-level AND (for example "a = 1 OR file__path IS NOT NULL") pushes nothing.

When a statement reads the table in more than one scan, the registered filter 
covers only the scans that pushed something. Example:
 * scan 1 of t: WHERE a = 1 OR file__path IS NOT NULL -> pushes nothing, 
registers nothing (it reads every file)
 * scan 2 of t: WHERE a = 1 -> registers a = 1
 * conflict-detection filter at commit: a = 1

The commit is validated only against concurrent changes to files that can hold 
a = 1. A concurrent commit that adds or deletes data in other files is not 
detected, even though scan 1 read those files.

If no scan of the table registers anything, no conflict-detection filter is set 
and Iceberg validates against the whole table. That case is correct 
(conservative).
h3. Expected

The conflict-detection filter covers everything that any scan of the table 
read: always-true if one of the scans read the whole table
h3. Proposed fix
 # When a scan of the table pushes no filter (including a scan without a WHERE 
clause), register an always-true filter. 
SessionStateUtil#getConflictDetectionFilter currently casts the stored filter to
ExprNodeGenericFuncDesc, so the registration and the conversion to an Iceberg 
expression need to accept a constant TRUE. 
 # Optionally, instead of pushing nothing for a non-conjunction that reads a 
virtual column, push a widened filter: replace each comparison on a virtual 
column with TRUE and simplify. For example, "a = 1 OR
partition_{_}spec{_}{_}id = 1" widens to "a = 1 OR a = 2". Iceberg can then 
still prune files, and the conflict filter stays accurate{_}.

h3. References
 * HiveIcebergStorageHandler#decomposePredicate
 * SessionStateUtil#setConflictDetectionFilter / #getConflictDetectionFilter
 * HiveIcebergOutputCommitter#commitWrite (conflictDetectionFilter)
 * Raised in the review of  
[HIVE-30252|https://github.com/apache/hive/pull/6990#discussion_r4738286542]

  was:
h3. Problem
For a write to an Iceberg table, Hive builds the conflict-detection filter from 
the filters that the table's scans push down. 
HiveIcebergStorageHandler#decomposePredicate registers each scan's pushed 
predicate through SessionStateUtil#setConflictDetectionFilter, which ORs 
together the filters of every scan of the same table. 
HiveIcebergOutputCommitter then passes the result to Iceberg's 
conflictDetectionFilter(...).

A scan that pushes no filter registers nothing:
* a scan without a WHERE clause never reaches decomposePredicate;
* since HIVE-30252, a scan whose filter reads a virtual column outside a 
top-level AND (for example "a = 1 OR file__path IS NOT NULL") pushes nothing.

When a statement reads the table in more than one scan, the registered filter 
covers only the scans that pushed something. Example:
* scan 1 of t: WHERE a = 1 OR file__path IS NOT NULL -> pushes nothing, 
registers nothing (it reads every file)
* scan 2 of t: WHERE a = 1 -> registers a = 1
* conflict-detection filter at commit: a = 1

The commit is validated only against concurrent changes to files that can hold 
a = 1. A concurrent commit that adds or deletes data in other files is not 
detected, even though scan 1 read those files.

If no scan of the table registers anything, no conflict-detection filter is set 
and Iceberg validates against the whole table. That case is correct 
(conservative).

h3. Expected
The conflict-detection filter covers everything that any scan of the table 
read: always-tthe whole table.

h3. Proposed fix
# When a scan of the table pushes no filter (including a scan without a WHERE 
clause), register an always-true filter. 
SessionStateUtil#getConflictDetectionFilter currently casts the stored filter to
ExprNodeGenericFuncDesc, so the registration and the conversion to an Iceberg 
expression E.
# Optionally, instead of pushing nothing for a non-conjunction that reads a 
virtual column, push a widened filter: replace each comparison on a virtual 
column with TRUE and simplify. For example, "a = 1 OR
partition__spec__id = 1" widens to TRUE, and "(a = 1 AND file__path = 'x') OR a 
= 2" widerg can then still prune files, and the conflict filter stays accurate.

h3. References
* HiveIcebergStorageHandler#decomposePredicate
* SessionStateUtil#setConflictDetectionFilter / #getConflictDetectionFilter
* HiveIcebergOutputCommitter#commitWrite (conflictDetectionFilter)
* Raised in the review of HIVE-30252: 
https://github.com/apache/hive/pull/6990#discussion


>  Iceberg: The conflict-detection filter can be narrower than what a scan of 
> the table read
> ------------------------------------------------------------------------------------------
>
>                 Key: HIVE-30289
>                 URL: https://issues.apache.org/jira/browse/HIVE-30289
>             Project: Hive
>          Issue Type: Bug
>          Components: Iceberg integration
>            Reporter: Gopinath
>            Assignee: Gopinath
>            Priority: Major
>              Labels: concurrency, iceberg
>
> h3. Problem
> For a write to an Iceberg table, Hive builds the conflict-detection filter 
> from the filters that the table's scans push down. 
> HiveIcebergStorageHandler#decomposePredicate registers each scan's pushed 
> predicate through SessionStateUtil#setConflictDetectionFilter, which ORs 
> together the filters of every scan of the same table. 
> HiveIcebergOutputCommitter then passes the result to Iceberg's 
> conflictDetectionFilter(...).
> A scan that pushes no filter registers nothing:
>  * a scan without a WHERE clause never reaches decomposePredicate;
>  * since HIVE-30252, a scan whose filter reads a virtual column outside a 
> top-level AND (for example "a = 1 OR file__path IS NOT NULL") pushes nothing.
> When a statement reads the table in more than one scan, the registered filter 
> covers only the scans that pushed something. Example:
>  * scan 1 of t: WHERE a = 1 OR file__path IS NOT NULL -> pushes nothing, 
> registers nothing (it reads every file)
>  * scan 2 of t: WHERE a = 1 -> registers a = 1
>  * conflict-detection filter at commit: a = 1
> The commit is validated only against concurrent changes to files that can 
> hold a = 1. A concurrent commit that adds or deletes data in other files is 
> not detected, even though scan 1 read those files.
> If no scan of the table registers anything, no conflict-detection filter is 
> set and Iceberg validates against the whole table. That case is correct 
> (conservative).
> h3. Expected
> The conflict-detection filter covers everything that any scan of the table 
> read: always-true if one of the scans read the whole table
> h3. Proposed fix
>  # When a scan of the table pushes no filter (including a scan without a 
> WHERE clause), register an always-true filter. 
> SessionStateUtil#getConflictDetectionFilter currently casts the stored filter 
> to
> ExprNodeGenericFuncDesc, so the registration and the conversion to an Iceberg 
> expression need to accept a constant TRUE. 
>  # Optionally, instead of pushing nothing for a non-conjunction that reads a 
> virtual column, push a widened filter: replace each comparison on a virtual 
> column with TRUE and simplify. For example, "a = 1 OR
> partition_{_}spec{_}{_}id = 1" widens to "a = 1 OR a = 2". Iceberg can then 
> still prune files, and the conflict filter stays accurate{_}.
> h3. References
>  * HiveIcebergStorageHandler#decomposePredicate
>  * SessionStateUtil#setConflictDetectionFilter / #getConflictDetectionFilter
>  * HiveIcebergOutputCommitter#commitWrite (conflictDetectionFilter)
>  * Raised in the review of  
> [HIVE-30252|https://github.com/apache/hive/pull/6990#discussion_r4738286542]



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to