繁体   English   中英

在雪花中查询/解析嵌套的 JSON

[英]querying/parsing nested JSON in snowflake

我有一个表格,在每一行中存储如下文件,我希望能够解析/展平这个文件 - 问题是对于嵌套文件(历史、经销商、车辆),当我使用lateral flatten时,我收到 NULL lateral flatten评论。 有人可以帮我理解我应该如何正确解析这个文件吗?

{
  "auction_ends_at": "2020-10-22T15:32:55.155330",
  "bid_history": [],
  "created_at": "2020-10-22T11:55:03.154852",
  "dealer": {},
  "external_id": "PE28537",
  "highest_bidder": null,
  "history": [
    "d4c48842-07ef-418c-94db-971e0625e9e3",
    "7cf6f349-09e6-420d-ab8f-9f94395e87b6",
    "325f2283-527f-4101-8366-baface5f0009",
    "6bae782c-3bdd-4d58-9839-f4a9d4e25e49",
    "e7358eed-0c0e-412c-a9cd-52036fcd7893"
  ],
  "meta": null,
  "price": 8500,
  "price_currency": "EURO",
  "requires_scheduling": true,
  "reserve_price": 9137,
  "start_price": null,
  "transport_distance": null,
  "transport_fee": null,
  "updated_at": "2020-10-22T11:55:03.155402",
  "url": "https://www.XXXX.com/en/app/merchant/car/PE28537",
  "vehicle": {
    "additional_equipment": null,
    "additional_info": null,
    "airbags": null,
    "availability": null,
    "body": null,
    "body_condition": null,
    "category": null,
    "climatisation": null,
    "co2_emission_g_km": null,
    "color": "green",
    "color_manufacturer": null,
    "construction_year": null,
    "created_at": "2020-10-22T11:55:03.155249",
    "cubic_capacity": null,
    "current_location": "DE, Kitzingen",
    "defects": null,
    "emission_class": null,
    "emission_sticker": null,
    "equipment": null,
    "external_id": null,
    "extras": null,
    "first_registration": "07/2017",
    "fuel_consumption_l_100km": null,
    "fuel_type": "diesel",
    "horse_power": 105,
    "id": null,
    "interior_design": null,
    "label": "Fabia 1.4 TDI Ambition",
    "last_inspection": null,
    "make": "Skoda",
    "meta": null,
    "mileage_in_km": 58128,
    "model": "Fabia",
    "num_car_seats": null,
    "num_doors": null,
    "num_owners": null,
    "origin": null,
    "parking_sensors": null,
    "pdf_details_url": null,
    "price": null,
    "price_currency": null,
    "transmission": "manual",
    "updated_at": "2020-10-22T11:55:03.155530",
    "url": null,
    "vin": null
  }
}

我写了一个查询列表:

select v.* from json_data,
lateral flatten( input=>j) v;

如我所见,经销商没有记录,所以可以得到一个NULL。 对于历史,我得到以下数组:

[
  "d4c48842-07ef-418c-94db-971e0625e9e3",
  "7cf6f349-09e6-420d-ab8f-9f94395e87b6",
  "325f2283-527f-4101-8366-baface5f0009",
  "6bae782c-3bdd-4d58-9839-f4a9d4e25e49",
  "e7358eed-0c0e-412c-a9cd-52036fcd7893"
]

车辆返回 object:

{
  "additional_equipment": null,
  "additional_info": null,
  "airbags": null,
  "availability": null,
  "body": null,
  "body_condition": null,
  "category": null,
  "climatisation": null,
  "co2_emission_g_km": null,
  "color": "green",
  "color_manufacturer": null,
  "construction_year": null,
  "created_at": "2020-10-22T11:55:03.155249",
  "cubic_capacity": null,
  "current_location": "DE, Kitzingen",
  "defects": null,
  "emission_class": null,
  "emission_sticker": null,
  "equipment": null,
  "external_id": null,
  "extras": null,
  "first_registration": "07/2017",
  "fuel_consumption_l_100km": null,
  "fuel_type": "diesel",
  "horse_power": 105,
  "id": null,
  "interior_design": null,
  "label": "Fabia 1.4 TDI Ambition",
  "last_inspection": null,
  "make": "Skoda",
  "meta": null,
  "mileage_in_km": 58128,
  "model": "Fabia",
  "num_car_seats": null,
  "num_doors": null,
  "num_owners": null,
  "origin": null,
  "parking_sensors": null,
  "pdf_details_url": null,
  "price": null,
  "price_currency": null,
  "transmission": "manual",
  "updated_at": "2020-10-22T11:55:03.155530",
  "url": null,
  "vin": null
}

如果我需要在 vechile 中获取物品,我可以使用以下内容:

select v.* 
from json_data,
lateral flatten( input => j:"vehicle" ) v;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM