AdamGS commented on code in PR #26584:
URL: https://github.com/apache/datafusion/pull/26584#discussion_r4399579100


##########
datafusion/sqllogictest/test_files/limit.slt:
##########
@@ -1312,3 +1312,63 @@ SET datafusion.optimizer.max_passes = 3;
 
 statement ok
 DROP TABLE t23534;
+
+# The sort below an OFFSET decides which rows are skipped, so it must be
+# kept even when an order-insensitive aggregate consumes the result and the
+# sort columns are projected away.
+# https://github.com/apache/datafusion/issues/26488
+statement ok
+CREATE TABLE t26488(id BIGINT, g BIGINT, v BIGINT, s VARCHAR) AS VALUES
+  (0, 0,  3, '中文'),
+  (1, 0,  0, 'a'),
+  (2, 1, -1, 'a'),
+  (3, 1, -1, 'a'),
+  (4, 0,  3, '中文'),
+  (5, 0,  3, NULL);
+
+# OFFSET 1 skips the first row in (s, id) order: id = 1 (g = 0, v = 0)
+query II
+SELECT g, SUM(v) AS sv
+FROM (
+  SELECT * FROM t26488 ORDER BY s ASC NULLS LAST, id ASC NULLS LAST OFFSET 1
+) q
+GROUP BY g
+ORDER BY g;
+----
+0 9
+1 -2
+
+query I
+SELECT SUM(v)
+FROM (SELECT * FROM t26488 ORDER BY s, id OFFSET 1) q;
+----
+7

Review Comment:
   playing around with this test on `55.2.0`, I noticed that with the subquery 
alias this query return 4, but without the alias it correctly return 7.



-- 
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