MCPcopy Create free account
hub / github.com/apache/datafusion / order_by

Method order_by

datafusion/sql/src/query.rs:303–320  ·  view source on GitHub ↗

Wrap the logical in a sort

(
        &self,
        plan: LogicalPlan,
        order_by: Vec<Sort>,
    )

Source from the content-addressed store, hash-verified

301
302 /// Wrap the logical in a sort
303 pub(super) fn order_by(
304 &self,
305 plan: LogicalPlan,
306 order_by: Vec<Sort>,
307 ) -> Result<LogicalPlan> {
308 if order_by.is_empty() {
309 return Ok(plan);
310 }
311
312 if let LogicalPlan::Distinct(Distinct::On(ref distinct_on)) = plan {
313 // In case of `DISTINCT ON` we must capture the sort expressions since during the plan
314 // optimization we're effectively doing a `first_value` aggregation according to them.
315 let distinct_on = distinct_on.clone().with_sort_expr(order_by)?;
316 Ok(LogicalPlan::Distinct(Distinct::On(distinct_on)))
317 } else {
318 LogicalPlanBuilder::from(plan).sort(order_by)?.build()
319 }
320 }
321
322 /// Handle AGGREGATE pipe operator
323 fn pipe_operator_aggregate(

Callers 15

expr_fn_demoFunction · 0.45
simple_udwfFunction · 0.45
advanced_udwfFunction · 0.45
select_to_planMethod · 0.45
query_to_planMethod · 0.45
pipe_operatorMethod · 0.45
nth_valueFunction · 0.45
first_valueFunction · 0.45
last_valueFunction · 0.45
distinct_with_order_byFunction · 0.45
filter_move_windowFunction · 0.45

Calls 6

DistinctEnum · 0.85
with_sort_exprMethod · 0.80
is_emptyMethod · 0.45
cloneMethod · 0.45
buildMethod · 0.45
sortMethod · 0.45