Skip to content

Native float ordering diverges from Spark for NaN and signed zero #2517

Description

@ShreyeshArangath

Describe the bug
Native floating-point comparisons and min/max aggregations diverge from Spark SQL semantics for NaN and signed zero (-0.0 vs 0.0).

To Reproduce
Run the following DataFrame queries:

val maxDouble = Seq(Double.NaN, Double.PositiveInfinity, Double.MaxValue)
  .map(Tuple1.apply).toDF("a").selectExpr("max(a)").first()
assert(java.lang.Double.isNaN(maxDouble.getDouble(0)))

val comparison = Seq((0.0, -0.0)).toDF("pos", "neg")
  .select($"pos" > $"neg").first()
assert(comparison.getBoolean(0) == false)

Actual Auron results:

  • Native max(a) returns a non-NaN value (Double.PositiveInfinity) instead of NaN.
  • Native 0.0 > -0.0 evaluates to true.

Reproduced on Spark 3.1 and Spark 3.5.

Expected behavior
Spark SQL floating-point ordering semantics:

  • NaN is equal to NaN and greater than any non-NaN value.
  • -0.0 is equal to 0.0.

max(a) should return NaN when NaN is present, and 0.0 > -0.0 should return false.

Screenshots
N/A

Additional context

  • Affected upstream commit: master at 9f90eacb
  • Upstream source file and line references:
    • spark-extension/src/main/scala/org/apache/spark/sql/auron/NativeConverters.scala:576-581
    • native-engine/datafusion-ext-plans/src/agg/maxmin.rs:110-124, 207-220
  • Distinction from Support NormalizeNaNAndZero #1015 and support normalize nan and zero #1016: those changes added NormalizeNaNAndZero for grouping keys, but direct comparisons and native min/max aggregations still use native float comparisons directly.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions