This is an automated email from the ASF dual-hosted git repository.
ptoth pushed a commit to branch branch-3.5
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/branch-3.5 by this push:
new 52a094e8127f [SPARK-55975][SQL][TESTS] NaN comparison can cause false
UT failures due to different NaNs
52a094e8127f is described below
commit 52a094e8127f2e2e6053413c19f19fcd97ac5130
Author: Marco Gaido <[email protected]>
AuthorDate: Fri Mar 13 09:43:14 2026 +0100
[SPARK-55975][SQL][TESTS] NaN comparison can cause false UT failures due to
different NaNs
### What changes were proposed in this pull request?
In the UTs, currently NaN comparisons can cause UT failures on the CI
(which is also hardware dependent) as on some hardware NaN can be represented
in different byte formats (see IEEE-754 that allows multiple bit patterns for
NaN). This has caused spurious UT failures e.g. in
https://github.com/apache/spark/pull/54676.
### Why are the changes needed?
Fix NaN comparison so that we do not run into hardware-dependent UT
failures and correctly passes when there are two NaNs.
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
Added UT.
### Was this patch authored or co-authored using generative AI tooling?
No.
Closes #54772 from mgaido91/SPARK-55975.
Authored-by: Marco Gaido <[email protected]>
Signed-off-by: Peter Toth <[email protected]>
(cherry picked from commit e7bbd323ec75e0ef96658c588146950131756f1e)
Signed-off-by: Peter Toth <[email protected]>
---
.../src/test/scala/org/apache/spark/sql/MathFunctionsSuite.scala | 9 +++++++++
sql/core/src/test/scala/org/apache/spark/sql/QueryTest.scala | 3 +++
2 files changed, 12 insertions(+)
diff --git
a/sql/core/src/test/scala/org/apache/spark/sql/MathFunctionsSuite.scala
b/sql/core/src/test/scala/org/apache/spark/sql/MathFunctionsSuite.scala
index ba04e3b691a1..6b8c12faa0fb 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/MathFunctionsSuite.scala
+++ b/sql/core/src/test/scala/org/apache/spark/sql/MathFunctionsSuite.scala
@@ -117,6 +117,15 @@ class MathFunctionsSuite extends QueryTest with
SharedSparkSession {
)
}
+ test("different NaN comparison") {
+ assert(QueryTest.compare(
+ java.lang.Double.longBitsToDouble(0x7ff8000000000000L),
+ java.lang.Double.longBitsToDouble(0xfff8000000000000L)))
+ assert(QueryTest.compare(
+ java.lang.Float.intBitsToFloat(0x7fc00000),
+ java.lang.Float.intBitsToFloat(0xffc00000)))
+ }
+
test("sin") {
testOneToOneMathFunction(sin, math.sin)
}
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/QueryTest.scala
b/sql/core/src/test/scala/org/apache/spark/sql/QueryTest.scala
index c2c333a998b4..96a9d749e397 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/QueryTest.scala
+++ b/sql/core/src/test/scala/org/apache/spark/sql/QueryTest.scala
@@ -378,9 +378,12 @@ object QueryTest extends Assertions {
case (a: Row, b: Row) =>
compare(a.toSeq, b.toSeq)
// 0.0 == -0.0, turn float/double to bits before comparison, to
distinguish 0.0 and -0.0.
+ // in some hardware NaN can be represented with different bits, so first
check for it
case (a: Double, b: Double) =>
+ a.isNaN && b.isNaN ||
java.lang.Double.doubleToRawLongBits(a) ==
java.lang.Double.doubleToRawLongBits(b)
case (a: Float, b: Float) =>
+ a.isNaN && b.isNaN ||
java.lang.Float.floatToRawIntBits(a) ==
java.lang.Float.floatToRawIntBits(b)
case (a, b) => a == b
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]