Skip to content

Commit 79c8d39

Browse files
committed
Add NullInclussion as type instead of bool
1 parent 41eb491 commit 79c8d39

File tree

4 files changed

+26
-10
lines changed

4 files changed

+26
-10
lines changed

src/ast/mod.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8701,6 +8701,26 @@ pub enum CopyIntoSnowflakeKind {
87018701
Location,
87028702
}
87038703

8704+
/// Specifies Include / Exclude NULL within UNPIVOT command.
8705+
/// For example
8706+
/// `UNPIVOT (column1 FOR new_column IN (col3, col4, col5, col6))`
8707+
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8708+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8709+
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8710+
pub enum NullInclusion {
8711+
IncludeNulls,
8712+
ExcludeNulls,
8713+
}
8714+
8715+
impl fmt::Display for NullInclusion {
8716+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8717+
match self {
8718+
NullInclusion::IncludeNulls => write!(f, "INCLUDE NULLS"),
8719+
NullInclusion::ExcludeNulls => write!(f, "EXCLUDE NULLS"),
8720+
}
8721+
}
8722+
}
8723+
87048724
#[cfg(test)]
87058725
mod tests {
87068726
use super::*;

src/ast/query.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,7 +1257,7 @@ pub enum TableFactor {
12571257
value: Ident,
12581258
name: Ident,
12591259
columns: Vec<Ident>,
1260-
include_nulls: Option<bool>,
1260+
include_nulls: Option<NullInclusion>,
12611261
alias: Option<TableAlias>,
12621262
},
12631263
/// A `MATCH_RECOGNIZE` operation on a table.
@@ -1902,11 +1902,7 @@ impl fmt::Display for TableFactor {
19021902
} => {
19031903
write!(f, "{table} UNPIVOT")?;
19041904
if let Some(include_nulls) = include_nulls {
1905-
if *include_nulls {
1906-
write!(f, " INCLUDE NULLS ")?;
1907-
} else {
1908-
write!(f, " EXCLUDE NULLS ")?;
1909-
}
1905+
write!(f, " {include_nulls} ")?;
19101906
}
19111907
write!(
19121908
f,

src/parser/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12398,10 +12398,10 @@ impl<'a> Parser<'a> {
1239812398
) -> Result<TableFactor, ParserError> {
1239912399
let include_nulls = if self.parse_keyword(Keyword::INCLUDE) {
1240012400
self.expect_keyword_is(Keyword::NULLS)?;
12401-
Some(true)
12401+
Some(NullInclusion::IncludeNulls)
1240212402
} else if self.parse_keyword(Keyword::EXCLUDE) {
1240312403
self.expect_keyword_is(Keyword::NULLS)?;
12404-
Some(false)
12404+
Some(NullInclusion::ExcludeNulls)
1240512405
} else {
1240612406
None
1240712407
};

tests/sqlparser_common.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10637,7 +10637,7 @@ fn parse_unpivot_table() {
1063710637
if let Unpivot { include_nulls, .. } =
1063810638
&verified_only_select(sql_unpivot_exclude_nulls).from[0].relation
1063910639
{
10640-
assert_eq!(*include_nulls, Some(false));
10640+
assert_eq!(*include_nulls, Some(NullInclusion::ExcludeNulls));
1064110641
}
1064210642

1064310643
assert_eq!(
@@ -10653,7 +10653,7 @@ fn parse_unpivot_table() {
1065310653
if let Unpivot { include_nulls, .. } =
1065410654
&verified_only_select(sql_unpivot_include_nulls).from[0].relation
1065510655
{
10656-
assert_eq!(*include_nulls, Some(true));
10656+
assert_eq!(*include_nulls, Some(NullInclusion::IncludeNulls));
1065710657
}
1065810658

1065910659
assert_eq!(

0 commit comments

Comments
 (0)