Repository navigation
feat(expression): implement NotStartsWith in StrictMetricsEvaluator - #1177
Open
deepaknettem wants to merge 4 commits into
Open
deepaknettem wants to merge 4 commits into
deepaknettem wants to merge 4 commits into
Conversation
WZhuo
reviewed
Nov 26, 2026
Comment on lines
+507
to
+508
| auto lower_it = data_file_.lower_bounds.find(id); | ||
| if (lower_it != data_file_.lower_bounds.cend()) { |
Contributor
There was a problem hiding this comment.
Suggested change
| auto lower_it = data_file_.lower_bounds.find(id); | |
| if (lower_it != data_file_.lower_bounds.cend()) { | |
| if (auto lower_it = data_file_.lower_bounds.find(id); | |
| lower_it != data_file_.lower_bounds.cend()) { |
| if (lower_it != data_file_.lower_bounds.cend()) { | ||
| ICEBERG_ASSIGN_OR_RAISE(auto lower, ParseBound(expr, lower_it->second)); | ||
| std::string_view lower_str = std::get<std::string>(lower.value()); | ||
| if (lower_str > prefix && !lower_str.starts_with(prefix)) { |
Contributor
There was a problem hiding this comment.
nit: The Java implementation truncates the lower bound to the prefix length and does a single comparison, while here we do > and then starts_with, which may scan the prefix twice. std::string_view::compare(pos, count, str) already clamps count to the string size, so we can get the same result with one call and stay closer to the Java logic:
Suggested change
| if (lower_str > prefix && !lower_str.starts_with(prefix)) { | |
| if (lower_str.compare(0, prefix.size(), prefix) > 0) { |
Comment on lines
+516
to
+517
| auto upper_it = data_file_.upper_bounds.find(id); | ||
| if (upper_it != data_file_.upper_bounds.cend()) { |
Contributor
There was a problem hiding this comment.
Suggested change
| auto upper_it = data_file_.upper_bounds.find(id); | |
| if (upper_it != data_file_.upper_bounds.cend()) { | |
| if (auto upper_it = data_file_.upper_bounds.find(id); | |
| upper_it != data_file_.upper_bounds.cend()) { |
Co-authored-by: wzhuo <wngzhuo@gmail.com>
Co-authored-by: wzhuo <wngzhuo@gmail.com>
Co-authored-by: wzhuo <wngzhuo@gmail.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #1154.
Problem
Support for NotStartsWith 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 and are drawn only from non-null values. Unlike StartsWith, null values satisfy NotStartsWith, so an all-null column matches and partial nulls or missing null_value_counts do not prevent matching when the non-null bounds fall outside the prefix range. Either bound alone is also sufficient if it rules out the prefix range.
Edge case: Writers can truncate the bounds (for example truncate(16)). Even with truncation, lower_bound <= min and max <= upper_bound still hold in UTF-8 byte order, so both bound checks remain safe without false positives.
Fix
Java Reference Implementation: StrictEvalVisitor.java
For NotStartsWith to return true, the column must be a top-level string column reference (not a transform or nested column), and at least one of these must hold:
Tests
Ported the NotStartsWith tests from Java's TestStrictMetricsEvaluator.java, plus additional cases: