From 60315bab113d34f47eb0c97dafe33de48c774f7a Mon Sep 17 00:00:00 2001 From: Gene Bordegaray Date: Sat, 25 Oct 2025 12:00:05 -0400 Subject: [PATCH 1/3] Add WITH ORDER display in information_schema.views --- datafusion/sql/src/parser.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/datafusion/sql/src/parser.rs b/datafusion/sql/src/parser.rs index 271ad8a856b47..1f1ef2a672abc 100644 --- a/datafusion/sql/src/parser.rs +++ b/datafusion/sql/src/parser.rs @@ -243,7 +243,19 @@ impl fmt::Display for CreateExternalTable { } write!(f, "{} ", self.name)?; write!(f, "STORED AS {} ", self.file_type)?; - write!(f, "LOCATION {} ", self.location) + if !self.order_exprs.is_empty() { + write!(f, "WITH ORDER (")?; + let mut first = true; + for expr in self.order_exprs.iter().flatten() { + if !first { + write!(f, ", ")?; + } + write!(f, "{expr}")?; + first = false; + } + write!(f, ") ")?; + } + write!(f, "LOCATION {}", self.location) } } From dce4f5fdacc8d6b01cabb5d13c61177a7f51d298 Mon Sep 17 00:00:00 2001 From: Gene Bordegaray Date: Sun, 26 Oct 2025 10:53:55 -0400 Subject: [PATCH 2/3] added tests in sqllogictests --- .../test_files/information_schema.slt | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/datafusion/sqllogictest/test_files/information_schema.slt b/datafusion/sqllogictest/test_files/information_schema.slt index b15ec026372d5..1e6cd712a1cec 100644 --- a/datafusion/sqllogictest/test_files/information_schema.slt +++ b/datafusion/sqllogictest/test_files/information_schema.slt @@ -705,6 +705,38 @@ SHOW CREATE TABLE abc; ---- datafusion public abc CREATE EXTERNAL TABLE abc STORED AS CSV LOCATION ../../testing/data/csv/aggregate_test_100.csv +# show_external_create_table_with_order +statement ok +CREATE EXTERNAL TABLE abc_ordered +STORED AS CSV +WITH ORDER (c1) +LOCATION '../../testing/data/csv/aggregate_test_100.csv' +OPTIONS ('format.has_header' 'true'); + +query TTTT +SHOW CREATE TABLE abc_ordered; +---- +datafusion public abc_ordered CREATE EXTERNAL TABLE abc_ordered STORED AS CSV WITH ORDER (c1) LOCATION ../../testing/data/csv/aggregate_test_100.csv + +statement ok +DROP TABLE abc_ordered; + +# show_external_create_table_with_multiple_order_columns +statement ok +CREATE EXTERNAL TABLE abc_multi_order +STORED AS CSV +WITH ORDER (c1, c2 DESC) +LOCATION '../../testing/data/csv/aggregate_test_100.csv' +OPTIONS ('format.has_header' 'true'); + +query TTTT +SHOW CREATE TABLE abc_multi_order; +---- +datafusion public abc_multi_order CREATE EXTERNAL TABLE abc_multi_order STORED AS CSV WITH ORDER (c1, c2 DESC) LOCATION ../../testing/data/csv/aggregate_test_100.csv + +statement ok +DROP TABLE abc_multi_order; + # string_agg has different arg_types but same return type. Test avoiding duplicate entries for the same function. query TTT select routine_name, data_type, function_type from information_schema.routines where routine_name = 'string_agg'; From d56bed49b464987225041d27b08bc49590a61b01 Mon Sep 17 00:00:00 2001 From: Gene Bordegaray Date: Mon, 27 Oct 2025 10:03:26 -0400 Subject: [PATCH 3/3] Adding test with NULLS options --- .../test_files/information_schema.slt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/datafusion/sqllogictest/test_files/information_schema.slt b/datafusion/sqllogictest/test_files/information_schema.slt index 1e6cd712a1cec..f469f536cd91d 100644 --- a/datafusion/sqllogictest/test_files/information_schema.slt +++ b/datafusion/sqllogictest/test_files/information_schema.slt @@ -737,6 +737,22 @@ datafusion public abc_multi_order CREATE EXTERNAL TABLE abc_multi_order STORED A statement ok DROP TABLE abc_multi_order; +# show_external_create_table_with_order_nulls +statement ok +CREATE EXTERNAL TABLE abc_order_nulls +STORED AS CSV +WITH ORDER (c1 NULLS LAST, c2 DESC NULLS FIRST) +LOCATION '../../testing/data/csv/aggregate_test_100.csv' +OPTIONS ('format.has_header' 'true'); + +query TTTT +SHOW CREATE TABLE abc_order_nulls; +---- +datafusion public abc_order_nulls CREATE EXTERNAL TABLE abc_order_nulls STORED AS CSV WITH ORDER (c1 NULLS LAST, c2 DESC NULLS FIRST) LOCATION ../../testing/data/csv/aggregate_test_100.csv + +statement ok +DROP TABLE abc_order_nulls; + # string_agg has different arg_types but same return type. Test avoiding duplicate entries for the same function. query TTT select routine_name, data_type, function_type from information_schema.routines where routine_name = 'string_agg';