fix(expr): correct CanContainNulls/CanContainNaNs when field missing from stats map#686
Open
sentomk wants to merge 2 commits into
Open
fix(expr): correct CanContainNulls/CanContainNaNs when field missing from stats map#686sentomk wants to merge 2 commits into
sentomk wants to merge 2 commits into
Conversation
…from stats map When null_value_counts or nan_value_counts is non-empty but does not contain an entry for the queried field, the evaluator incorrectly returned false (cannot contain nulls/NaNs). This caused comparison operators to erroneously return kRowsMustMatch, skipping row-level filtering for rows that may not satisfy the predicate. Fix CanContainNulls to: - Return false for required (non-optional) fields per schema - Return true (conservative) when field is absent from a non-empty map Fix CanContainNaNs to: - Return false for non-floating-point types - Return true (conservative) when field is absent from a non-empty map This aligns with the Java StrictMetricsEvaluator behavior.
There was a problem hiding this comment.
Pull request overview
This PR fixes StrictMetricsEvaluator’s handling of missing per-field entries in null_value_counts / nan_value_counts, making the evaluator conservative (i.e., assume nulls/NaNs may exist) when the stats maps are non-empty but omit the queried field, preventing incorrect kRowsMustMatch results that could skip row-level filtering.
Changes:
- Update
CanContainNullsto returntruewhen a field is absent from a non-emptynull_value_countsmap, andfalsefor required schema fields. - Update
CanContainNaNsto returntruewhen a field is absent from a non-emptynan_value_countsmap, andfalsefor non-floating-point fields. - Add regression tests for missing-entry scenarios (with one test needing adjustment to actually exercise the bug condition).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/iceberg/expression/strict_metrics_evaluator.cc |
Makes null/NaN containment checks conservative when stats maps omit a field, and adds required/non-floating fast paths. |
src/iceberg/test/strict_metrics_evaluator_test.cc |
Adds regression coverage for missing null/NaN count entries (one test currently doesn’t set bounds, so it won’t regress the original issue). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+849
to
+861
| TEST_F(StrictMetricsEvaluatorMigratedTest, MissingNullCountForField) { | ||
| // Field 14 (no_nan_stats, float64, optional) has bounds and value_counts but is | ||
| // missing from null_value_counts. The evaluator must conservatively assume nulls | ||
| // may exist and return kRowsMightNotMatch for comparison operators. | ||
| ExpectShouldRead(Expressions::LessThan("no_nan_stats", Literal::Double(200.0)), false); | ||
| ExpectShouldRead(Expressions::LessThanOrEqual("no_nan_stats", Literal::Double(200.0)), | ||
| false); | ||
| ExpectShouldRead(Expressions::GreaterThan("no_nan_stats", Literal::Double(-1.0)), | ||
| false); | ||
| ExpectShouldRead(Expressions::GreaterThanOrEqual("no_nan_stats", Literal::Double(-1.0)), | ||
| false); | ||
| ExpectShouldRead(Expressions::Equal("no_nan_stats", Literal::Double(50.0)), false); | ||
| } |
f20015a to
e7344ea
Compare
Cover the scenario where a field is absent from null_value_counts or nan_value_counts while the map is non-empty. Verify that comparison operators conservatively return kRowsMightNotMatch instead of incorrectly claiming kRowsMustMatch.
e7344ea to
68c68b3
Compare
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.
Summary
StrictMetricsEvaluator::CanContainNullsto returntrue(conservative) when a field is absent from a non-emptynull_value_countsmap, andfalsefor required fields per schemaStrictMetricsEvaluator::CanContainNaNsto returntrue(conservative) when a field is absent from a non-emptynan_value_countsmap, andfalsefor non-floating-point typesClose #685
Motivation
When
null_value_countsornan_value_countsis non-empty but does not contain an entry for the queried field, the evaluator incorrectly returnedfalse. This caused comparison operators to erroneously returnkRowsMustMatch, potentially skipping row-level filtering and returning rows that do not satisfy the predicate.Test plan