You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by pt...@apache.org on 2026/03/13 08:43:50 UTC
(spark) branch master updated: [SPARK-55975][SQL][TESTS] NaN comparison can cause false UT failures due to different NaNs
This is an automated email from the ASF dual-hosted git repository.
ptoth pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/master by this push:
new e7bbd323ec75 [SPARK-55975][SQL][TESTS] NaN comparison can cause false UT failures due to different NaNs
e7bbd323ec75 is described below
commit e7bbd323ec75e0ef96658c588146950131756f1e
Author: Marco Gaido <mg...@fbk.eu>
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 <mg...@fbk.eu>
Signed-off-by: Peter Toth <pe...@gmail.com>
---
.../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 23d3fc3d2fe5..42f15a04fd58 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 ae1b4abe31a3..ac406a9fa694 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
@@ -407,9 +407,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: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org