1

I want to concatenate columns of my Dataframe. I wrote a Udf to achieve that but as I can see concat_ws expects columns while I'm passing it Array[String]. How should I pass columns of my DataFrame correctly?

val columns = salesDF.columns
val concatColumns = udf((arr: Seq[String]) => arr.mkString(" "))

salesDF.select(concat_ws(",", concatColumns(columns)))
0

1 Answer 1

3

You will just need to pass the selection as an Array[Column]:

import org.apache.spark.sql.functions.{col,concat_ws}

val selection = salesDF.columns.map(col)
salesDF.select(concat_ws(",", selection : _*))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.