Skip to content

Commit eb5c7af

Browse files
committed
test: avoid scan-order assumptions in float min/max checks
1 parent b15afcf commit eb5c7af

2 files changed

Lines changed: 20 additions & 10 deletions

File tree

‎spark/src/test/resources/sql-tests/expressions/aggregate/min_max_floating_point.sql‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,26 @@ INSERT INTO mm_float VALUES
4545
(12, 8, double('Infinity'), float('Infinity')),
4646
(13, 8, double('NaN'), float('NaN'))
4747

48-
-- Without grouping
48+
-- Without grouping. The extrema are NaN and infinities, so scan/merge order cannot change them.
4949
query
5050
SELECT max(d), min(d), max(-d), min(-d), max(f), min(f), max(-f), min(-f) FROM mm_float
5151

52-
-- Of equal values the first one seen wins
52+
-- Signed-zero ties need an explicit input order, not just an ORDER BY on the aggregate result.
53+
-- Use windows for groups 2 and 3: neither file layout nor partial-aggregate merge order is fixed.
54+
-- The native accumulator tests check first-value preservation by bits for ordinary and grouped
55+
-- aggregates, including partial-state merges.
5356
query
54-
SELECT max(d), min(d), max(-d), min(-d), max(f), min(f) FROM mm_float WHERE g IN (2, 3)
57+
SELECT id, g,
58+
max(d) OVER w, min(d) OVER w, max(-d) OVER w, min(-d) OVER w,
59+
max(f) OVER w, min(f) OVER w, max(-f) OVER w, min(-f) OVER w
60+
FROM mm_float WHERE g IN (2, 3)
61+
WINDOW w AS (PARTITION BY g ORDER BY id ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING)
5562

56-
-- Grouped. Groups 4 and 5 hold only an infinity, group 6 only NaN and group 7 only NULL.
63+
-- Grouped, excluding the order-sensitive signed-zero groups. Groups 4 and 5 hold only an
64+
-- infinity, group 6 only NaN and group 7 only NULL.
5765
query
5866
SELECT g, max(d), min(d), max(-d), min(-d), max(f), min(f), max(-f), min(-f)
59-
FROM mm_float GROUP BY g ORDER BY g
67+
FROM mm_float WHERE g NOT IN (2, 3) GROUP BY g ORDER BY g
6068

6169
-- Window frames: growing, sliding and the whole partition. Each frame is ordered by id, so the
6270
-- first of two equal values is well defined. The sliding frames use FOLLOWING offsets because the

‎spark/src/test/scala/org/apache/comet/exec/CometAggregateSuite.scala‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -286,10 +286,8 @@ class CometAggregateSuite extends CometTestBase with AdaptiveSparkPlanHelper {
286286
1000,
287287
DataGenOptions(generateNegativeZero = true))
288288
withTempDir { dir =>
289-
// Spark returns the first of equal values, so both engines have to read the rows in the
290-
// same order: write a single file.
291289
val path = new Path(dir.toString, "tbl").toString
292-
df.repartition(1).write.parquet(path)
290+
df.write.parquet(path)
293291
spark.read.parquet(path).createOrReplaceTempView("tbl")
294292

295293
for (col <- Seq("float_col", "double_col")) {
@@ -299,8 +297,12 @@ class CometAggregateSuite extends CometTestBase with AdaptiveSparkPlanHelper {
299297
for (agg <- Seq("min", "max")) {
300298
// min and max follow Spark's float ordering natively, so strict mode keeps them native.
301299
withSQLConf(COMET_EXEC_STRICT_FLOATING_POINT.key -> "true") {
302-
checkSparkAnswerAndOperator(
303-
s"select $agg($col) from tbl where cast($col as string) in ('0.0', '-0.0')")
300+
// Test each sign separately: mixed signed-zero ties depend on scan/merge order.
301+
// Ordered windows and native accumulator bit tests cover first-value preservation.
302+
for (zero <- Seq("0.0", "-0.0")) {
303+
checkSparkAnswerAndOperator(
304+
s"select $agg($col) from tbl where cast($col as string) = '$zero'")
305+
}
304306
}
305307
checkSparkAnswer(
306308
s"select $col, count(*) from tbl " +

0 commit comments

Comments
 (0)