Skip to content

fix(expression): handle -NaN upper bounds in inclusive and strict metrics evaluator - #1186

Open
deepaknettem wants to merge 1 commit into
apache:mainfrom
deepaknettem:fix/metrics-evaluator-nan-upper-bound
Open

deepaknettem wants to merge 1 commit into
apache:mainfrom
deepaknettem:fix/metrics-evaluator-nan-upper-bound

Conversation

@deepaknettem

Copy link
Copy Markdown
Contributor

Problem

Writers like ORC can record NaN for both lower and upper bounds when the first value in a float/double column is NaN, even if finite values are present later in the file. When that value is -NaN (for example, 0.0 / 0.0 on x86-64), pruning is incorrect.

I added unit tests setting upper_bounds to -NaN to confirm my suspicion and saw them fail.

Java implementation checks isNaN(lower) only because Float.compare / Double.compare collapses -NaN to +NaN at the time of comparison, so it doesn't need to handle this case.

I saw the PyIceberg implementation, and it is also doing an explicit check on upper_bounds with a comment to that effect (visitors.py#L1415-L1417).

In existing implementation, -NaN upper bound causes both upper < lit and upper <= lit evaluate true, so without an explicit check for -NaN,

  • InclusiveMetricsEvaluator: Gt, GtEq, Eq, and In return false, skipping files that may match.
  • StrictMetricsEvaluator: Lt, LtEq, NotEq, and NotIn return true, and could be dropping files.

References:

Fix

  • Check upper->IsNaN() in InclusiveMetricsEvaluator (Gt, GtEq, Eq, In) and return kRowsMightMatch.
  • Check upper.IsNaN() in StrictMetricsEvaluator (Lt, LtEq, NotEq, NotIn) and return kRowsMightNotMatch.

Tests

  • Added basic unit tests.

if (upper_it != data_file_.upper_bounds.cend()) {
ICEBERG_ASSIGN_OR_RAISE(auto upper, ParseBound(expr, upper_it->second));
if (upper.IsNaN()) {
return kRowsMightNotMatch;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Strict NOT IN discards a usable lower bound. With lower = 10, x NOT IN (1, 2) must match every row, correct me if I'm wrong :-)

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