cloud-fan commented on code in PR #36150:
URL: https://github.com/apache/spark/pull/36150#discussion_r923029449
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/basicLogicalOperators.scala:
##########
@@ -1245,6 +1245,44 @@ case class Pivot(
override protected def withNewChildInternal(newChild: LogicalPlan): Pivot =
copy(child = newChild)
}
+/**
+ * A constructor for creating an Unpivot, which will later be converted to an
[[Expand]]
+ * during the query analysis.
+ *
+ * An empty values array will be replaced during analysis with all resolved
outputs of child except
+ * the ids. This expansion allows to easily unpivot all non-id columns.
+ *
+ * @see `org.apache.spark.sql.catalyst.analysis.Analyzer.ResolveUnpivot`
+ *
+ * The type of the value column is derived from all value columns during
analysis once all values
+ * are resolved. All values' types have to be compatible, otherwise the result
value column cannot
+ * be assigned the individual values and an AnalysisException is thrown.
+ *
+ * @see
`org.apache.spark.sql.catalyst.analysis.TypeCoercionBase.UnpivotCoercion`
+ *
+ * @param ids Id columns
+ * @param values Value columns to unpivot
+ * @param variableColumnName Name of the variable column
+ * @param valueColumnName Name of the value column
+ * @param valueType Type of value column once known
+ * @param child Child operator
+ */
+case class Unpivot(
+ ids: Seq[NamedExpression],
+ values: Seq[NamedExpression],
+ variableColumnName: String,
+ valueColumnName: String,
+ valueType: Option[DataType],
Review Comment:
I think this does not bring more information to the logical plan, but more
of a bool flag to indicate if type coercion has been done or not. A simpler
idea is to have a method
```
def valuesTypeCoercioned: Boolean = values.forall(_.resolved) &&
values.nonEmpty && {
values.tail.foreall(v => v.dataType.sameType(values.head.dataType))
}
```
--
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]