alamb commented on issue #15231:
URL: https://github.com/apache/datafusion/issues/15231#issuecomment-3214307185

   Here is a test case I wrote that should change with this code
   
   ```sql
   
   # Data is ordered by column2 (100, 200, 300, 400)
   statement error DataFusion error: SQL error: ParserError\("Expected: an SQL 
statement, found: COPT at Line: 1, Column: 1"\)
   COPY (
     SELECT * FROM VALUES
       ([1,2,3], 100),
       ([3],     200),
       ([],      300),
       ([3,1],   400)
     ORDER BY column2
    ) TO 'test_files/scratch/unnest/ordered.parquet';
   
   
   statement ok
   CREATE EXTERNAL TABLE t
   STORED AS PARQUET
   LOCATION 'test_files/scratch/unnest/ordered.parquet'
   WITH ORDER (column2)
   
   query ?I
   SELECT * FROM t;
   ----
   [1, 2, 3] 100
   [3] 200
   [] 300
   [3, 1] 400
   
   # data is sorted on column2 already, so no need to sort again
   query II
   SELECT UNNEST(column1), column2 FROM t ORDER BY column2;
   ----
   1 100
   2 100
   3 100
   3 200
   3 400
   1 400
   
   # Explain should not have a SortExec
   query TT
   EXPLAIN SELECT UNNEST(column1), column2 FROM t ORDER BY column2;
   ----
   logical_plan
   01)Sort: t.column2 ASC NULLS LAST
   02)--Projection: __unnest_placeholder(t.column1,depth=1) AS 
UNNEST(t.column1), t.column2
   03)----Unnest: lists[__unnest_placeholder(t.column1)|depth=1] structs[]
   04)------Projection: t.column1 AS __unnest_placeholder(t.column1), t.column2
   05)--------TableScan: t projection=[column1, column2]
   physical_plan
   01)SortExec: expr=[column2@1 ASC NULLS LAST], preserve_partitioning=[false]
   02)--ProjectionExec: expr=[__unnest_placeholder(t.column1,depth=1)@0 as 
UNNEST(t.column1), column2@1 as column2]
   03)----UnnestExec
   04)------ProjectionExec: expr=[column1@0 as __unnest_placeholder(t.column1), 
column2@1 as column2]
   05)--------DataSourceExec: file_groups={1 group: 
[[WORKSPACE_ROOT/datafusion/sqllogictest/test_files/scratch/unnest/ordered.parquet]]},
 projection=[column1, column2], output_ordering=[column2@1 ASC NULLS LAST], 
file_type=parquet
   
   # cleanup
   statement ok
   drop table t;
   ```


-- 
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: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to