Skip to content

Commit 5eb4e0e

Browse files
committed
rs: ignore/respect nulls
1 parent 8480dcc commit 5eb4e0e

3 files changed

Lines changed: 26 additions & 0 deletions

File tree

src/ast/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,10 @@ pub enum Expr {
207207
expr: Box<Expr>,
208208
tz: String,
209209
},
210+
IgnoreRespectNulls {
211+
expr: Box<Expr>,
212+
ignore: bool,
213+
},
210214
/// CAST an expression to a different data type e.g. `CAST(foo AS VARCHAR(123))`
211215
Cast {
212216
/// try_cast is a snowflake feature
@@ -338,6 +342,13 @@ impl fmt::Display for Expr {
338342
}
339343
// rs/pg: https://docs.aws.amazon.com/redshift/latest/dg/r_AT_TIME_ZONE.html
340344
Expr::AtTimeZone { expr, tz } => write!(f, "{} AT TIME ZONE '{}'", expr, tz),
345+
// rs: https://docs.aws.amazon.com/redshift/latest/dg/r_WF_first_value.html
346+
Expr::IgnoreRespectNulls { expr, ignore } => write!(
347+
f,
348+
"{} {} NULLS",
349+
expr,
350+
if *ignore { "IGNORE" } else { "RESPECT " }
351+
),
341352
Expr::Cast {
342353
try_cast,
343354
expr,

src/dialect/keywords.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ define_keywords!(
237237
HOUR,
238238
IDENTITY,
239239
IF,
240+
IGNORE,
240241
ILIKE,
241242
IN,
242243
INDEX,
@@ -378,6 +379,7 @@ define_keywords!(
378379
RENAME,
379380
REPEATABLE,
380381
REPLACE,
382+
RESPECT,
381383
RESTRICT,
382384
RESULT,
383385
RETURN,

src/parser.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,16 @@ impl<'a> Parser<'a> {
827827
true,
828828
))
829829
}
830+
Keyword::IGNORE | Keyword::RESPECT => {
831+
self.expect_keyword(Keyword::NULLS)?;
832+
Ok((
833+
Expr::IgnoreRespectNulls {
834+
expr: Box::new(expr),
835+
ignore: w.value == "IGNORE",
836+
},
837+
true,
838+
))
839+
}
830840
Keyword::IS => {
831841
if self.parse_keyword(Keyword::NULL) {
832842
Ok((Expr::IsNull(Box::new(expr)), true))
@@ -959,6 +969,9 @@ impl<'a> Parser<'a> {
959969
let token = self.peek_token();
960970
debug!("get_next_precedence() {:?}", token);
961971
match token {
972+
Token::Word(w) if w.keyword == Keyword::IGNORE || w.keyword == Keyword::RESPECT => {
973+
Ok(4)
974+
}
962975
Token::Word(w) if w.keyword == Keyword::OR => Ok(5),
963976
Token::Word(w) if w.keyword == Keyword::AND => Ok(10),
964977
Token::Word(w) if w.keyword == Keyword::NOT => match self.peek_nth_token(1) {

0 commit comments

Comments
 (0)