spark-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Divya Gehlot <>
Subject [Spark -1.5.2]Dynamically creation of caseWhen expression
Date Wed, 23 Mar 2016 11:50:48 GMT
I have a map collection .
I am trying to build when condition based on the key values .
Like df.withColumn("ID", when( condition with map keys ,values of map )

How can I do that dynamically.
Currently I am iterating over keysIterator and get the values
Kal keys = myMap.keysIterator.toArray
Like below
df.withColumn("ID",when(condition on keys(0),lit(myMap get
keys(0)).when(condition on keys(1),lit(myMap get keys(1)).
when(condition on keys(2),lit(myMap get keys(3)).otherwise("value not

How can I build the above expression dynamically
Like for (key <-keys){
when(condition on key ,lit(myMap get key)
Would really appreciate the help.


View raw message