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
20 changes: 9 additions & 11 deletions datafusion/sql/src/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1445,25 +1445,23 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
.map(|order_by_expr| {
let ordered_expr = &order_by_expr.expr;
let ordered_expr = ordered_expr.to_owned();
let ordered_expr = self
.sql_expr_to_logical_expr(
ordered_expr,
schema,
planner_context,
)
.unwrap();
let ordered_expr = self.sql_expr_to_logical_expr(
ordered_expr,
schema,
planner_context,
)?;
let asc = order_by_expr.options.asc.unwrap_or(true);
let nulls_first =
order_by_expr.options.nulls_first.unwrap_or_else(|| {
self.options.default_null_ordering.nulls_first(asc)
});

SortExpr::new(ordered_expr, asc, nulls_first)
Ok(SortExpr::new(ordered_expr, asc, nulls_first))
})
.collect::<Vec<SortExpr>>();
result
.collect::<Result<Vec<SortExpr>>>()?;
Ok(result)
})
.collect::<Vec<Vec<SortExpr>>>();
.collect::<Result<Vec<Vec<SortExpr>>>>()?;

return Ok(results);
}
Expand Down
7 changes: 7 additions & 0 deletions datafusion/sqllogictest/test_files/order.slt
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,13 @@ physical_plan DataSourceExec: file_groups={1 group: [[WORKSPACE_ROOT/datafusion/
query error DataFusion error: Error during planning: Column a is not in schema
CREATE EXTERNAL TABLE dt (a_id integer, a_str string, a_bool boolean) STORED AS CSV WITH ORDER (a ASC) LOCATION 'file://path/to/table';


# Create external table with order column expression that can't be planned
# This is currently expected to fail, but should not panic
query error DataFusion error: Schema error: No field named a\.
CREATE EXTERNAL TABLE dt STORED AS CSV WITH ORDER (a || b) LOCATION 'file://path/to/table';


# Sort with duplicate sort expressions
# Table is sorted multiple times on the same column name and should not fail
statement ok
Expand Down