dreddy dreddy - 1 month ago 7
Scala Question

scala add a string in the mapper

Hi I have the following code that gets each column and produces a string separated by commas.

val selectCols = t.columns.map( c => cmap.getOrElse(c.name, c.name)).mkString(",")

Output: store_id,date_id,user_id,data,other_column


But I would like to modify this map function to get the following string:

t.store_id,t.date_id,t.user_id,t.data,t.other_column


Any help is appreciated.

Answer
val selectCols    = t.columns.map( c => cmap.getOrElse(c.name, c.name))
.map(c => s"t.$c")
.mkString(",")
Comments