This message was deleted.
# general
s
This message was deleted.
j
Hi Sadiq, It's not straight forward, and I haven't explicitly tried this coming from JSON, but theoretically one of these two options might work: • extract array element, cast to Array datatype, and UNNEST() it • extract array element, case to MV datatype, and do a Group By on it which will automatically unnest it. Let us know if you make any progress on this ... would be interested to hear. Thanks. John
👍 1
s
Thanks, let me try with
unnest()
l
fyi, unnest won’t work with MSQ in the current Druid version (Druid 27). its merged in master, in case you are trying it out on local setups, and it should mp be out in Druid 28.
👍 1
s
what’s my option now? I was hoping for some Field flattening specifications magic
j
Hi Sadiq, Can you extract the array, then convert it to an MV, then unnest it using a Group By? The below SQL works for me ...
Copy code
select STRING_TO_MV(ARRAY_TO_STRING(array[1,2,3,4,5],','),',') key, channel, count(*)
  from wikipedia where page like '%arrio%'
group by 1, 2
s
Thanks @John Kowtko, I don’t think this will work in my case because my column is not just an array of string, it is a complex json
Actually it works
looks hacky but it works
Copy code
select JSON_QUERY(jsonObj, '$.name') name, JSON_QUERY(jsonObj, '$.chat.slack') slack
from (
  select TRY_PARSE_JSON('{' || str || '}') jsonObj
  from (
    select STRING_TO_MV(TO_JSON_STRING("value"), '},\{') str from "Submissions"
    group by 1
  )
)
j
Okay, then in that case can you try using something like STRING_TO_MV(TO_JSON_STRING(JSON_QUERY(colName, '$.path_to_array_element')), ',') and pull it out as an MV?
s
I had to use
TO_JSON_STRING
Thanks @John Kowtko for the help
🙌 1