为什么AWS athena将我的表创建为字符串而不是嵌套对象数组

时间:2017-03-14 19:46:21

标签: amazon-athena

我得到的是一个包含sql命令但没有错误的非常长的标题,而不是嵌套表。为什么它正常工作但实际上没有正确输入json数据?

CREATE external TABLE ranked (
    airlineRankings array<struct<
    overall_rating:TINYINT,
    seat_comfort_rating:TINYINT,
    cabin_staff_rating:TINYINT,
    food_beverages_rating:TINYINT,
    inflight_entertainment_rating:TINYINT,
    ground_service_rating:TINYINT,
    wifi_connectivity_rating:TINYINT,
    value_money_rating:TINYINT,
    recommended:TINYINT,
    review_amount:TINYINT,
    count:TINYINT,
    iata:string,
    icao:string,
    airline_link:string,
    call_sign:string,
    country:string,
    airline:string
      >>
      )
    ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe'
    LOCATION 's3://**********/'

JSON数据格式:

{
    "airlineRankings": [{
        "iata": "",
        "icao": "EVY",
        "airline_link": "34 Squadron, Royal Australian Air Force",
        "call_sign": "",
        "country": "Australia",
        "airline": "34 Squadron, Royal Australian Air Force",
        "overall_rating": 0,
        "seat_comfort_rating": 0,
        "cabin_staff_rating": 0,
        "food_beverages_rating": 0,
        "inflight_entertainment_rating": 0,
        "ground_service_rating": 0,
        "wifi_connectivity_rating": 0,
        "value_money_rating": 0,
        "recommended": 0,
        "review_amount": 0
    }
]
}

1 个答案:

答案 0 :(得分:1)

您的DDL没问题。如果您在查询阵列时遇到问题,可能会错过&#34; \ n \ n去除&#34;数组对象。

您的结构的示例查询如下所示:

select myRecord.icao from ranked
CROSS JOIN UNNEST(airlinerankings) AS myTable (myRecord);