I'm new to Scala and Spark and I'm struggling to do the following, I'm trying to convert a Seq into a Map and at the same time, modify the value when I'm converting the sequence by adding a "_suffix" like so:
val columns = Seq($"col2",$"col3")
val map = columns.map(t => t.toString() -> t.toString()+"_suffix").toMap
However, I'm getting the following error:
scala> val map = columns.map(t => t.toString() -> t.toString()+"_suffix").toMap
<console>:25: error: Cannot prove that String <:< (T, U).
val map = columns.map(t => t.toString() -> t.toString()+"_suffix").toMap
Furthermore, the .map
result returns the following:
scala> val map = columns.map(t => t.toString() -> t.toString()+"_suffix")
map: Seq[String] = List((col2,col2)_suffix, (col3,col3)_suffix)
And this is what I'm trying to produce:
map: Seq[(String, String)] = List((col2,col2_suffix), (col3,col3_suffix)
So I can ultimately convert it into a Map:
map: scala.collection.immutable.Map[String,String] = Map(col2 -> col2_suffix, col3 -> col3_suffix)
I'm pretty stuck trying to achieve this, any advice?