@@ -1045,6 +1045,52 @@ physical_plan
10451045statement ok
10461046drop table t;
10471047
1048+ # Unnest tuple where the data is already sorted by column 1
1049+ statement ok
1050+ COPY (
1051+ SELECT * FROM VALUES
1052+ (100, [3,2,1], 'a'),
1053+ (200, [1,2,3], 'b'),
1054+ (300, [3,1,2], 'c')
1055+ ORDER BY column1
1056+ ) TO 'test_files/scratch/unnest/ordered_tuples.parquet';
1057+
1058+ statement ok
1059+ CREATE EXTERNAL TABLE t
1060+ STORED AS PARQUET
1061+ LOCATION 'test_files/scratch/unnest/ordered_tuples.parquet'
1062+ WITH ORDER (column1)
1063+
1064+ query I?T
1065+ SELECT * FROM t;
1066+ ----
1067+ 100 [3, 2, 1] a
1068+ 200 [1, 2, 3] b
1069+ 300 [3, 1, 2] c
1070+
1071+ # Put the columns in a tuple and unnest, we need to sort because we discard ordering of unnested columns
1072+ query TT
1073+ EXPLAIN WITH unnested AS (
1074+ SELECT unnest((column1, column2, column3))
1075+ FROM t
1076+ ) SELECT * FROM unnested order by 1;
1077+ ----
1078+ logical_plan
1079+ 01)Sort: unnested.__unnest_placeholder(struct(t.column1,t.column2,t.column3)).c0 ASC NULLS LAST
1080+ 02)--SubqueryAlias: unnested
1081+ 03)----Unnest: lists[] structs[__unnest_placeholder(struct(t.column1,t.column2,t.column3))]
1082+ 04)------Projection: struct(t.column1, t.column2, t.column3) AS __unnest_placeholder(struct(t.column1,t.column2,t.column3))
1083+ 05)--------TableScan: t projection=[column1, column2, column3]
1084+ physical_plan
1085+ 01)SortExec: expr=[__unnest_placeholder(struct(t.column1,t.column2,t.column3)).c0@0 ASC NULLS LAST], preserve_partitioning=[false]
1086+ 02)--UnnestExec
1087+ 03)----ProjectionExec: expr=[struct(column1@0, column2@1, column3@2) as __unnest_placeholder(struct(t.column1,t.column2,t.column3))]
1088+ 04)------DataSourceExec: file_groups={1 group: [[WORKSPACE_ROOT/datafusion/sqllogictest/test_files/scratch/unnest/ordered_tuples.parquet]]}, projection=[column1, column2, column3], output_ordering=[column1@0 ASC NULLS LAST], file_type=parquet
1089+
1090+ # cleanup
1091+ statement ok
1092+ drop table t;
1093+
10481094# Unnest struct where data is already ordered by column2 (100, 200, 300, 400)
10491095statement ok
10501096COPY (
0 commit comments