Skip to content

Add support for INCLUDE/EXCLUDE NULLS for UNPIVOT #1849

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Vedin
Copy link
Contributor

@Vedin Vedin commented May 13, 2025

UNPIVOT structure is changed from 2023 and now supports INCLUDE or EXCLUDE NULLS.
Full syntax now looks like:

SELECT ...
FROM ...
    UNPIVOT [ { INCLUDE | EXCLUDE } NULLS ]
      ( <value_column>
        FOR <name_column> IN ( <column_list> ) )
[ ... ]

So, I added this functionality.

src/ast/query.rs Outdated
@@ -1257,6 +1257,7 @@ pub enum TableFactor {
value: Ident,
name: Ident,
columns: Vec<Ident>,
include_nulls: Option<bool>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking it would be useful to include a description of this parameter - specifically highlighting that true means include nulls and false means exclude nulls (thinking otherwise at least the latter won't be obvious API wise to a user of the library without reading the code).

Also maybe we can call this property null_treatment similar to e.g. Function vs include_nulls which only covers one possible value naming wise?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, agree. To not confuse it with null_treatment I add a new one null_inclussion. As I have checked it's used only in UNPIVOT.

@Vedin Vedin force-pushed the unpivot-improvments branch from 79c8d39 to 8e87a2c Compare May 14, 2025 14:23
@Vedin Vedin force-pushed the unpivot-improvments branch from 8e87a2c to e029450 Compare May 14, 2025 14:27
Copy link
Contributor

@iffyio iffyio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks @Vedin!
cc @alamb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants