This is what I am using for two pivot column in a Dataframe where I am concatenating two columns and then doing the transpose.
// Define a udf to concatenate two passed in string values
val concat = udf( (first: String, second: String) => { first + " " + second } )
def main (args: Array[String]) {
// pivot using concatenated column
domainDF.withColumn("combColumn", concat($"col1",$"col2"))
.groupBy("someCol").pivot("combColumn").agg(count).show()
}
My requirement is make this functionality generic, so any number of columns can be passed as variable argument for concatenation. Can anyone provide any solution for the requirement? Thanks