gruuya commented on code in PR #7981:
URL: https://github.com/apache/arrow-datafusion/pull/7981#discussion_r1381591595


##########
datafusion/sqllogictest/test_files/distinct_on.slt:
##########
@@ -0,0 +1,129 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+
+#   http://www.apache.org/licenses/LICENSE-2.0
+
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+statement ok
+CREATE EXTERNAL TABLE aggregate_test_100 (
+  c1  VARCHAR NOT NULL,
+  c2  TINYINT NOT NULL,
+  c3  SMALLINT NOT NULL,
+  c4  SMALLINT,
+  c5  INT,
+  c6  BIGINT NOT NULL,
+  c7  SMALLINT NOT NULL,
+  c8  INT NOT NULL,
+  c9  BIGINT UNSIGNED NOT NULL,
+  c10 VARCHAR NOT NULL,
+  c11 FLOAT NOT NULL,
+  c12 DOUBLE NOT NULL,
+  c13 VARCHAR NOT NULL
+)
+STORED AS CSV
+WITH HEADER ROW
+LOCATION '../../testing/data/csv/aggregate_test_100.csv'
+
+# Basic example: distinct on the first column project the second one, and
+# order by the third
+# TODO: Note that the value for 'a' is actually degenerate, and while Postgres
+# returns the actual first match (4), DataFusion returns the last one, 
presumably
+# because `first_value` aggregation function doesn't have a dedicated 
`GroupsAccumulator`

Review Comment:
   Oh I see what this is, it's another case of unstable sort, i.e. the sorted 
rows that have equal ordering expressions evaluations do not preserve the 
original order of those rows (but they're stable in the sense that output is 
always the same):
   ```sql
   ❯ select c1, c2, c3 from test order by c1, c3;
   +----+----+------+
   | c1 | c2 | c3   |
   +----+----+------+
   | a  | 5  | -101 |
   | a  | 4  | -101 |
   | a  | 1  | -85  |
   | a  | 3  | -72  |
   | a  | 1  | -56  |
   ...
   ```
   I've removed the misleading comment now.



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

Reply via email to