如何在雪花中解析这个json
{
"segmentId": "b204c220-ea8d-4cf4-b579-30eb59a1a2a4",
"diffFields": [
{
"fieldName": "name",
"valueBefore": null,
"valueAfter": "new-segment-name"
},
{
"fieldName": "active",
"valueBefore": null,
"valueAfter": true
}
]
}
在上面的JSON中,我有一个difffields
的数组。我试图在雪花上解析此列,而不是行阵列而不是行。 我尝试了变平,但这将其弄平为行。
我试图在DBT中解析此此表,以创建上面的JSON,其表结构为
create table some_table (
field_one,
--if `name` is present in the above json I want that to be 2nd column
-- if `active` is present in the above json i want that to be 3nd column
)
)
{
"segmentId": "b204c220-ea8d-4cf4-b579-30eb59a1a2a4",
"diffFields": [
{
"fieldName": "name",
"valueBefore": null,
"valueAfter": "new-segment-name"
},
{
"fieldName": "active",
"valueBefore": null,
"valueAfter": true
}
]
}
In the above json I have an array of diffFields
. I am trying to parse this in snowflake get the array of columns instead of rows.
I tried flatten, but this flatten it as rows.
I am trying to parse this in dbt to create another table from the above json with table structure as
create table some_table (
field_one,
--if `name` is present in the above json I want that to be 2nd column
-- if `active` is present in the above json i want that to be 3nd column
)
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我会像以下情况下给它那样的弄平
seg_id
)空。因此,您想使用 is_null_value 测试和covert 要
选择数组零件:
json
I would flatten it like
which gives:
but those variant data nulls are not real nulls. so you want to use something like is_null_value to test and covert to real nulls
To select array parts:
gives:
您可以使用QuickTable连接雪花并进行JSON PARSE使用QuickTable。 QuickTable可以生成与雪花兼容的相关SQL。
You can use QuickTable to connect snowflake and do JSON parse use QuickTable. QuickTable can generate related SQL that is compatible with Snowflake.