awdavidson commented on PR #36150:
URL: https://github.com/apache/spark/pull/36150#issuecomment-1097821790
@EnricoMi FYI it could simple look something like this in `Dataset.scala`
```scala
def melt(
idColumns: Seq[String],
valueColumns: Seq[String],
valueColumnName: String,
dropNulls: Boolean = true ): DataFrame = {
val numOfValue = valueColumns.length
val exprString = valueColumns.map(e => s"'$e', $e").mkString(",")
val stackExpr = expr(s"stack($numOfValue, $exprString) AS
($valueColumnName, value)")
val stacked = select(idColumns.map(col) :+ stackExpr: _*)
if (dropNulls) {
stacked.filter(col("value").isNotNull)
} else {
stacked
}
}
def unpivot(
idColumns: Seq[String],
valueColumnName: String,
dropNulls: Boolean = true): DataFrame = {
melt(idColumns, columns.diff(idColumns).toSeq, valueColumnName,
dropNulls)
}
```
--
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]