Skip to content

feat(expression): implement NotStartsWith in StrictMetricsEvaluator - #1177

Open
deepaknettem wants to merge 4 commits into
apache:mainfrom
deepaknettem:feat/strict-metrics-not-starts-with
Open

deepaknettem wants to merge 4 commits into
apache:mainfrom
deepaknettem:feat/strict-metrics-not-starts-with

Conversation

@deepaknettem

@deepaknettem deepaknettem commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

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:

  • The column contains nulls only (ContainsNullsOnly).
  • lower_bound is present and lower > prefix and does not start with prefix (all non-null values are past the prefix range).
  • upper_bound is present and upper < prefix (all non-null values are strictly before the prefix range).

Tests

Ported the NotStartsWith tests from Java's TestStrictMetricsEvaluator.java, plus additional cases:

  • prefix bounds (above, below, overlapping, equal to lower/upper, proper prefix of prefix, longer prefix, wider range, writer-truncated upper bound, empty prefix)
  • missing bounds and single bound only (lower-only and upper-only)
  • all-null columns, mixed nulls with range/equal bounds, and optional columns with missing null counts
  • nested string columns (without stats, with stats, all nulls) and transform terms
  • Not(StartsWith(...)) rewrite
  • multibyte UTF-8 strings
  • non-string column, non-string literal, and null literal bind rejection

Comment on lines +507 to +508
auto lower_it = data_file_.lower_bounds.find(id);
if (lower_it != data_file_.lower_bounds.cend()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@WZhuo WZhuo Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()) {

deepaknettem and others added 3 commits November 25, 2026 20:03
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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants