comphead commented on code in PR #7194:
URL: https://github.com/apache/datafusion-comet/pull/7194#discussion_r4669998226


##########
spark/src/test/resources/sql-tests/expressions/aggregate/regr.sql:
##########
@@ -174,6 +174,57 @@ SELECT regr_slope(y, x), regr_intercept(y, x), regr_r2(y, 
x) FROM test_regr_cons
 query
 SELECT regr_sxx(y, x), regr_syy(y, x), regr_sxy(y, x) FROM test_regr_const_y
 
+-- Nullable aggregate FILTERs must preserve group positions and combine with
+-- each function's pair-null rules. Group 1 exists but has no qualifying rows;
+-- group 2 has x values whose y is NULL, which slope/intercept counted before 
SPARK-48719.
+statement
+CREATE TABLE test_regr_filtered(g int, y double, x double, keep boolean) USING 
parquet
+
+statement
+INSERT INTO test_regr_filtered VALUES
+  (0, 3.0, 1.0, true), (0, 9.0, 4.0, true), (0, 8.0, NULL, true),
+  (0, NULL, 20.0, true), (0, 90.0, 8.0, false), (0, 70.0, 9.0, NULL),
+  (1, 2.0, 5.0, false), (1, 8.0, 9.0, NULL),
+  (2, NULL, 1.0, true), (2, NULL, 4.0, true),
+  (3, 7.0, 1.0, true), (3, 7.0, 4.0, true)
+
+query
+SELECT g,
+  regr_sxx(y, x) FILTER (WHERE keep), regr_syy(y, x) FILTER (WHERE keep),
+  regr_sxy(y, x) FILTER (WHERE keep), regr_slope(y, x) FILTER (WHERE keep),
+  regr_intercept(y, x) FILTER (WHERE keep), regr_r2(y, x) FILTER (WHERE keep)
+FROM test_regr_filtered GROUP BY g ORDER BY g
+
+query
+SELECT g,
+  regr_sxx(x, y) FILTER (WHERE keep), regr_syy(x, y) FILTER (WHERE keep),
+  regr_sxy(x, y) FILTER (WHERE keep), regr_slope(x, y) FILTER (WHERE keep),
+  regr_intercept(x, y) FILTER (WHERE keep), regr_r2(x, y) FILTER (WHERE keep)
+FROM test_regr_filtered GROUP BY g ORDER BY g
+
+-- NaN, infinities and -0.0 through the grouped path, in y (groups 0, 2, 4) 
and in
+-- x (groups 1, 3, 5). Group 6 has a NaN and an infinity only in rows the 
FILTER drops.
+statement
+CREATE TABLE test_regr_special(g int, y double, x double, keep boolean) USING 
parquet
+
+statement
+INSERT INTO test_regr_special VALUES
+  (0, cast('NaN' as double), 1.0, true), (0, 2.0, 2.0, true), (0, 4.0, 3.0, 
true),
+  (1, 1.0, cast('NaN' as double), true), (1, 2.0, 2.0, true), (1, 4.0, 3.0, 
true),
+  (2, cast('Infinity' as double), 1.0, true), (2, 2.0, 2.0, true), (2, 4.0, 
3.0, true),
+  (3, 1.0, cast('-Infinity' as double), true), (3, 2.0, 2.0, true), (3, 4.0, 
3.0, true),
+  (4, -0.0D, 1.0, true), (4, -0.0D, 2.0, true), (4, -0.0D, 3.0, true),
+  (5, 1.0, -0.0D, true), (5, 2.0, -0.0D, true), (5, 4.0, -0.0D, true),
+  (6, 1.0, 1.0, true), (6, 2.0, 2.0, true), (6, 4.0, 3.0, true),
+  (6, cast('NaN' as double), 4.0, false), (6, 5.0, cast('Infinity' as double), 
NULL)

Review Comment:
   None of the grouped queries has a group with exactly one non-null pair. The 
ungrouped `test_regr_single` covers that case, but the grouped path takes 
`count == 1` through its own `finish` implementations, where `regr_slope`, 
`regr_intercept` and `regr_r2` should be NULL and the three moments should be 
`0.0`. The Rust tests compare this against the scalar accumulator only. Adding 
one more group to this table, for example `(7, 3.0, 5.0, true), (7, NULL, 2.0, 
true)`, would check it against Spark without a new table.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to