Skip to content

fix(expr): treat NaN row group bounds as might-match for inequalities - #3502

Merged
laskoviymishka merged 3 commits into
apache:mainfrom
ump45nose:fix/3494-nan-min-inequality
Oct 23, 2026
Merged

laskoviymishka merged 3 commits into
apache:mainfrom
ump45nose:fix/3494-nan-min-inequality

Conversation

@ump45nose

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

What changes are included in this PR?

RowGroupMetricsEvaluator::visit_inequality only checked the literal for NaN. When a row group's min statistic was NaN (parquet-mr 1.9 and earlier record a NaN that starts a row group as both min and max), f < 5.0 and f <= 5.0 pruned the row group even though it could hold smaller values.

This makes visit_inequality return might-match when the bound it compares against is NaN, the same way eq and in in this evaluator already treat a NaN bound as unreliable.

Are these changes tested?

Yes. Four new tests in row_group_metrics_evaluator.rs evaluate <, <=, > and >= against a row group whose min and max are both NaN. The < and <= tests fail on main (219571a) and pass with the fix; the >/>= ones already pass (a NaN max compares greater than the literal) and are there to pin the behaviour for both bounds. cargo test -p iceberg --lib expr::visitors and cargo clippy -p iceberg --all-targets -- -D warnings pass locally.

AI Disclosure

I used an AI assistant to help write the fix and tests, then reviewed the change and ran the tests myself.

@JeonDaehong JeonDaehong 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.

Checked this locally. The is_nan() check covers both ends: with sign-bit NaN bounds (0xffc0_0000), main also prunes > and >= (see inline), so the fix matters there too, not only for < / <=.

PageIndexEvaluator::visit_inequality (page_index_evaluator.rs:575) has the same shape. It checks only the literal for NaN before comparing the page min/max. I haven't built a page index with NaN bounds to confirm it, so this is from reading the code, but it might be worth the same guard or a follow-up.

}

#[test]
fn eval_true_for_nan_upper_bound_greater_than() -> Result<()> {

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.

These pass on main too, since a positive NaN max is above 5.0 under total_cmp. A NaN with the sign bit set sorts below -Inf instead. With min = max = f32::from_bits(0xffc0_0000), main prunes the row group for f > 5.0 and f >= 5.0, and this PR keeps it. I checked by dropping the new is_nan() block. Running these two tests (or all four) with that bound as well would pin the upper-bound half of the fix.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for checking. In 93ebac6 all four tests now run with both f32::NAN and f32::from_bits(0xffc0_0000) as min/max. Without the is_nan() block all four fail, so the > / >= half is pinned too. I will look at PageIndexEvaluator::visit_inequality separately rather than widen this PR. (AI-assisted reply.)

@laskoviymishka laskoviymishka 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.

Thanks for the quick follow-up. Running each test with both NaN signs means the >/>= half of the check now has a test that fails on main too. The fix looks right to me: it checks the one bound each operator reads, the same way eq and in already do. I left one small optional test ask inline.

@anoopj or @blackmwk, could one of you also take a look at the evaluator change when you get a chance?

1,
1,
Some(Statistics::float(
Some(nan),

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.

Could the helper take min and max separately, so we can add a < case with a NaN min and a finite max, e.g. (f32::NAN, 2.0)? It's the same branch, since </<= only read the min. But it pins that a finite max doesn't change the result, the way eval_true_for_meta_lower_nan_filter_eq does for eq.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in a133ee8. The helper now takes min and max separately, and eval_true_for_nan_lower_bound_finite_upper_bound_less_than checks < and <= with (NaN, 2.0) for both NaN signs. It fails without the is_nan() check. (AI-assisted reply.)

@laskoviymishka

Copy link
Copy Markdown
Contributor

This is good to merge to me, thanks 🌬️ ⛵

@laskoviymishka
laskoviymishka added this pull request to the merge queue Oct 23, 2026
Merged via the queue into apache:main with commit aa9986f Oct 23, 2026
24 checks passed
@laskoviymishka

Copy link
Copy Markdown
Contributor

@ump45nose welcome to contributors team!

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.

Row-group pruning skips < and <= matches when the min statistic is NaN

3 participants