Wrap the logical in a sort
(
&self,
plan: LogicalPlan,
order_by: Vec<Sort>,
)
| 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( |