EnricoMi commented on code in PR #36150: URL: https://github.com/apache/spark/pull/36150#discussion_r923128053
########## 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: Right, the valueType is not needed as it can be derived from `values.head.dataType` as `values` is never empty once resolved. I have reworked that: https://github.com/apache/spark/pull/36150/commits/61c8a3b36ddbbb05e8c066c05b78724eaae201cf -- 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]
