EnricoMi commented on code in PR #37407:
URL: https://github.com/apache/spark/pull/37407#discussion_r983396003
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala:
##########
@@ -1098,6 +1106,87 @@ class AstBuilder extends
SqlBaseParserBaseVisitor[AnyRef] with SQLConfHelper wit
}
}
+ /**
+ * Add an [[Unpivot]] to a logical plan.
+ */
+ private def withUnpivot(
+ ctx: UnpivotClauseContext,
+ query: LogicalPlan): LogicalPlan = withOrigin(ctx) {
+ // this is needed to create unpivot and to filter unpivot for nulls
further down
+ val valueColumnNames =
+ Option(ctx.unpivotOperator().unpivotSingleValueColumnClause())
+ .map(_.unpivotValueColumn().identifier().getText)
+ .map(Seq(_))
+ .getOrElse(
+ Option(ctx.unpivotOperator().unpivotMultiValueColumnClause())
+ .map(_.unpivotValueColumns.asScala.map(_.identifier().getText).toSeq)
+ .get
+ )
+
+ val unpivot = if (ctx.unpivotOperator().unpivotSingleValueColumnClause()
!= null) {
+ val unpivotClause =
ctx.unpivotOperator().unpivotSingleValueColumnClause()
+ val variableColumnName =
unpivotClause.unpivotNameColumn().identifier().getText
+ val unpivotColumns =
unpivotClause.unpivotColumns.asScala.map(visitUnpivotColumn).toSeq
+
+ Unpivot(
+ None,
+ Some(unpivotColumns.map(Seq(_))),
Review Comment:
Done in 70f986a.
I think the error message needs some improvement, it is likely not clear to
users what is meant with `Attribute`:
"UNPIVOT requires given {given} to be Attributes when no {empty} are
given: [<types>]"
Maybe `column names` is better.
--
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]