Spec: Float sort order puts `-NaN` first but says it matches Java

Aperta
#19,040 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@mbutrovich ci sta già lavorando.

Dal 20/11/2026.

  • #19069 di @mbutrovich — aperta

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
52/100
Tipo di issue
Documentazione
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
java
Ambito
documentation

Direzione di ricerca

Start with the floating-point sorting rule in format/spec.md and compare it with Java's Double.compareTo behavior described in the issue. Review the discussion and proposal in issue #2891 for prior concerns. Done means the spec clearly states that all NaN representations compare equal and sort after Infinity, while stored NaN bits remain unchanged.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug
Apache Iceberg version

main (development)

Query engine

None

Please describe the bug 🐞

The sorting rule orders floats as -NaN < -Infinity < -value < -0 < 0 < value < Infinity < NaN and says this "aligns with the implementation of Java floating-point types comparisons." Java's Double.compareTo treats every NaN as equal and greater than +Infinity, so Java has no -NaN at the low end. The listed order is IEEE 754 totalOrder.

Implementations follow different halves of the sentence. Iceberg Java compares floats with Comparator.naturalOrder(), which is Double.compareTo. iceberg-rust uses total_cmp, which puts negative NaNs first and orders NaNs by payload.

Following totalOrder also makes a computed NaN's position depend on hardware. IEEE 754 doesn't specify the sign of a NaN result. For 0.0 / 0.0, x86 SSE returns 0xfff8000000000000 and AArch64 returns 0x7ff8000000000000, so the same expression sorts first on one writer and last on another. This matters most where position must be exact, such as the ordering keys in the secondary index spec (#16961), which cites this rule.

#2891 proposed removing -NaN and grouping all NaNs after Infinity. @RussellSpitzer supported it, but it was closed without a decision. The concern there was that requiring writers to canonicalize NaN is extra work and discards legitimate NaN bit patterns. #2891 also let NaN representations sort in an arbitrary order, which would leave different NaN bit patterns as distinct keys.

Could the rule say that all NaN representations compare equal and sort after Infinity? This matches Java and the sentence that already claims it does. It constrains only comparison, so stored values keep their bits and writers don't canonicalize.

Willingness to contribute
  • I can contribute a fix for this bug independently
  • I would be willing to contribute a fix for this bug with guidance from the Iceberg community
  • I cannot contribute a fix for this bug at this time
Lingua principale
Java
Stelle
9.4k
Fork
3.7k
Merge medio
2g 16h
PR unite (30g)
160

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di apache/iceberg

Tutte le issue di apache/iceberg

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.