Skip to content

Commit 8e87a2c

Browse files
committed
Add NullInclussion as type instead of bool
1 parent 16856ae commit 8e87a2c

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
@@ -9203,6 +9203,26 @@ pub enum CopyIntoSnowflakeKind {
92039203
Location,
92049204
}
92059205

9206+
/// Specifies Include / Exclude NULL within UNPIVOT command.
9207+
/// For example
9208+
/// `UNPIVOT (column1 FOR new_column IN (col3, col4, col5, col6))`
9209+
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9210+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9211+
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9212+
pub enum NullInclusion {
9213+
IncludeNulls,
9214+
ExcludeNulls,
9215+
}
9216+
9217+
impl fmt::Display for NullInclusion {
9218+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9219+
match self {
9220+
NullInclusion::IncludeNulls => write!(f, "INCLUDE NULLS"),
9221+
NullInclusion::ExcludeNulls => write!(f, "EXCLUDE NULLS"),
9222+
}
9223+
}
9224+
}
9225+
92069226
#[cfg(test)]
92079227
mod tests {
92089228
use super::*;

src/ast/query.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,7 +1248,7 @@ pub enum TableFactor {
12481248
value: Ident,
12491249
name: Ident,
12501250
columns: Vec<Ident>,
1251-
include_nulls: Option<bool>,
1251+
include_nulls: Option<NullInclusion>,
12521252
alias: Option<TableAlias>,
12531253
},
12541254
/// A `MATCH_RECOGNIZE` operation on a table.
@@ -1893,11 +1893,7 @@ impl fmt::Display for TableFactor {
18931893
} => {
18941894
write!(f, "{table} UNPIVOT")?;
18951895
if let Some(include_nulls) = include_nulls {
1896-
if *include_nulls {
1897-
write!(f, " INCLUDE NULLS ")?;
1898-
} else {
1899-
write!(f, " EXCLUDE NULLS ")?;
1900-
}
1896+
write!(f, " {include_nulls} ")?;
19011897
}
19021898
write!(
19031899
f,

src/parser/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12746,10 +12746,10 @@ impl<'a> Parser<'a> {
1274612746
) -> Result<TableFactor, ParserError> {
1274712747
let include_nulls = if self.parse_keyword(Keyword::INCLUDE) {
1274812748
self.expect_keyword_is(Keyword::NULLS)?;
12749-
Some(true)
12749+
Some(NullInclusion::IncludeNulls)
1275012750
} else if self.parse_keyword(Keyword::EXCLUDE) {
1275112751
self.expect_keyword_is(Keyword::NULLS)?;
12752-
Some(false)
12752+
Some(NullInclusion::ExcludeNulls)
1275312753
} else {
1275412754
None
1275512755
};

tests/sqlparser_common.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10743,7 +10743,7 @@ fn parse_unpivot_table() {
1074310743
if let Unpivot { include_nulls, .. } =
1074410744
&verified_only_select(sql_unpivot_exclude_nulls).from[0].relation
1074510745
{
10746-
assert_eq!(*include_nulls, Some(false));
10746+
assert_eq!(*include_nulls, Some(NullInclusion::ExcludeNulls));
1074710747
}
1074810748

1074910749
assert_eq!(
@@ -10759,7 +10759,7 @@ fn parse_unpivot_table() {
1075910759
if let Unpivot { include_nulls, .. } =
1076010760
&verified_only_select(sql_unpivot_include_nulls).from[0].relation
1076110761
{
10762-
assert_eq!(*include_nulls, Some(true));
10762+
assert_eq!(*include_nulls, Some(NullInclusion::IncludeNulls));
1076310763
}
1076410764

1076510765
assert_eq!(

0 commit comments

Comments
 (0)