alamb commented on code in PR #27721:
URL: https://github.com/apache/datafusion/pull/27721#discussion_r4699488226


##########
datafusion/sqllogictest/test_files/copy.slt:
##########
@@ -932,3 +932,76 @@ DROP TABLE copy_with_order;
 
 statement ok
 DROP TABLE union_const_src;
+
+# A struct column before the sort key must not shift the recorded sort column
+query I
+COPY (
+  SELECT named_struct('x', i, 'y', i) AS st, i % 3 AS a, i AS b
+  FROM generate_series(1, 6) AS t(i)
+  ORDER BY b
+) TO 'test_files/scratch/copy/struct_before_sort_key/sorted.parquet';
+----
+6
+
+statement ok
+CREATE EXTERNAL TABLE struct_before_sort_key STORED AS PARQUET
+LOCATION 'test_files/scratch/copy/struct_before_sort_key/sorted.parquet';
+
+query I
+SELECT a FROM struct_before_sort_key ORDER BY a;
+----
+0
+0
+1
+1
+2
+2
+
+# The file is sorted by b, so ORDER BY b needs no sort

Review Comment:
   the plan shows a sort so I don't understand this comment



##########
datafusion/sqllogictest/test_files/copy.slt:
##########
@@ -932,3 +932,76 @@ DROP TABLE copy_with_order;
 
 statement ok
 DROP TABLE union_const_src;
+
+# A struct column before the sort key must not shift the recorded sort column
+query I
+COPY (
+  SELECT named_struct('x', i, 'y', i) AS st, i % 3 AS a, i AS b
+  FROM generate_series(1, 6) AS t(i)
+  ORDER BY b
+) TO 'test_files/scratch/copy/struct_before_sort_key/sorted.parquet';
+----
+6
+
+statement ok
+CREATE EXTERNAL TABLE struct_before_sort_key STORED AS PARQUET
+LOCATION 'test_files/scratch/copy/struct_before_sort_key/sorted.parquet';
+
+query I
+SELECT a FROM struct_before_sort_key ORDER BY a;
+----
+0
+0
+1
+1
+2
+2
+
+# The file is sorted by b, so ORDER BY b needs no sort
+query TT
+EXPLAIN SELECT b FROM struct_before_sort_key ORDER BY b;
+----
+logical_plan
+01)Sort: struct_before_sort_key.b ASC NULLS LAST
+02)--TableScan: struct_before_sort_key projection=[b]
+physical_plan DataSourceExec: file_groups={1 group: 
[[WORKSPACE_ROOT/datafusion/sqllogictest/test_files/scratch/copy/struct_before_sort_key/sorted.parquet]]},
 projection=[b], output_ordering=[b@0 ASC NULLS LAST], file_type=parquet
+
+# A struct sort key can't be recorded, so no sort order is written
+query I
+COPY (
+  SELECT named_struct('x', -i, 'y', i) AS st, i % 3 AS a, i AS b
+  FROM generate_series(1, 6) AS t(i)
+  ORDER BY st, b
+) TO 'test_files/scratch/copy/struct_sort_key/sorted.parquet';
+----
+6
+
+statement ok
+CREATE EXTERNAL TABLE struct_sort_key STORED AS PARQUET
+LOCATION 'test_files/scratch/copy/struct_sort_key/sorted.parquet';
+
+query I
+SELECT a FROM struct_sort_key ORDER BY a;
+----
+0
+0
+1
+1
+2
+2
+
+query I
+SELECT b FROM struct_sort_key ORDER BY b;

Review Comment:
   can you please show these plans too via `EXPLAIN` so we cn verify if there 
is a sort or not?



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