0

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

{
  "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
  }
}
4

1 回答 1

0

我写了一个查询列表:

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"
]

车辆返回一个对象:

{
  "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;
于 2021-02-02T12:59:52.367 回答