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


##########
datafusion/sqllogictest/test_files/create_external_table.slt:
##########
@@ -228,3 +228,41 @@ OPTIONS (
         format.delimiter '|',
         has_header false,
         compression gzip);
+
+# Create an external parquet table and infer schema to order by
+
+# query should succeed
+statement ok
+CREATE EXTERNAL TABLE t STORED AS parquet LOCATION 
'../../parquet-testing/data/alltypes_plain.parquet' WITH ORDER (id);
+
+## Verify that the table is created with a sort order. Explain should show 
output_ordering=[id@0 ASC]
+query TT
+EXPLAIN SELECT id FROM t ORDER BY id ASC;
+----
+logical_plan
+01)Sort: t.id ASC NULLS LAST
+02)--TableScan: t projection=[id]
+physical_plan
+01)SortExec: expr=[id@0 ASC NULLS LAST], preserve_partitioning=[false]
+02)--ParquetExec: file_groups={1 group: 
[[WORKSPACE_ROOT/parquet-testing/data/alltypes_plain.parquet]]}, 
projection=[id], output_ordering=[id@0 ASC]
+
+statement ok
+DROP TABLE t;
+
+# Create table with non default sort order
+statement ok
+CREATE EXTERNAL TABLE t STORED AS parquet LOCATION 
'../../parquet-testing/data/alltypes_plain.parquet' WITH ORDER (id DESC NULLS 
FIRST);
+
+## Verify that the table is created with a sort order. Explain should show 
output_ordering=[id@0 DESC NULLS FIRST]

Review Comment:
   I think this test shows one small bug (the output ordering is `DESC` not 
`DESC NULLS FIRST`)
   
   I think this is due to the fact that  this PR computes nulls first like this:
   
   ```rust
                      let nulls_first = 
ordered_expr.nulls_first.unwrap_or(true);
   ``` 
   
   But the SQL planner computes it like this:
   
   
https://github.com/apache/datafusion/blob/94d178ebe9674669b32ecd7896b5597f49e90791/datafusion/sql/src/expr/order_by.rs#L105-L107
   
   



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