I am doing some testing for spark using scala. We usually read json files which needs to be manipulated like the following example:
test.json:
{"a":1,"b":[2,3]}
val test = sqlContext.read.json("test.json")
How can I convert it to the following format:
{"a":1,"b":2}
{"a":1,"b":3}
explode is often suggested, but it's from the untyped DataFrame API and given you use Dataset, I think flatMap operator might be a better fit (see org.apache.spark.sql.Dataset).
You could use it as follows:
You can use
explode
function: