deepaknettem opened a new pull request, #1154:
URL: https://github.com/apache/iceberg-cpp/pull/1154

   ### **Problem**
   
   Support for StartsWith metadata-based pruning
   
   StrictMetricsEvaluator is called from DeleteFiles or OverwriteFiles for 
metadata-based evaluation / pruning. It checks whether every row in a data file 
is guaranteed to match the predicate. It is important to make sure we don't 
have false positives here, otherwise we will have correctness issues.
   
   Per the spec, string lower_bounds and upper_bounds are stored in manifest 
entries as UTF-8 bytes. The bounds are drawn only from non-null values in a 
column. If the column contains null, startsWith doesn't match all rows, so 
return false.
   
   **_Edge case:_** Writers can truncate the bounds (for example truncate(16)). 
Even with truncation, lower_bound <= min and max <= upper_bound still hold, so 
checking both bounds would still be safe. Note: If a bound was truncated 
shorter than the prefix, StartsWith should return false.
   
   ### **Fix**
   
   Java Reference Implementation: 
[StrictEvalVisitor.java](https://github.com/apache/iceberg/blob/282ff355692a71e6e974fa96c5ecd8bd9e3d5fe2/api/src/main/java/org/apache/iceberg/expressions/StrictEvalVisitor.java#L386)
   
   For StartsWith to return true, these are the conditions:
   - Top-level column reference (not a transform or nested column, where null 
counts may be missing).
   - No nulls (CanContainNulls needs to be false).
   - Both lower_bounds and upper_bounds should be present.
   - Both bounds start with the prefix.
   
   NotStartsWith will be handled in a separate follow-up PR to keep changes 
small, however Not(NotStartsWith) gets rewritten as StartsWith, so included a 
test case for this. 
   
   ### **Tests**
   Mostly ported the StartsWith tests from Java's 
TestStrictMetricsEvaluator.cc, plus some cases:
   * missing bound
   * optional columns with and without null counts
   * nested string columns with stats
   * transform terms
   * non-string/null bind rejection, 
   * Not(NotStartsWith(...)) rewrite
   * multibyte UTF-8 strings.
   
   To verify my understanding, also wrote an e2e test in delete_files_test.cc 
(not included in this PR to keep the diff small) using Parquet files with 
truncated bounds, Avro manifests, DeleteFiles::DeleteFromRowFilter, and 
TableScan to verify the full flow, I considered including this test in the 
current PR, but felt like an overkill.


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