I have string of columns and they are grouped by they purpose etc address cols and personal info cols.
val columns="address:addressLine,address:city,address:state,address:zipCode,person:firstName,person:lastName,person:middleName"
I wanted them to be arranged like that:
lastName->person,zipCode->address
So every pair like lastName->person would be a Map. I wanted these Maps to be placed inside another Map, like that:
columnSchema -> {
lastName->person,
zipCode->address
}
So it would be Map[String,Map[String,String]]
I started by doing it like that:
columns.split(",").map(_.split(":")).map(x=>Map(x(1)->x(0)))
What I got is:
Array[scala.collection.immutable.Map[String,String]] = Array(Map(addressLine -> address), Map(city -> address), Map(state -> address), Map(zipCode -> address), Map(firstName -> person), Map(lastName -> person), Map(middleName -> person))
So I got an Array[Map[String,String]]. How could I make it a Map[String,Map[String,String]]? I tried to do it like:
Map("columnSchema" -> columns.split(",").map(_.split(":")).map(x=>Map(x(1)->x(0))))
However it still returns an array of Maps:
scala.collection.immutable.Map[String,Array[scala.collection.immutable.Map[String,String]]]
How to get rid of an Array? Thanks!