Skip to content

Commit 2476463

Browse files
authored
feat: support RANGE frame for window function. (#10911)
1 parent fa9ac5b commit 2476463

File tree

14 files changed

+681
-254
lines changed

14 files changed

+681
-254
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/query/ast/src/ast/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ pub struct WindowFrame {
491491
pub end_bound: WindowFrameBound,
492492
}
493493

494-
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
494+
#[derive(Debug, Clone, PartialEq, Eq, Hash, EnumAsInner)]
495495
pub enum WindowFrameUnits {
496496
Rows,
497497
Range,

src/query/ast/src/parser/query.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -618,20 +618,20 @@ pub fn group_by_items(i: Input) -> IResult<GroupBy> {
618618
pub fn window_frame_bound(i: Input) -> IResult<WindowFrameBound> {
619619
alt((
620620
value(WindowFrameBound::CurrentRow, rule! { CURRENT ~ ROW }),
621-
map(rule! { #subexpr(0) ~ PRECEDING }, |(expr, _)| {
622-
WindowFrameBound::Preceding(Some(Box::new(expr)))
623-
}),
624621
value(
625622
WindowFrameBound::Preceding(None),
626623
rule! { UNBOUNDED ~ PRECEDING },
627624
),
628-
map(rule! { #subexpr(0) ~ FOLLOWING }, |(expr, _)| {
629-
WindowFrameBound::Following(Some(Box::new(expr)))
625+
map(rule! { #subexpr(0) ~ PRECEDING }, |(expr, _)| {
626+
WindowFrameBound::Preceding(Some(Box::new(expr)))
630627
}),
631628
value(
632629
WindowFrameBound::Following(None),
633630
rule! { UNBOUNDED ~ FOLLOWING },
634631
),
632+
map(rule! { #subexpr(0) ~ FOLLOWING }, |(expr, _)| {
633+
WindowFrameBound::Following(Some(Box::new(expr)))
634+
}),
635635
))(i)
636636
}
637637

src/query/ast/tests/it/testdata/expr.txt

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3350,22 +3350,7 @@ FunctionCall {
33503350
WindowFrame {
33513351
units: Rows,
33523352
start_bound: Preceding(
3353-
Some(
3354-
ColumnRef {
3355-
span: Some(
3356-
76..85,
3357-
),
3358-
database: None,
3359-
table: None,
3360-
column: Identifier {
3361-
name: "UNBOUNDED",
3362-
quote: None,
3363-
span: Some(
3364-
76..85,
3365-
),
3366-
},
3367-
},
3368-
),
3353+
None,
33693354
),
33703355
end_bound: CurrentRow,
33713356
},
@@ -3593,22 +3578,7 @@ FunctionCall {
35933578
WindowFrame {
35943579
units: Rows,
35953580
start_bound: Preceding(
3596-
Some(
3597-
ColumnRef {
3598-
span: Some(
3599-
38..47,
3600-
),
3601-
database: None,
3602-
table: None,
3603-
column: Identifier {
3604-
name: "UNBOUNDED",
3605-
quote: None,
3606-
span: Some(
3607-
38..47,
3608-
),
3609-
},
3610-
},
3611-
),
3581+
None,
36123582
),
36133583
end_bound: CurrentRow,
36143584
},

src/query/service/src/pipelines/pipeline_builder.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,11 @@ impl PipelineBuilder {
738738
.iter()
739739
.map(|o| {
740740
let offset = input_schema.index_of(&o.order_by.to_string())?;
741-
Ok(offset)
741+
Ok(SortColumnDescription {
742+
offset,
743+
asc: o.asc,
744+
nulls_first: o.nulls_first,
745+
})
742746
})
743747
.collect::<Result<Vec<_>>>()?;
744748

@@ -754,13 +758,7 @@ impl PipelineBuilder {
754758
})
755759
}
756760

757-
for (order_desc, offset) in window.order_by.iter().zip(order_by.iter()) {
758-
sort_desc.push(SortColumnDescription {
759-
offset: *offset,
760-
asc: order_desc.asc,
761-
nulls_first: order_desc.nulls_first,
762-
})
763-
}
761+
sort_desc.extend(order_by.clone());
764762

765763
self.build_sort_pipeline(input_schema.clone(), sort_desc, window.plan_id, None)?;
766764
}

0 commit comments

Comments
 (0)