You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
test("SUM, MIN, MAX, AVG for NaN, -0.0 and 0.0") {
// NaN should be grouped together, and -0.0 and 0.0 should also be grouped together
Seq(true, false).foreach { dictionaryEnabled =>
val data: Seq[(Float, Int)] = Seq(
(Float.NaN, 1),
(-0.0.asInstanceOf[Float], 2),
(0.0.asInstanceOf[Float], 3),
(Float.NaN, 4))
withSQLConf(CometConf.COMET_EXEC_SHUFFLE_ENABLED.key -> "true") {
withParquetTable(data, "tbl", dictionaryEnabled) {
checkSparkAnswer("SELECT SUM(_2), MIN(_2), MAX(_2), _1 FROM tbl GROUP BY _1")
checkSparkAnswer("SELECT MIN(_1), MAX(_1), MIN(_2), MAX(_2) FROM tbl")
checkSparkAnswer("SELECT AVG(_2), _1 FROM tbl GROUP BY _1")
checkSparkAnswer("SELECT AVG(_1), AVG(_2) FROM tbl")
}
}
}
}
scala> spark.sql("select min(a) from (select cast(-0.0 as float) a union all select cast(0.0 as float))").show(false)
+------+
|min(a)|
+------+
|0.0 |
+------+
> select min(a) from (select 0.0::float a union all select -0.0::float);
+--------+
| min(a) |
+--------+
| -0.0 |
+--------+
Activity
comphead commentedon Sep 24, 2025
Thanks @wForget
might be related to apache/datafusion#11051
wForget commentedon Sep 26, 2025
Possibly relevant code:
datafusion-comet/spark/src/main/scala/org/apache/comet/rules/CometExecRule.scala
Lines 600 to 612 in 03c0626
comphead commentedon Sep 26, 2025
made a quick investigation, it fails on MIN if shuffle enabled. Let me check if quick fix available
comphead commentedon Sep 27, 2025
I dont see normalized code is called, checking
but Spark and DF has diff vision on min
wForget commentedon Sep 28, 2025
datafusion-comet/spark/src/main/scala/org/apache/comet/rules/CometExecRule.scala
Lines 575 to 578 in 03c0626
As mentioned in the comment,
SQLOrderingUtil.compareFloatsis used in vanilla Spark to compare float types .We might be able to simply fix this by wrapping
NormalizeNaNAndZeroin themin/maxagg for float types in comet.wForget commentedon Sep 29, 2025
This may not be a solution. Spark only does normalization when sorting, so returning
-0.0or0.0is unstable.comphead commentedon Sep 29, 2025
passed
whereas
failed
I'll check little bit more today