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
{{ message }}
Repository navigation
count distinct on NaN produces incorrect results #1238
In #1209 we now fall back to columnar shuffle in some cases where native shuffle is not supported, rather than just falling back to Spark. This caused some test failures in Spark SQL tests such as the following test that now produces incorrect results. This could potentially be a bug in columnar shuffle that we have not seen before.
This is from SPARK-32038: NormalizeFloatingNumbers should work on distinct aggregate.
I can reproduce the issue in main so I am confused how this is currently passing when we run Spark SQL tests. Any idea @kazuyukitanimura or @parthchandra?
Here is my repro:
test("SPARK-32038: NormalizeFloatingNumbers should work on distinct aggregate") {
withSQLConf(CometConf.COMET_ENABLED.key ->"false") {
valnan1= java.lang.Float.intBitsToFloat(0x7f800001)
valnan2= java.lang.Float.intBitsToFloat(0x7fffffff)
valdf=Seq(
("mithunr", Float.NaN),
("mithunr", nan1),
("mithunr", nan2),
("abellina", 1.0f),
("abellina", 2.0f)).toDF("uid", "score")
df.write.mode(SaveMode.Overwrite).parquet("test.parquet")
}
withSQLConf(CometConf.COMET_SHUFFLE_MODE.key ->"auto") {
spark.read.parquet("test.parquet").createOrReplaceTempView("view")
valdf=
spark.sql("select uid, count(distinct score) from view group by 1 order by 1 asc")
checkSparkAnswer /*AndOperator*/ (df)
}
}
Perhaps we can fall back to Spark for count distinct on floating-point columns unless some config is set. We can explain the NaN issue in the compatibility guide.
I think that we will have to explicitly check if both sides of a floating point comparison are NaN to match Spark behavior. By definition NaN is not equal to NaN, so technically Comet is correct.
Falling back to Spark for floating point can be forced by a config value but I don't think we should do that by default.
Since filing this issue we discovered that Comet did not really support distinct aggregates (#1260) so that may at least have been a factor that contributed to this test failing.
Activity
andygrove commentedon Jan 8, 2025
I can reproduce the issue in
mainso I am confused how this is currently passing when we run Spark SQL tests. Any idea @kazuyukitanimura or @parthchandra?Here is my repro:
Produces:
The issue is presumably relateds to normalizing
NaNand differences between Rust and JVM when comparingNaNto otherNaNnumbers.kazuyukitanimura commentedon Jan 9, 2025
Hmm can be an aggregation bug?
[-]Potential bug in columnar shuffle[/-][+]count distinct on NaN produces incorrect results[/+]andygrove commentedon Jan 9, 2025
Here is a better repro:
The test passes for shuffle mode
autoornativeand fails forjvm.andygrove commentedon Jan 9, 2025
Query plan in
automode passes because we fall back to Spark for most of the query:Query plan in
jvmmode:andygrove commentedon Jan 9, 2025
Perhaps we can fall back to Spark for count distinct on floating-point columns unless some config is set. We can explain the NaN issue in the compatibility guide.
parthchandra commentedon Jan 11, 2025
I think that we will have to explicitly check if both sides of a floating point comparison are NaN to match Spark behavior. By definition NaN is not equal to NaN, so technically Comet is correct.
Falling back to Spark for floating point can be forced by a config value but I don't think we should do that by default.
andygrove commentedon Jan 13, 2025
Since filing this issue we discovered that Comet did not really support distinct aggregates (#1260) so that may at least have been a factor that contributed to this test failing.
andygrove commentedon Jun 10, 2025
This was fixed by upgrading to DF 48, which fixed a bug with counting distict NaNs in a grouped aggregate query