Skip to content

Commit 87a334c

Browse files
andygroveclaude
andcommitted
fix: add tiebreaker columns to window fallback tests for deterministic results
Window function tests with ROWS BETWEEN frames were failing due to non-deterministic sort order when using ORDER BY with non-unique values. When CometSort encounters rows with identical sort keys, the relative order of those rows is undefined, causing window function results to vary between Spark and Comet executions. Updated all window fallback tests to include column 'c' (which contains unique values) as a tiebreaker in ORDER BY clauses, ensuring deterministic ordering and consistent test results. Tests updated: - ROWS BETWEEN tests (COUNT, SUM, AVG, MAX) - ORDER BY DESC test - Multiple PARTITION BY/ORDER BY columns tests - RANGE BETWEEN tests Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
1 parent 11b615d commit 87a334c

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

spark/src/test/scala/org/apache/comet/exec/CometWindowExecSuite.scala

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ class CometWindowExecSuite extends CometTestBase {
423423
checkSparkAnswerAndFallbackReason(
424424
"""
425425
SELECT a, b, c,
426-
COUNT(*) OVER (PARTITION BY a ORDER BY b ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) as cnt
426+
COUNT(*) OVER (PARTITION BY a ORDER BY b, c ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) as cnt
427427
FROM window_test
428428
""",
429429
"Partition expressions must be a subset of order expressions for native window")
@@ -445,7 +445,7 @@ class CometWindowExecSuite extends CometTestBase {
445445
checkSparkAnswerAndFallbackReason(
446446
"""
447447
SELECT a, b, c,
448-
SUM(c) OVER (PARTITION BY a ORDER BY b ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING) as sum_c
448+
SUM(c) OVER (PARTITION BY a ORDER BY b, c ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING) as sum_c
449449
FROM window_test
450450
""",
451451
"Partition expressions must be a subset of order expressions for native window")
@@ -467,7 +467,7 @@ class CometWindowExecSuite extends CometTestBase {
467467
checkSparkAnswerAndFallbackReason(
468468
"""
469469
SELECT a, b, c,
470-
AVG(c) OVER (PARTITION BY a ORDER BY b ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) as avg_c
470+
AVG(c) OVER (PARTITION BY a ORDER BY b, c ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) as avg_c
471471
FROM window_test
472472
""",
473473
"Partition expressions must be a subset of order expressions for native window")
@@ -489,7 +489,7 @@ class CometWindowExecSuite extends CometTestBase {
489489
checkSparkAnswerAndFallbackReason(
490490
"""
491491
SELECT a, b, c,
492-
SUM(c) OVER (PARTITION BY a ORDER BY b ROWS BETWEEN 2 PRECEDING AND CURRENT ROW) as sum_c
492+
SUM(c) OVER (PARTITION BY a ORDER BY b, c ROWS BETWEEN 2 PRECEDING AND CURRENT ROW) as sum_c
493493
FROM window_test
494494
""",
495495
"Partition expressions must be a subset of order expressions for native window")
@@ -511,7 +511,7 @@ class CometWindowExecSuite extends CometTestBase {
511511
checkSparkAnswerAndFallbackReason(
512512
"""
513513
SELECT a, b, c,
514-
COUNT(*) OVER (PARTITION BY a ORDER BY b ROWS BETWEEN CURRENT ROW AND 2 FOLLOWING) as cnt
514+
COUNT(*) OVER (PARTITION BY a ORDER BY b, c ROWS BETWEEN CURRENT ROW AND 2 FOLLOWING) as cnt
515515
FROM window_test
516516
""",
517517
"Partition expressions must be a subset of order expressions for native window")
@@ -533,7 +533,7 @@ class CometWindowExecSuite extends CometTestBase {
533533
checkSparkAnswerAndFallbackReason(
534534
"""
535535
SELECT a, b, c,
536-
MAX(c) OVER (PARTITION BY a ORDER BY b ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) as max_c
536+
MAX(c) OVER (PARTITION BY a ORDER BY b, c ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) as max_c
537537
FROM window_test
538538
""",
539539
"Partition expressions must be a subset of order expressions for native window")
@@ -882,7 +882,7 @@ class CometWindowExecSuite extends CometTestBase {
882882
checkSparkAnswerAndFallbackReason(
883883
"""
884884
SELECT a, b, c,
885-
SUM(c) OVER (PARTITION BY a ORDER BY b DESC) as sum_c_desc
885+
SUM(c) OVER (PARTITION BY a ORDER BY b DESC, c DESC) as sum_c_desc
886886
FROM window_test
887887
""",
888888
"Partition expressions must be a subset of order expressions for native window")
@@ -904,7 +904,7 @@ class CometWindowExecSuite extends CometTestBase {
904904
checkSparkAnswerAndFallbackReason(
905905
"""
906906
SELECT a, b, d, c,
907-
SUM(c) OVER (PARTITION BY a, b ORDER BY d) as sum_c
907+
SUM(c) OVER (PARTITION BY a, b ORDER BY d, c) as sum_c
908908
FROM window_test
909909
""",
910910
"Partition expressions must be a subset of order expressions for native window")
@@ -948,7 +948,7 @@ class CometWindowExecSuite extends CometTestBase {
948948
checkSparkAnswerAndFallbackReason(
949949
"""
950950
SELECT a, b, c,
951-
SUM(c) OVER (PARTITION BY a ORDER BY b RANGE BETWEEN 2 PRECEDING AND 2 FOLLOWING) as sum_c
951+
SUM(c) OVER (PARTITION BY a ORDER BY b, c RANGE BETWEEN 2 PRECEDING AND 2 FOLLOWING) as sum_c
952952
FROM window_test
953953
""",
954954
"Partition expressions must be a subset of order expressions for native window")
@@ -970,7 +970,7 @@ class CometWindowExecSuite extends CometTestBase {
970970
checkSparkAnswerAndFallbackReason(
971971
"""
972972
SELECT a, b, c,
973-
SUM(c) OVER (PARTITION BY a ORDER BY b RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) as sum_c
973+
SUM(c) OVER (PARTITION BY a ORDER BY b, c RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) as sum_c
974974
FROM window_test
975975
""",
976976
"Partition expressions must be a subset of order expressions for native window")

0 commit comments

Comments
 (0)