Skip to content

Commit 427bec4

Browse files
Support for INTERVAL inside window frames (#655)
* Add support to for INTERVAL inside window queries * Remove the unnecessary ancillary struct Interval * Convert Window Frame Bound to Expr * remove unnecessary changes * remove unnecessary changes Co-authored-by: Mehmet Ozan Kabak <ozankabak@gmail.com>
1 parent cacdf33 commit 427bec4

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

src/ast/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -906,9 +906,9 @@ pub enum WindowFrameBound {
906906
/// `CURRENT ROW`
907907
CurrentRow,
908908
/// `<N> PRECEDING` or `UNBOUNDED PRECEDING`
909-
Preceding(Option<u64>),
909+
Preceding(Option<Box<Expr>>),
910910
/// `<N> FOLLOWING` or `UNBOUNDED FOLLOWING`.
911-
Following(Option<u64>),
911+
Following(Option<Box<Expr>>),
912912
}
913913

914914
impl fmt::Display for WindowFrameBound {

src/parser.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,6 @@ impl<'a> Parser<'a> {
623623
} else {
624624
None
625625
};
626-
627626
Ok(Expr::Function(Function {
628627
name,
629628
args,
@@ -685,7 +684,10 @@ impl<'a> Parser<'a> {
685684
let rows = if self.parse_keyword(Keyword::UNBOUNDED) {
686685
None
687686
} else {
688-
Some(self.parse_literal_uint()?)
687+
Some(Box::new(match self.peek_token() {
688+
Token::SingleQuotedString(_) => self.parse_interval()?,
689+
_ => self.parse_expr()?,
690+
}))
689691
};
690692
if self.parse_keyword(Keyword::PRECEDING) {
691693
Ok(WindowFrameBound::Preceding(rows))

tests/sqlparser_common.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2940,13 +2940,17 @@ fn parse_window_functions() {
29402940
ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW), \
29412941
avg(bar) OVER (ORDER BY a \
29422942
RANGE BETWEEN 1 PRECEDING AND 1 FOLLOWING), \
2943+
sum(bar) OVER (ORDER BY a \
2944+
RANGE BETWEEN INTERVAL '1' DAY PRECEDING AND INTERVAL '1 MONTH' FOLLOWING), \
2945+
COUNT(*) OVER (ORDER BY a \
2946+
RANGE BETWEEN INTERVAL '1 DAY' PRECEDING AND INTERVAL '1 DAY' FOLLOWING), \
29432947
max(baz) OVER (ORDER BY a \
29442948
ROWS UNBOUNDED PRECEDING), \
29452949
sum(qux) OVER (ORDER BY a \
29462950
GROUPS BETWEEN 1 PRECEDING AND 1 FOLLOWING) \
29472951
FROM foo";
29482952
let select = verified_only_select(sql);
2949-
assert_eq!(5, select.projection.len());
2953+
assert_eq!(7, select.projection.len());
29502954
assert_eq!(
29512955
&Expr::Function(Function {
29522956
name: ObjectName(vec![Ident::new("row_number")]),

0 commit comments

Comments
 (0)