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

Method with_sort_expr

datafusion/expr/src/logical_plan/plan.rs:3505–3525  ·  view source on GitHub ↗

Try to update `self` with a new sort expressions. Validates that the sort expressions are a super-set of the `ON` expressions.

(mut self, sort_expr: Vec<SortExpr>)

Source from the content-addressed store, hash-verified

3503 ///
3504 /// Validates that the sort expressions are a super-set of the `ON` expressions.
3505 pub fn with_sort_expr(mut self, sort_expr: Vec<SortExpr>) -> Result<Self> {
3506 let sort_expr = normalize_sorts(sort_expr, self.input.as_ref())?;
3507
3508 // Check that the left-most sort expressions are the same as the `ON` expressions.
3509 let mut matched = true;
3510 for (on, sort) in self.on_expr.iter().zip(sort_expr.iter()) {
3511 if on != &sort.expr {
3512 matched = false;
3513 break;
3514 }
3515 }
3516
3517 if self.on_expr.len() > sort_expr.len() || !matched {
3518 return plan_err!(
3519 "SELECT DISTINCT ON expressions must match initial ORDER BY expressions"
3520 );
3521 }
3522
3523 self.sort_expr = Some(sort_expr);
3524 Ok(self)
3525 }
3526}
3527
3528// Manual implementation needed because of `schema` field. Comparison excludes this field.

Callers 2

try_newMethod · 0.80
order_byMethod · 0.80

Calls 4

normalize_sortsFunction · 0.85
as_refMethod · 0.45
iterMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected