I have a dataframe structure as shown below:
+----+----+--------------------+
|col1|col2|col3 |
+----+----+--------------------+
|1 |2 |{"key1" : "val1"} |
|3 |4 |{"key2" : "val2"} |
+----+----+--------------------+
col3 is a Json String. I would like to add another column to the dataframe that will convert col3 to a MAP. Something like this:
+----+----+--------------------+----------------+
|col1|col2|col3 |col4 |
+----+----+--------------------+----------------+
|1 |2 |{"key1" : "val1"} |[key1 -> val1] |
|3 |4 |{"key2" : "val2"} |[key2 -> val2] |
+----+----+--------------------+----------------+
My Scala code snippet is something like this:
val df: DataFrame = getRowDataset(payload, schema, "payload") // df is represented by the first column
df.withColumn("col4", "<>") // <What do I need to do here?>
How am I supposed to implement this with Scala?
val df2 = df.withColumn("map_data", from_json((df("crawl_request")), mappingSchema)). This works as expected.