Skip to content
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

Fix(spark): unqualify columns in PIVOT expressions #1572

Merged
merged 2 commits into from
May 9, 2023

Conversation

georgesittas
Copy link
Collaborator

Spark doesn't seem to allow qualified columns inside of the PIVOT operator's "field" arg (i.e. FOR .. IN (...)):

spark-sql (default)> WITH x(a, b) AS (SELECT * FROM VALUES (1, 2)) SELECT * FROM x PIVOT (SUM(a) FOR b IN (2 AS col));
col
1
Time taken: 0.411 seconds, Fetched 1 row(s)
spark-sql (default)> WITH x(a, b) AS (SELECT * FROM VALUES (1, 2)) SELECT * FROM x PIVOT (SUM(x.a) FOR x.b IN (2 AS col));

[PARSE_SYNTAX_ERROR] Syntax error at or near '.'.(line 1, pos 83)

== SQL ==
WITH x(a, b) AS (SELECT * FROM VALUES (1, 2)) SELECT * FROM x PIVOT (SUM(x.a) FOR x.b IN (2 AS col))
-----------------------------------------------------------------------------------^^^

spark-sql (default)> WITH x(a, b) AS (SELECT * FROM VALUES (1, 2)) SELECT * FROM x PIVOT (SUM(x.a) FOR b IN (2 AS col));
col
1
Time taken: 0.52 seconds, Fetched 1 row(s)

This may be a bug in Spark.

@tobymao tobymao merged commit 34d99ab into main May 9, 2023
@tobymao tobymao deleted the jo/unqualify_pivot_columns branch May 9, 2023 15:55
adrianisk pushed a commit to adrianisk/sqlglot that referenced this pull request Jun 21, 2023
* Fix(spark): unqualify columns in PIVOT expressions

* Only transform 'field' instead of the whole pivot expression
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