JSON Serde解析数组结构问题

时间:2017-10-12 01:13:56

标签: amazon-web-services hive bigdata

我的JSON对象:

{
    "_total": 4,
    "values": [
        {
            "total-follower-count": 63911,
            "organic-follower-count": 6000,
            "paid-follower-count": 3911,
            "time": 1399334400000
        },
        {
            "total-follower-count": 64023,
            "organic-follower-count": 6000,
            "paid-follower-count": 4023,
            "time": 1399420800000
        },
        {
            "total-follower-count": 64023,
            "organic-follower-count": 6000,
            "paid-follower-count": 4023,
            "time": 1399507200000
        },
        {
            "total-follower-count": 64048,
            "organic-follower-count": 6000,
            "paid-follower-count": 4048,
            "time": 1399593600000
        }
    ]
}

在AWS Athena中,我创建了一个如下表格。

CREATE EXTERNAL TABLE IF NOT EXISTS Linkedindata 
(
  `_total` INT,
   values array<struct<total_follower_count:INT,
                       organic_follower_count:INT,
                       paid_follower_count:INT>>
)
ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe'
WITH SERDEPROPERTIES (
  "mapping.total_follower_count"="total-follower-count",
  "mapping.organic_follower_count"="organic-follower-count", 
  "mapping.paid_follower_count"="paid-follower-count" 
  )
LOCATION 's3://mybucket/'
TBLPROPERTIES ('has_encrypted_data'='false') 

我无法访问“Total_Follower_count”之类的数组值。能否请你帮忙。谢谢

1 个答案:

答案 0 :(得分:0)

您需要展平数组并执行选择。

在这里用明确的例子记录,

http://docs.aws.amazon.com/athena/latest/ug/flattening-arrays.html

希望它有所帮助。