我有两个不同的结构化 json 文件从雪管中输入。唯一的区别是它有许多嵌套数组,而不是嵌套字典。我试图弄清楚如何将结构 1转换为一个最终表格。我已成功将结构 2转换为表格并包含以下代码。
我知道我需要使用横向展平,但没有成功。
**Structure 1: Nested Arrays (Need help on)**
This json lives within a table and in column **JSONTEXT**
[
{
"ID": "xxx-xxxx-xxxx xxx-xxx",
"caseTypeID": "xx-xxxx-xxxx-xxxxx",
"content": {
"AccountID": "xx-xxxxx-xxxx-xxxx xxxx-xxxxx",
"AccountName": "XXXX",
"Address": {
"pxObjClass": "Data-Address-Postal"
},
"Addresses": [],
"AllKickoffsComplete": "true",
"BillingContactList": [],
"ClientCurrency": "USD",
"ClientID": "XXXXXX",
"ClientNSID": "XXXXXXXX-00",
"ClientName": "XXXXX XXXX Inc.",
"CompanyPhoneNumber": "XXX-XXX-XXXX",
"CrmSearchOrg": "XXXX",
"EEList": [
{
"AccountID": "xxx-xxxxx-xxxx-xxxxx xxxx-xxxxx",
"AccountName": "XXXX",
"AllowanceList": [
{
"AllowanceAmount": "327",
"AllowanceName": "Car Allowance",
"pxObjClass": "xxxxx-xxxxx-xxxxx"
]
结构 2:嵌套字典 此 json 存在于表和列JSONTEXT中
[
{
"OppID": "xxxx-xxxxx",
"pxObjClass": "xx-xxxxx-xxxx-xxxxxx",
"pxPages": {
"EEList": {
"Country": "xxx",
"CountryName": "xxx",
"Currency": "xxx",
"EstimatedICPCost": "xxxxxxxxxxx",
"ICPCurrency": "xxxxx",
"ICPID": "xxxxxxxxx.",
"ICPNSID": "xxxx-xx",
"ICPName": "xxx xx xx.",
"LocalMonthlySalary": "xxxxxx",
"MinFee": "xxxx",
"MonthlyGrossCost": "xxxxx",
"NewOrRepeatCustomer": "xxxxx",
"OppCloseDate": "xxx-xxx-xx",
"OppID": "xxx-xxxx",
"OpportunityName": "xxx - xxx xxx - xxx - xxxx",
"ReferralSource": "xxxxxx",
"pxObjClass": "Index-xx-xxxx-xxxx-xxxxxx",
"pxSubscript": "EEList"
}
},
"pyID": "xxxxxx",
"pzInsKey": "xxxx-xxxx-xxxx xxxxx-xxx"
},
]
这是我的第二个有效结构的代码。
create or replace table xxxx
as select
value:ID::varchar as ID,
value:caseTypeID::varchar as caseTypeID,
value:content:AccountID::varchar as AccountID,
value:content:AccountName::varchar as AccountName,
value:content:AllKickoffsComplete::boolean as AllKickoffsComplete,
value:content:ClientCurrency::varchar as ClientCurrency,
value:content:ClientID::varchar as ClientID,
value:content:ClientNSID::varchar as ClientNSID,
value:content:ClientName::varchar as ClientName,
value:content:CompanyAddressCountryName::varchar as CompanyAddressCountryName,
value:content:CompanyPhoneNumber::varchar as CompanyPhoneNumber,
value:content:CreateNew::boolean as CreateNew,
value:content:CrmSearchOrg::varchar as CrmSearchOrg,
value:content:EEList:AccountID::varchar as EE_AccountID,
value:content:EEList:AccountName::varchar as EE_AccountName
from new_raw_json,
lateral flatten (input =>jsontext);
这是我尝试过的代码,它仅在您放置 jsontext[Nth] 时才有效。
select
value:ID::varchar as ID,
value:EEListID::varchar as EEListID,
value:caseTypeID::varchar as caseTypeID
from new_raw_json,
lateral flatten (input => jsontext[0]:content:EEList);
感谢任何帮助!