Sample json document:
{
"chats": [
{
"chatID": 123,
"agentComments": "[{\"agentID\":\"agent1\", \"queueID\":\"queue1\", \"comment\":\"Visitor's query not relevant for this queue.\"}, {\"agentID\":\"agent2\", \"queueID\":\"queue2\", \"comment\":\"Resolved\"}]"
}
]
}
Result required:
+---------+---------+-----------------------------------------------+ | chatID | agentID | Comment | +---------+---------+-----------------------------------------------+ | 123 | agent1 | visitor's query not relevant for this queue. | | 123 | agent2 | Resolved | +---------+---------+-----------------------------------------------+
Value for agentComments in the sample document given above is a stringified JSON. Had it been a JSONArray, above result could be obtained using something like
select B.chatID, B.agent.agentID agentID, B.agent.comment comment from (select A.chat.chatID chatID, flatten(A.chat.agentComments) agent from (select flatten(chats) chat from dfs.`/tmp/test.json`)A)B;
Please share a sample user defined function, in the context of apache drill, that works similar to JSON.parse available in Javascript.