Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion datafusion/sql/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
48 changes: 48 additions & 0 deletions datafusion/sqllogictest/test_files/information_schema.slt
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,54 @@ 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;

# 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';
Expand Down