cloud-fan commented on code in PR #37407:
URL: https://github.com/apache/spark/pull/37407#discussion_r981213360
##########
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:
How can we make sure these value columns will end up with `Attribute`?
--
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]