Skip to content

fix: keep NaN and -0.0 rows when pushing down float filters - #164

Open
NoahKusaba wants to merge 1 commit into
apache:mainfrom
NoahKusaba:fix/float-predicate-pushdown
Open

NoahKusaba wants to merge 1 commit into
apache:mainfrom
NoahKusaba:fix/float-predicate-pushdown

Conversation

@NoahKusaba

@NoahKusaba NoahKusaba commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Closes #101.

Rationale for this change

DataFusion and Iceberg compare floats differently:

DataFusion Iceberg file skipping
-0.0 vs 0.0 equal -0.0 < 0.0
NaN vs a number NaN is greater no match
-NaN (sign bit set) vs a number -NaN is less no match
NaN vs NaN equal only if the bits are no match
How NaN can match any comparison only IS NAN, which matches every NaN

A filter pushed down unchanged is therefore read by Iceberg's rules, while DataFusion expects its own. Iceberg then skips files holding rows the filter keeps:

  • x > 2.0 skips files whose only matches are NaN.
  • x < 2.0 skips files whose only matches are -NaN.
  • x = 0.0 skips files whose zeros are all -0.0.

The query silently returns fewer rows than the same query on an in-memory table.

Background

Rules -0.0 vs 0.0 NaN Used by
IEEE 754 comparisons (1985) equal unordered, so NaN != NaN hardware
IEEE 754 totalOrder (2008) -0.0 < 0.0 -NaN lowest, NaN highest Arrow kernels, Iceberg's sort order and bounds
PostgreSQL equal NaN = NaN, highest PostgreSQL, Spark

Neither is wrong: Iceberg's rules order stored values, and DataFusion's give SQL results. This PR translates between them.

What changes are included in this PR?

Float comparisons and IN lists are translated into Iceberg's terms so they keep the rows DataFusion's filter keeps:

  1. Compare the values other than NaN. A zero literal becomes a range that holds both -0.0 and 0.0.
  2. Then handle the NaN rows, which Iceberg can only match all together:
    • Every NaN row matches (e.g. !=): add OR x IS NAN.
    • No NaN row matches (e.g. =): add AND x IS NOT NAN.
    • Some match, depending on the NaN's sign (e.g. <, >): add OR x IS NAN, keeping a few extra rows for DataFusion to filter out.
Filter Pushed predicate
x > 2.0 (x > 2) OR (x IS NAN)
x = 0.0 ((x >= -0) AND (x <= 0)) AND (x IS NOT NAN)
x = 'NaN' x IS NAN
x NOT IN (1.5, 2.5) (x NOT IN (1.5, 2.5)) OR (x IS NAN)

NOT around a translation is pushed down only when no NaN rows were kept extra. Filters on other types are unchanged.

Cost: the NaN term still lets a file be skipped when its NaN count is zero, which iceberg-rust's writer records. Files without NaN counts, such as imported Parquet files, are no longer skipped for float comparisons other than =.

Follow-up: apache/datafusion#26091 proposes making every NaN equal and greater than every number, as in PostgreSQL. float_predicate_pushdown.slt checks DataFusion's current NaN rules, so a DataFusion upgrade that changes them fails that test. A TODO on float_comparison says what to update.

Are these tested?

  • Unit snapshot of the pushed predicate for every comparison with a number, a zero, NaN and -NaN, plus -0.0, REAL, a literal on the left, IN, NOT IN and NOT.
  • float_predicate_pushdown.slt: 32 queries over a table with NaN, -NaN, -0.0, 0.0 and NULL in separate files.
    • Expected rows are what DataFusion returns for the same data in memory.
    • 21 of the queries fail on main.
    • One EXPLAIN checks that the NaN term reaches the scan.

Are there any user-facing changes?

  • Float filters return the right rows.
  • EXPLAIN shows the added NaN and zero terms in the pushed predicate.

@NoahKusaba
NoahKusaba force-pushed the fix/float-predicate-pushdown branch from c549d2b to cbda72f Compare December 4, 2026 02:58
DataFusion treats -0.0 as equal to 0.0, and compares NaN by its bits:
NaN is greater than every number and -NaN less. Iceberg's file skipping
orders -0.0 before 0.0 and matches NaN only with IS NAN, which can't tell
NaNs apart. So float comparisons and IN lists pushed down unchanged
skipped files holding rows the filter keeps.

Convert them to compare the values other than NaN, with a zero literal
matching both zeros, then add or exclude the NaN rows. The conversion is
exact when every NaN row matches or none does, and otherwise keeps them
all and is only implied, so NOT isn't pushed through it.

float_predicate_pushdown.slt checks DataFusion's current NaN rules, which
apache/datafusion#26091 may change.

Closes apache#101.
@NoahKusaba
NoahKusaba force-pushed the fix/float-predicate-pushdown branch from cbda72f to 327f65e Compare December 4, 2026 03:11
@NoahKusaba
NoahKusaba marked this pull request as ready for review December 4, 2026 03:19
@NoahKusaba

Copy link
Copy Markdown
Contributor Author

Bit of a boring PR to read through and a bit confusing, but important for the sake of correctness/production-readiness.
cc @Perseus

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.

Filter pushdown on float columns drops rows with NaN or -0.0

1 participant