I am new to Spark and have one requirement to remove the key from nested map.
root
|-- property: map (nullable = true)
| |-- name: string
| |-- address: map (valueContainsNull = true)
| | |-- State: string
| | |-- pincode: string (valueContainsNull = true)
Sample code:
val unwantedKey : String = "State"
def updateMap(unwantedKey : String) = udf((colMapName:Map[String,Map[String, String]]) => {colMapName.-(unwantedKey)})
val FinalDF = df2.withColumn("address",updateMap(unwantedKey)(col("address")))