如何创建表 AWS Athena --> 映射 Json 数组?

How to Create Tables AWS Athena --> Mappings Json Array?

如何为 Json 数组格式创建 table Athena(AWS)?

示例 JSON 格式:

{  
   "Tapes":[  
      {  
         "Status":"AVAILABLE",
         "Used":0.0,
         "Barcode":"TEST1217F7",
         "Gateway":"Test_Report",
         "UsedGB":0.0,
         "Date":"06-11-2017",
         "SizeGB":107.0
      },
      {  
         "Status":"AVAILABLE",
         "Used":0.0,
         "Barcode":"TEST1227F7",
         "Gateway":"Test_Report",
         "UsedGB":0.0,
         "Date":"06-11-2017",
         "SizeGB":107.0
      }
   ]
}

我想获得以下输出格式:
enter image description here

我已经按照这个网站尝试解决了问题 enter link description here

根据您的示例 JSON,您可以创建以下内容 table。

create external table test(
  Tapes array<struct<
        Status:string,
        Used:string,
        Barcode:string,
        Gateway:string,
        UsedGB:string,
        Date:string,
        SizeGB:string>>
) ROW FORMAT  serde 'org.openx.data.jsonserde.JsonSerDe'
LOCATION 's3://bucket/test'

这样table,你可以通过以下方式查询所有数组元素

select t1.* from test
cross join UNNEST(test.Tapes) as t1

感谢您的回复

现在,我知道这个查询的原因 我认为这是一个示例 SQL 查询

昨天,我创建了 table 下面的语法

  CREATE external TABLE monlyreport (
        Tapes array<struct< Status:string,
      Used:double,
      Barcode:string,
      SizeGB:double,
      UsedGB:double,
      Date:date >>
       )
    ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe'
    LOCATION 's3://bucket/test';

和预览 table 得到输出

tapes

    [{status=AVAILABLE, used=0.0, barcode=TEST5257F7, sizegb=107.0, usedgb=0.0, date=null}, {status=AVAILABLE, used=0.0, barcode=TEST5257F7, sizegb=107.0, usedgb=0.0, date=null}]

我尝试查询,但是没有用

现在,我明白了这个问题的查询

select n.status,n.used,n.barcode,n.gateway,n.usedgb,n.date,n.sizegb from test
cross join UNNEST(test.Tapes) as t (n)

非常感谢