spark-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paras Bansal <email2pa...@gmail.com>
Subject How to set Map values in spark/scala
Date Tue, 12 Sep 2017 16:13:50 GMT
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

Mime
View raw message