Repository navigation
Treat missing null value counts as unknown in the strict metrics evaluator - #4472
Thanatos9404 wants to merge 1 commit into
Conversation
…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.
|
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. |
|
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. |
Rationale for this change
null_value_countsis optional in a data file. When a file has none, Java'sStrictMetricsEvaluatortreats every column as possibly containing nulls:_StrictMetricsEvaluationVisitor._can_contain_nullsread the missing map as empty, so it treated every column as having no nulls. For an optional columnxwith bounds 1 to 5 and no null counts,x < 10,x <= 5,x > 0andx >= 1returnedROWS_MUST_MATCH, although rows wherexis null do not match._DeleteFilesdrops a data file when the strict evaluator returnsROWS_MUST_MATCH, so for such a filedelete("x < 10")also removed the rows wherexis 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_countsintests/expressions/test_evaluator.pychecks 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 oftests/expressionspasses, apart from twotest_parser.pycases and the Cython-decoder warning tests that fail the same way onmainin my environment.ruffandruff formatare clean on the changed files, andmypyreports 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.