Skip to content

feat: support multi value column unpivot & alias in unpivot #1969

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 1 commit into
base: main
Choose a base branch
from

Conversation

chenkovsky
Copy link
Contributor

for example, spark supports

SELECT * FROM sales_quarterly
    UNPIVOT EXCLUDE NULLS (
        (first_quarter, second_quarter)
        FOR half_of_the_year IN (
            (q1, q2) AS H1,
            (q3, q4) AS H2
        )
    );

https://spark.apache.org/docs/latest/sql-ref-syntax-qry-select-unpivot.html

@chenkovsky chenkovsky changed the title feat: support multi value column unpivot feat: support multi value column unpivot & alias in unpivot Jul 23, 2025
@@ -1351,9 +1392,9 @@ pub enum TableFactor {
/// See <https://docs.snowflake.com/en/sql-reference/constructs/unpivot>.
Unpivot {
table: Box<TableFactor>,
value: Ident,
value: Vec<Ident>,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

should we use expr::Identifier ? otherwise we cannot visit this ident by vistor.

@@ -11022,6 +11022,67 @@ fn parse_unpivot_table() {
verified_stmt(sql_unpivot_include_nulls).to_string(),
sql_unpivot_include_nulls
);

let sql_unpivot_with_alias = concat!(
Copy link
Contributor

Choose a reason for hiding this comment

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

@chenkovsky do you know or would you be able to check if this feature is supported by any of the dialects that the parser currently supports?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This comes from spark.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah I see, spark dialect isn't a supported by the parser currently so I'm not sure that we can merge this changes without repercussions later on e.g. if we hit scenarios with ambiguous syntax

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Spark adds some features based on Hive. We can regard it as Hive dialect.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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