Repository navigation
fix: keep NaN and -0.0 rows when pushing down float filters - #164
Open
NoahKusaba wants to merge 1 commit into
Open
NoahKusaba wants to merge 1 commit into
NoahKusaba wants to merge 1 commit into
Conversation
NoahKusaba
force-pushed
the
fix/float-predicate-pushdown
branch
from
December 4, 2026 02:58
c549d2b to
cbda72f
Compare
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
force-pushed
the
fix/float-predicate-pushdown
branch
from
December 4, 2026 03:11
cbda72f to
327f65e
Compare
NoahKusaba
marked this pull request as ready for review
December 4, 2026 03:19
Contributor
Author
|
Bit of a boring PR to read through and a bit confusing, but important for the sake of correctness/production-readiness. |
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.
Which issue does this PR close?
Closes #101.
Rationale for this change
DataFusion and Iceberg compare floats differently:
-0.0vs0.0-0.0<0.0IS NAN, which matches every NaNA 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.0skips files whose only matches are NaN.x < 2.0skips files whose only matches are -NaN.x = 0.0skips files whose zeros are all-0.0.The query silently returns fewer rows than the same query on an in-memory table.
Background
-0.0vs0.0NaN != NaNtotalOrder(2008)-0.0<0.0-NaNlowest,NaNhighestNaN = NaN, highesttotalOrderand PostgreSQL's rules are the two common fixes.totalOrderand keeps NaN out of queries. Bounds exclude NaN, and Iceberg's Java API rejects NaN literals in favour ofisNaN/notNaN.totalOrderand is moving to PostgreSQL's rules:-0.0 = 0.0.-0.0(and NaN) float keys in one place instead of per call site datafusion#26138 extends that to sorting.-NaN = NaN) datafusion#26091 (open) would make-NaN = NaN.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
INlists are translated into Iceberg's terms so they keep the rows DataFusion's filter keeps:-0.0and0.0.!=): addOR x IS NAN.=): addAND x IS NOT NAN.<,>): addOR x IS NAN, keeping a few extra rows for DataFusion to filter out.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 NANx NOT IN (1.5, 2.5)(x NOT IN (1.5, 2.5)) OR (x IS NAN)NOTaround 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.sltchecks DataFusion's current NaN rules, so a DataFusion upgrade that changes them fails that test. A TODO onfloat_comparisonsays what to update.Are these tested?
-0.0,REAL, a literal on the left,IN,NOT INandNOT.float_predicate_pushdown.slt: 32 queries over a table with NaN, -NaN,-0.0,0.0andNULLin separate files.main.EXPLAINchecks that the NaN term reaches the scan.Are there any user-facing changes?
EXPLAINshows the added NaN and zero terms in the pushed predicate.