How to set Map values in spark/scala

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

How to set Map values in spark/scala

paras301

Hello,

I am new to spark-scala development. I am trying to create map values in spark using scala but getting nothing printed

def createMap() : Map[String, Int] = {
var tMap:Map[String, Int] = Map()
val tDF = spark.sql("select a, b, c from temp")
for (x <- tDF) {
  val k = x.getAs[Long](0) + "|" + x.getAs[Long](1)
  val v = x.getAs[Int](2)
  tMap += ( k -> v )
  println( k -> v ) ///----------This print values
}
println("Hellllooooooooo1")
for ((k,v) <- tMap) println("key = " + k+ ", value= " + v) ////------This prints nothing
println("Hellllooooooooo2")
return tMap
}

Please suggest.

I have posted the same at: https://stackoverflow.com/questions/46181071/how-to-set-map-values-in-spark-scala

Thank you,
Paras