-1

If I have a Array[String] that contains the columns I need to use in select() function, how I can apply them in the most designed way?

.select(from_json(col("value").cast("string"), schema).as("data"), col("oneColumn"))

I'd like to put several columns with names from the array in the place of col("oneColumn")

ANswers from here can't help me, as they deal with Lists of Strings, while I already have a Column object and can't apply collection of columns as a parameter of select()

Eljah
  • 4,188
  • 4
  • 41
  • 85

1 Answers1

0

preparing list of columns

val cols: List[Column] = headers.toList.map(name => col(name))
val cols1 = cols :+ from_json(col("value").cast("string"), schema).as("data")

and then

   .select(cols1: _*)
Eljah
  • 4,188
  • 4
  • 41
  • 85