Skip to content

Treat missing null value counts as unknown in the strict metrics evaluator - #4472

Open
Thanatos9404 wants to merge 1 commit into
apache:mainfrom
Thanatos9404:strict-missing-null-counts
Open

Thanatos9404 wants to merge 1 commit into
apache:mainfrom
Thanatos9404:strict-missing-null-counts

Conversation

@Thanatos9404

Copy link
Copy Markdown

Rationale for this change

null_value_counts is optional in a data file. When a file has none, Java's StrictMetricsEvaluator treats every column as possibly containing nulls:

private boolean canContainNulls(Integer id) {
  return nullCounts == null || (nullCounts.containsKey(id) && nullCounts.get(id) > 0);
}

_StrictMetricsEvaluationVisitor._can_contain_nulls read the missing map as empty, so it treated every column as having no nulls. For an optional column x with bounds 1 to 5 and no null counts, x < 10, x <= 5, x > 0 and x >= 1 returned ROWS_MUST_MATCH, although rows where x is null do not match.

_DeleteFiles drops a data file when the strict evaluator returns ROWS_MUST_MATCH, so for such a file delete("x < 10") also removed the rows where x is null.

Now the visitor treats every column as possibly containing nulls when the file has no null value counts, as Java does. A file whose map exists but has no entry for a column is unchanged, which also matches Java.

Are these changes tested?

Yes. test_strict_missing_null_counts in tests/expressions/test_evaluator.py checks the four predicates on the same file with null counts {1: 0} (must match) and without null counts (might not match). It fails without the change. The rest of tests/expressions passes, apart from two test_parser.py cases and the Cython-decoder warning tests that fail the same way on main in my environment. ruff and ruff format are clean on the changed files, and mypy reports nothing new.

Are there any user-facing changes?

Deletes no longer drop a whole data file without null value counts when the predicate cannot match its null rows. Such a file is now read and rewritten, so only the matching rows are removed.

…uator

Java's StrictMetricsEvaluator treats a data file without null value
counts as possibly containing nulls. PyIceberg treated it as having none,
so a delete could drop the whole file, including null rows that do not
match the predicate.
Copilot AI balanced review requested due to automatic review settings November 23, 2026 03:14

Copilot AI left a comment

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@korsakowii

Copy link
Copy Markdown

I tested the partial-map case mentioned in the PR description through Table.add_files on 45b1749.

With the NULL count for x omitted but its bounds retained, deleting x = 5 or x < 10 dropped the entire file, including two NULL rows. I also reproduced this after a required-to-optional schema evolution.

A local follow-up treating missing per-field counts as unknown preserves the NULL rows while retaining the strict-match optimization when a zero count is recorded.

This also seems related to apache/iceberg#17648. Would a separate PyIceberg follow-up PR be welcome? I have a small reproducer and regression tests ready.

@Fokko

Fokko commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

First of all, thanks for working on this @Thanatos9404 🙌 And thanks @korsakowii for referencing apache/iceberg#17648, maybe we should first follow up on that one before driving this issue. I think one big change there is that we assume that only optional columns can contain nulls. Which make sense, but there are some edge cases, for example, a required column, inside of a nested column might be null. Therefore let's get consensus on Java first, so then PyIceberg can follow.

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.

4 participants