Skip to content

Commit 7d0dc15

Browse files
committed
snowflake: ignore/respect nulls for window funcs
1 parent 3d9f2c4 commit 7d0dc15

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/ast/mod.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1072,6 +1072,10 @@ pub struct Function {
10721072
/// Some(true) for ASC, Some(false) for DESC
10731073
pub order_by: Vec<OrderByExpr>,
10741074
pub limit: Option<Box<Expr>>,
1075+
// for snowflake - this goes outside of the parens
1076+
// https://docs.snowflake.com/en/sql-reference/functions/first_value.html
1077+
/// Some(true) for IGNORE NULLS, Some(false) for RESPECT NULLS
1078+
pub outer_ignore_respect_nulls: Option<bool>,
10751079
}
10761080

10771081
impl fmt::Display for Function {
@@ -1084,7 +1088,7 @@ impl fmt::Display for Function {
10841088
display_comma_separated(&self.args),
10851089
)?;
10861090
if let Some(b) = self.ignore_respect_nulls {
1087-
write!(f, " {} NULLS", if b { "IGNORE" } else { "RESPECT" })?;
1091+
write!(f, " {} NULLS", if b { "IGNORE" } else { "RESPECT" })?;
10881092
}
10891093
if !self.order_by.is_empty() {
10901094
write!(f, " ORDER BY ")?;
@@ -1098,6 +1102,9 @@ impl fmt::Display for Function {
10981102
write!(f, " LIMIT {}", lim)?;
10991103
}
11001104
write!(f, ")")?;
1105+
if let Some(b) = self.outer_ignore_respect_nulls {
1106+
write!(f, " {} NULLS", if b { "IGNORE" } else { "RESPECT" })?;
1107+
}
11011108
if !self.within_group.is_empty() {
11021109
write!(
11031110
f,

src/parser.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,15 @@ impl<'a> Parser<'a> {
363363
} else {
364364
vec![]
365365
};
366+
let outer_ignore_respect_nulls = if self.parse_keyword(Keyword::IGNORE) {
367+
self.expect_keyword(Keyword::NULLS)?;
368+
Some(true)
369+
} else if self.parse_keyword(Keyword::RESPECT) {
370+
self.expect_keyword(Keyword::NULLS)?;
371+
Some(false)
372+
} else {
373+
None
374+
};
366375
let over = if self.parse_keyword(Keyword::OVER) {
367376
Some(self.parse_window_spec()?)
368377
} else {
@@ -376,6 +385,7 @@ impl<'a> Parser<'a> {
376385
over,
377386
distinct,
378387
ignore_respect_nulls: args_res.ignore_respect_nulls,
388+
outer_ignore_respect_nulls,
379389
order_by: args_res.order_by,
380390
limit: args_res.limit,
381391
}))

0 commit comments

Comments
 (0)