Skip to content

Commit 16265d0

Browse files
authored
refactor(window): consume explicitly sorted input (#378)
1 parent 506bd78 commit 16265d0

4 files changed

Lines changed: 244 additions & 270 deletions

File tree

src/binder/window.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use crate::expression::visitor_mut::{walk_mut_expr, ExprVisitorMut};
1919
use crate::expression::window::{WindowCall, WindowFunction, WindowFunctionKind, WindowSpec};
2020
use crate::expression::ScalarExpression;
2121
use crate::planner::operator::sort::SortField;
22+
use crate::planner::operator::sort::SortOperator;
2223
use crate::planner::operator::window::WindowOperator;
2324
use crate::planner::operator::Operator;
2425
use crate::planner::{Childrens, LogicalPlan, PlanArena};
@@ -209,14 +210,23 @@ impl<T: Transaction, A: AsRef<[(&'static str, DataValue)]>> Binder<'_, '_, T, A>
209210

210211
for group in groups {
211212
let partition_by_len = group.partition_by.len();
213+
let sort_fields: Vec<_> = group
214+
.partition_by
215+
.into_iter()
216+
.map(SortField::from)
217+
.chain(group.order_by)
218+
.collect();
219+
if !sort_fields.is_empty() {
220+
children = LogicalPlan::new(
221+
Operator::Sort(SortOperator {
222+
sort_fields: sort_fields.clone(),
223+
}),
224+
Childrens::Only(Box::new(children)),
225+
);
226+
}
212227
children = LogicalPlan::new(
213228
Operator::Window(WindowOperator {
214-
sort_fields: group
215-
.partition_by
216-
.into_iter()
217-
.map(SortField::from)
218-
.chain(group.order_by)
219-
.collect(),
229+
sort_fields,
220230
partition_by_len,
221231
functions: group.functions,
222232
output_columns: group.output_columns,

0 commit comments

Comments
 (0)