You can use the function udfto combine all columnsinto one. All you have to do is define the function udfand pass all columnsthat you want to execute with the function udfand call the function udfusing the function.withColumn dataframe
Or
You can use the function concat_ws(java.lang.String sep, Column... exprs)available for dataframe.
var df = Seq(("qwertyuiop",0,0,16102.0,0))
.toDF("agentName","original_dt","parsed_dt","user","text")
df.withColumn("newCol", concat_ws(",",$"agentName",$"original_dt",$"parsed_dt",$"user",$"text"))
df.show(false)
Gives you the result as
+----------+-----------+---------+-------+----+------------------------+
|agentName |original_dt|parsed_dt|user |text|newCol |
+----------+-----------+---------+-------+----+------------------------+
|qwertyuiop|0 |0 |16102.0|0 |qwertyuiop,0,0,16102.0,0|
+----------+-----------+---------+-------+----+------------------------+
This will give you the result you want
source
share