Hi there,
What is the proper way to UNNEST a JSON array? I have following JSON structure saved in a raw column of my table :
{
"post_id": "1",
"mentioned_users": [
{
"user_id": "B"
},
{
"user_id": "C"
}
]
}
I would like to convert it in a table like like so:
| post_id |
mentioned_user_id |
| 1 |
B |
| 1 |
C |
I have something like this that works:
MODEL (
name mentions.full_model,
kind FULL,
cron '@daily',
grain ('post_id', 'mentioned_user_id')
);
SELECT
raw.post_id AS `post_id`,
mentioned_user.user_id as `mentioned_user_id`
FROM posts.seed_model AS raw,
UNNEST(CAST(JSON_EXTRACT(raw, '$.mentioned_users') AS ARRAY<STRUCT<user_id STRING>>)) AS mentioned_user
But the lineage is not working properly for the mentioned_user_id column. When I select it the column greys out and a new mentioned_user columns appear with the lineage on the UNNEST line. Is this the best I can get?
Hi there,
What is the proper way to UNNEST a JSON array? I have following JSON structure saved in a
rawcolumn of my table :I would like to convert it in a table like like so:
I have something like this that works:
But the lineage is not working properly for the
mentioned_user_idcolumn. When I select it the column greys out and a newmentioned_usercolumns appear with the lineage on the UNNEST line. Is this the best I can get?