view raw
Himaprasoon Himaprasoon - 7 months ago 99
Scala Question

Scala Spark DataFrame : multiple columns given a Sequence of column names

val columnName=Seq("col1","col2",....."coln");

Is there a way to do operation to get dataframe containing only the column names specified .
I know I can do"col1","col2"...)

but the
is generated at runtime.
I could do
repeatedly for each column name in a loop.Will it have any performance overheads?. Is there any other simpler way to accomplish this?

val columnNames = Seq("col1","col2",....."coln")

// using the string column names:
val result =, columnNames.tail: _*)

// or, equivalently, using Column objects:
val result = => col(c)): _*)