"events": {
"a": {
"eventName": "a",
"eventIdentifier": "abc"
},
"b": {
"eventName": "b",
"eventIdentifier": "xyz"
}
}
I want to split events "a" and "b" into 2 different records using spark sql only and above json should not in array.
Output:
+---------+-------------------+
|eventname|eventidentifier |
+---------+-------------------+
|a |abc |
|b |xyz |
+---------+-------------------+
2
Answers
To split the events "a" and "b" into two separate records using Spark SQL, you can use the explode function to transform the JSON structure. Here’s a way to achieve this:
}
}
Use
array
to create rows &inline
functions to flatten or explode array of rows.Logic –
inline(array(events.*))
OR