动态 JSON 可以按原样轻松加载到 Snowflake 中。在您的示例中,对于可变长度数组,您可以使用 FLATTEN() 将单行 JSON 分解为查询中的多行。在这种情况下,我建议您也将其作为 JSON 保留在数据湖中。
此类事情的惩罚相对较低,因为 JSON 数据不只是存储为长字符串;取而代之的是,Snowflake 在内部分析加载的 JSON,并采取措施帮助快速查询,例如为您的示例中的 $.Job_Profile_Reference 和 $.Job_Profile_Reference.ID 等频繁路径创建虚拟列。
with semistructured as (select parse_json('{"Job_Profile_Reference": {"ID": [{"@type": "WI","__text": "4acf03b2e8e301fab3caeab105020f"},{"@type": "Job_Profile_ID","__text": "112"}]}}') json)
select * from semistructured, lateral flatten(json, recursive=>True) structured;
JSON SEQ KEY PATH INDEX VALUE THIS
{ "Job_Profile_Reference": { "ID": [ { "@type": "WI", "__text": "4acf03b2e8e301fab3caeab105020f" }, { "@type": "Job_Profile_ID", "__text": "112" } ] } } 1 Job_Profile_Reference Job_Profile_Reference { "ID": [ { "@type": "WI", "__text": "4acf03b2e8e301fab3caeab105020f" }, { "@type": "Job_Profile_ID", "__text": "112" } ] } { "Job_Profile_Reference": { "ID": [ { "@type": "WI", "__text": "4acf03b2e8e301fab3caeab105020f" }, { "@type": "Job_Profile_ID", "__text": "112" } ] } }
{ "Job_Profile_Reference": { "ID": [ { "@type": "WI", "__text": "4acf03b2e8e301fab3caeab105020f" }, { "@type": "Job_Profile_ID", "__text": "112" } ] } } 1 ID Job_Profile_Reference.ID [ { "@type": "WI", "__text": "4acf03b2e8e301fab3caeab105020f" }, { "@type": "Job_Profile_ID", "__text": "112" } ] { "ID": [ { "@type": "WI", "__text": "4acf03b2e8e301fab3caeab105020f" }, { "@type": "Job_Profile_ID", "__text": "112" } ] }
{ "Job_Profile_Reference": { "ID": [ { "@type": "WI", "__text": "4acf03b2e8e301fab3caeab105020f" }, { "@type": "Job_Profile_ID", "__text": "112" } ] } } 1 Job_Profile_Reference.ID[0] 0 { "@type": "WI", "__text": "4acf03b2e8e301fab3caeab105020f" } [ { "@type": "WI", "__text": "4acf03b2e8e301fab3caeab105020f" }, { "@type": "Job_Profile_ID", "__text": "112" } ]
{ "Job_Profile_Reference": { "ID": [ { "@type": "WI", "__text": "4acf03b2e8e301fab3caeab105020f" }, { "@type": "Job_Profile_ID", "__text": "112" } ] } } 1 @type Job_Profile_Reference.ID[0]['@type'] "WI" { "@type": "WI", "__text": "4acf03b2e8e301fab3caeab105020f" }
{ "Job_Profile_Reference": { "ID": [ { "@type": "WI", "__text": "4acf03b2e8e301fab3caeab105020f" }, { "@type": "Job_Profile_ID", "__text": "112" } ] } } 1 __text Job_Profile_Reference.ID[0].__text "4acf03b2e8e301fab3caeab105020f" { "@type": "WI", "__text": "4acf03b2e8e301fab3caeab105020f" }
{ "Job_Profile_Reference": { "ID": [ { "@type": "WI", "__text": "4acf03b2e8e301fab3caeab105020f" }, { "@type": "Job_Profile_ID", "__text": "112" } ] } } 1 Job_Profile_Reference.ID[1] 1 { "@type": "Job_Profile_ID", "__text": "112" } [ { "@type": "WI", "__text": "4acf03b2e8e301fab3caeab105020f" }, { "@type": "Job_Profile_ID", "__text": "112" } ]
{ "Job_Profile_Reference": { "ID": [ { "@type": "WI", "__text": "4acf03b2e8e301fab3caeab105020f" }, { "@type": "Job_Profile_ID", "__text": "112" } ] } } 1 @type Job_Profile_Reference.ID[1]['@type'] "Job_Profile_ID" { "@type": "Job_Profile_ID", "__text": "112" }
{ "Job_Profile_Reference": { "ID": [ { "@type": "WI", "__text": "4acf03b2e8e301fab3caeab105020f" }, { "@type": "Job_Profile_ID", "__text": "112" } ] } } 1 __text Job_Profile_Reference.ID[1].__text "112" { "@type": "Job_Profile_ID", "__text": "112" }```