@@ -10746,49 +10746,47 @@ fn parse_unpivot_table() {
1074610746 "SELECT * FROM sales AS s ",
1074710747 "UNPIVOT(quantity FOR quarter IN (Q1, Q2, Q3, Q4)) AS u (product, quarter, quantity)"
1074810748 );
10749-
10750- pretty_assertions::assert_eq!(
10751- verified_only_select(sql).from[0].relation,
10752- Unpivot {
10753- table: Box::new(TableFactor::Table {
10754- name: ObjectName::from(vec![Ident::new("sales")]),
10755- alias: Some(TableAlias {
10756- name: Ident::new("s"),
10757- columns: vec![]
10758- }),
10759- args: None,
10760- with_hints: vec![],
10761- version: None,
10762- partitions: vec![],
10763- with_ordinality: false,
10764- json_path: None,
10765- sample: None,
10766- index_hints: vec![],
10749+ let base_unpivot = Unpivot {
10750+ table: Box::new(TableFactor::Table {
10751+ name: ObjectName::from(vec![Ident::new("sales")]),
10752+ alias: Some(TableAlias {
10753+ name: Ident::new("s"),
10754+ columns: vec![],
1076710755 }),
10768- value: Ident {
10769- value: "quantity".to_string(),
10770- quote_style: None,
10771- span: Span::empty()
10772- },
10756+ args: None,
10757+ with_hints: vec![],
10758+ version: None,
10759+ partitions: vec![],
10760+ with_ordinality: false,
10761+ json_path: None,
10762+ sample: None,
10763+ index_hints: vec![],
10764+ }),
10765+ null_inclusion: None,
10766+ value: Ident {
10767+ value: "quantity".to_string(),
10768+ quote_style: None,
10769+ span: Span::empty(),
10770+ },
1077310771
10774- name: Ident {
10775- value: "quarter".to_string(),
10776- quote_style: None,
10777- span: Span::empty()
10778- },
10779- columns: ["Q1", "Q2", "Q3", "Q4"]
10772+ name: Ident {
10773+ value: "quarter".to_string(),
10774+ quote_style: None,
10775+ span: Span::empty(),
10776+ },
10777+ columns: ["Q1", "Q2", "Q3", "Q4"]
10778+ .into_iter()
10779+ .map(Ident::new)
10780+ .collect(),
10781+ alias: Some(TableAlias {
10782+ name: Ident::new("u"),
10783+ columns: ["product", "quarter", "quantity"]
1078010784 .into_iter()
10781- .map(Ident::new )
10785+ .map(TableAliasColumnDef::from_name )
1078210786 .collect(),
10783- alias: Some(TableAlias {
10784- name: Ident::new("u"),
10785- columns: ["product", "quarter", "quantity"]
10786- .into_iter()
10787- .map(TableAliasColumnDef::from_name)
10788- .collect(),
10789- }),
10790- }
10791- );
10787+ }),
10788+ };
10789+ pretty_assertions::assert_eq!(verified_only_select(sql).from[0].relation, base_unpivot);
1079210790 assert_eq!(verified_stmt(sql).to_string(), sql);
1079310791
1079410792 let sql_without_aliases = concat!(
@@ -10808,6 +10806,38 @@ fn parse_unpivot_table() {
1080810806 verified_stmt(sql_without_aliases).to_string(),
1080910807 sql_without_aliases
1081010808 );
10809+
10810+ let sql_unpivot_exclude_nulls = concat!(
10811+ "SELECT * FROM sales AS s ",
10812+ "UNPIVOT EXCLUDE NULLS (quantity FOR quarter IN (Q1, Q2, Q3, Q4)) AS u (product, quarter, quantity)"
10813+ );
10814+
10815+ if let Unpivot { null_inclusion, .. } =
10816+ &verified_only_select(sql_unpivot_exclude_nulls).from[0].relation
10817+ {
10818+ assert_eq!(*null_inclusion, Some(NullInclusion::ExcludeNulls));
10819+ }
10820+
10821+ assert_eq!(
10822+ verified_stmt(sql_unpivot_exclude_nulls).to_string(),
10823+ sql_unpivot_exclude_nulls
10824+ );
10825+
10826+ let sql_unpivot_include_nulls = concat!(
10827+ "SELECT * FROM sales AS s ",
10828+ "UNPIVOT INCLUDE NULLS (quantity FOR quarter IN (Q1, Q2, Q3, Q4)) AS u (product, quarter, quantity)"
10829+ );
10830+
10831+ if let Unpivot { null_inclusion, .. } =
10832+ &verified_only_select(sql_unpivot_include_nulls).from[0].relation
10833+ {
10834+ assert_eq!(*null_inclusion, Some(NullInclusion::IncludeNulls));
10835+ }
10836+
10837+ assert_eq!(
10838+ verified_stmt(sql_unpivot_include_nulls).to_string(),
10839+ sql_unpivot_include_nulls
10840+ );
1081110841}
1081210842
1081310843#[test]
@@ -10904,6 +10934,7 @@ fn parse_pivot_unpivot_table() {
1090410934 sample: None,
1090510935 index_hints: vec![],
1090610936 }),
10937+ null_inclusion: None,
1090710938 value: Ident {
1090810939 value: "population".to_string(),
1090910940 quote_style: None,
0 commit comments