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>)
| 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. |