EnricoMi commented on code in PR #37407:
URL: https://github.com/apache/spark/pull/37407#discussion_r981242591
##########
sql/catalyst/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBaseParser.g4:
##########
@@ -618,6 +618,46 @@ pivotValue
: expression (AS? identifier)?
;
+unpivotClause
+ : UNPIVOT nullOperator=unpivotNullClause? LEFT_PAREN
+ operator=unpivotOperator
+ RIGHT_PAREN (AS? identifier)?
+ ;
+
+unpivotNullClause
+ : (INCLUDE | EXCLUDE) NULLS
+ ;
+
+unpivotOperator
+ : (unpivotSingleValueColumnClause | unpivotMultiValueColumnClause)
+ ;
+
+unpivotSingleValueColumnClause
+ : unpivotValueColumn FOR unpivotNameColumn IN LEFT_PAREN
unpivotColumns+=unpivotColumn (COMMA unpivotColumns+=unpivotColumn)* RIGHT_PAREN
+ ;
+
+unpivotMultiValueColumnClause
+ : LEFT_PAREN unpivotValueColumns+=unpivotValueColumn (COMMA
unpivotValueColumns+=unpivotValueColumn)* RIGHT_PAREN
+ FOR unpivotNameColumn
+ IN LEFT_PAREN unpivotColumnSets+=unpivotColumnSet (COMMA
unpivotColumnSets+=unpivotColumnSet)* RIGHT_PAREN
+ ;
+
+unpivotColumnSet
+ : LEFT_PAREN unpivotColumns+=unpivotColumn (COMMA
unpivotColumns+=unpivotColumn)* RIGHT_PAREN (AS? identifier)?
Review Comment:
Have have to come back to this:
It looks like Oracle and BigQuery allow for these aliases:
```sql
SELECT * FROM table UNPIVOT (
val for var in (col1 AS alias1, col2 AS alias2)
)
```
and
```sql
SELECT * FROM table UNPIVOT (
(val1, val2) for var in ((col1, col2) AS alias1, (col3, col4) AS alias2)
)
```
but still not
```sql
SELECT * FROM table UNPIVOT (
(val1, val2) for var in ((col1 AS aliasA, col2 AS aliasB) AS alias1, (col3
AS aliasC, col4 AS aliasD) AS alias2)
)
```
(which was your original question).
https://docs.oracle.com/cd/B28359_01/server.111/b28286/statements_10002.htm#SQLRF55133
https://blogs.oracle.com/sql/post/how-to-convert-rows-to-columns-and-back-again-with-sql-aka-pivot-and-unpivot
https://hevodata.com/learn/bigquery-columns-to-rows/#u1
I'll add the former alias again.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]