Skip to content

Commit

Permalink
snowflake: ignore/respect nulls for window funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
donhcd committed Dec 12, 2020
1 parent 3d9f2c4 commit 7d0dc15
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,10 @@ pub struct Function {
/// Some(true) for ASC, Some(false) for DESC
pub order_by: Vec<OrderByExpr>,
pub limit: Option<Box<Expr>>,
// for snowflake - this goes outside of the parens
// https://docs.snowflake.com/en/sql-reference/functions/first_value.html
/// Some(true) for IGNORE NULLS, Some(false) for RESPECT NULLS
pub outer_ignore_respect_nulls: Option<bool>,
}

impl fmt::Display for Function {
Expand All @@ -1084,7 +1088,7 @@ impl fmt::Display for Function {
display_comma_separated(&self.args),
)?;
if let Some(b) = self.ignore_respect_nulls {
write!(f, " {} NULLS", if b { "IGNORE" } else { "RESPECT" })?;
write!(f, " {} NULLS", if b { "IGNORE" } else { "RESPECT" })?;
}
if !self.order_by.is_empty() {
write!(f, " ORDER BY ")?;
Expand All @@ -1098,6 +1102,9 @@ impl fmt::Display for Function {
write!(f, " LIMIT {}", lim)?;
}
write!(f, ")")?;
if let Some(b) = self.outer_ignore_respect_nulls {
write!(f, " {} NULLS", if b { "IGNORE" } else { "RESPECT" })?;
}
if !self.within_group.is_empty() {
write!(
f,
Expand Down
10 changes: 10 additions & 0 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,15 @@ impl<'a> Parser<'a> {
} else {
vec![]
};
let outer_ignore_respect_nulls = if self.parse_keyword(Keyword::IGNORE) {
self.expect_keyword(Keyword::NULLS)?;
Some(true)
} else if self.parse_keyword(Keyword::RESPECT) {
self.expect_keyword(Keyword::NULLS)?;
Some(false)
} else {
None
};
let over = if self.parse_keyword(Keyword::OVER) {
Some(self.parse_window_spec()?)
} else {
Expand All @@ -376,6 +385,7 @@ impl<'a> Parser<'a> {
over,
distinct,
ignore_respect_nulls: args_res.ignore_respect_nulls,
outer_ignore_respect_nulls,
order_by: args_res.order_by,
limit: args_res.limit,
}))
Expand Down

0 comments on commit 7d0dc15

Please sign in to comment.