Skip to content

Commit e029450

Browse files
committed
Add NullInclussion as type instead of bool
1 parent d0917c9 commit e029450

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
@@ -9633,6 +9633,26 @@ impl fmt::Display for OpenStatement {
96339633
}
96349634
}
96359635

9636+
/// Specifies Include / Exclude NULL within UNPIVOT command.
9637+
/// For example
9638+
/// `UNPIVOT (column1 FOR new_column IN (col3, col4, col5, col6))`
9639+
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9640+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9641+
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9642+
pub enum NullInclusion {
9643+
IncludeNulls,
9644+
ExcludeNulls,
9645+
}
9646+
9647+
impl fmt::Display for NullInclusion {
9648+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9649+
match self {
9650+
NullInclusion::IncludeNulls => write!(f, "INCLUDE NULLS"),
9651+
NullInclusion::ExcludeNulls => write!(f, "EXCLUDE NULLS"),
9652+
}
9653+
}
9654+
}
9655+
96369656
#[cfg(test)]
96379657
mod tests {
96389658
use super::*;

src/ast/query.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,7 +1345,7 @@ pub enum TableFactor {
13451345
value: Ident,
13461346
name: Ident,
13471347
columns: Vec<Ident>,
1348-
include_nulls: Option<bool>,
1348+
include_nulls: Option<NullInclusion>,
13491349
alias: Option<TableAlias>,
13501350
},
13511351
/// A `MATCH_RECOGNIZE` operation on a table.
@@ -2024,11 +2024,7 @@ impl fmt::Display for TableFactor {
20242024
} => {
20252025
write!(f, "{table} UNPIVOT")?;
20262026
if let Some(include_nulls) = include_nulls {
2027-
if *include_nulls {
2028-
write!(f, " INCLUDE NULLS ")?;
2029-
} else {
2030-
write!(f, " EXCLUDE NULLS ")?;
2031-
}
2027+
write!(f, " {include_nulls} ")?;
20322028
}
20332029
write!(
20342030
f,

src/parser/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13370,10 +13370,10 @@ impl<'a> Parser<'a> {
1337013370
) -> Result<TableFactor, ParserError> {
1337113371
let include_nulls = if self.parse_keyword(Keyword::INCLUDE) {
1337213372
self.expect_keyword_is(Keyword::NULLS)?;
13373-
Some(true)
13373+
Some(NullInclusion::IncludeNulls)
1337413374
} else if self.parse_keyword(Keyword::EXCLUDE) {
1337513375
self.expect_keyword_is(Keyword::NULLS)?;
13376-
Some(false)
13376+
Some(NullInclusion::ExcludeNulls)
1337713377
} else {
1337813378
None
1337913379
};

tests/sqlparser_common.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10815,7 +10815,7 @@ fn parse_unpivot_table() {
1081510815
if let Unpivot { include_nulls, .. } =
1081610816
&verified_only_select(sql_unpivot_exclude_nulls).from[0].relation
1081710817
{
10818-
assert_eq!(*include_nulls, Some(false));
10818+
assert_eq!(*include_nulls, Some(NullInclusion::ExcludeNulls));
1081910819
}
1082010820

1082110821
assert_eq!(
@@ -10831,7 +10831,7 @@ fn parse_unpivot_table() {
1083110831
if let Unpivot { include_nulls, .. } =
1083210832
&verified_only_select(sql_unpivot_include_nulls).from[0].relation
1083310833
{
10834-
assert_eq!(*include_nulls, Some(true));
10834+
assert_eq!(*include_nulls, Some(NullInclusion::IncludeNulls));
1083510835
}
1083610836

1083710837
assert_eq!(

0 commit comments

Comments
 (0)