Skip to content

fix: treat -0.0 and 0.0 as equal in short float IN lists - #27122

Open
jonasHanhan wants to merge 1 commit into
apache:mainfrom
jonasHanhan:fix-float-in-signed-zero
Open

jonasHanhan wants to merge 1 commit into
apache:mainfrom
jonasHanhan:fix-float-in-signed-zero

Conversation

@jonasHanhan

Copy link
Copy Markdown

Which issue does this PR close?

Rationale for this change

Since #25187, short Float32/Float64 literal IN lists are no longer rewritten into =/<> chains and stay as membership expressions. The membership filters compare floats by bit pattern, so -0.0 IN (0.0, 5.0) returns false even though -0.0 = 0.0 is true. That's a behavior change from 55.x.

What changes are included in this PR?

ShortenInListSimplifier still keeps short float lists as IN lists, except when one of the literals is 0.0 or -0.0. In that case it falls back to the comparison chain like before, so IN agrees with =. Lists without a zero keep the faster path.

I went with the narrow fix rather than changing the filters to normalize zeros, since the bit-equality behavior there is covered by existing tests and also affects longer lists (the case mentioned at the end of the issue, which already behaves this way in 55). Happy to look at that separately if you'd prefer it handled in the filters.

Are these changes tested?

Yes:

  • New sqllogictest in in_list.slt covering IN / NOT IN with signed zero for DOUBLE and FLOAT columns. It fails on main and passes with this change.
  • Updated simplify_inlist_signed_zero: short float lists containing zero are now inlined, so the test evaluates them instead of expecting them unchanged.
  • cargo test -p datafusion-optimizer passes, clippy and fmt are clean.

Are there any user-facing changes?

No API changes. Short float IN lists containing zero now match -0.0 and 0.0 the same way = does.

Short Float32/Float64 IN lists are kept as membership expressions, which
compare floats by bit pattern, so -0.0 did not match 0.0. Fall back to the
equality chain when the list contains a zero literal.
@github-actions github-actions Bot added optimizer Optimizer rules sqllogictest SQL Logic Tests (.slt) labels Nov 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

optimizer Optimizer rules sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression: short floating-point IN lists mishandle signed zero

1 participant