I have a dataframe origMap with a column that is of type map. I want to add more entries to that map
I'm doing following that's working:
val origMap = df("mapping")
val tempMap = tempDFFields.flatMap(tempField => Array(lit(tempField), tempDF(tempField))): _*)
origMap.withColumn("mapping", tempMap.union(origMap))
tempDFFields is list of column names in tempDF.
I'm creating a map of all colname->colvalue from tempDF and want to add it to original DF. It complains that I'm passing array of Column instead of single instance of Column. how can I pass single instance of column here .. I just want to update the map and store it back.
Example:
Input
origDF
+--------+-----------------------------
|id | amount | mapping |
|1 | 10 | {a=b, c=d} |
|3 | 90 | {e=f, g=h} |
tempDF
+-----
|Id |
|1 |
output: origDF
+--------+-----------------------------
|id | amount | mapping |
|1 | 10 | {a=b, c=d, id=1} |
|3 | 90 | {e=f, g=h, id=1} |
tempDFIdcontains value 1, 2 and 3.