我正在 hive 中为Twitter json文件创建表。这是示例文件。我面临的问题是我无法使用结构创建数组,因为在以下数据中,单个数组中有4个相同的结构。谁能告诉我如何为以下数据创建数组。我尝试给每个结构指定不同的名称,该表已成功创建,但无法从table.Kindly Help中提取数据。
谢谢
> "variants": [
{
"bitrate": 2176000,
"content_type": "video\/mp4",
"url": "https:\/\/video.twimg.com\/ext_tw_video\/560070131976392705\/pu\/vid\/1280x720\/c4E56sl91ZB7cpYi.mp4"
},
{
"bitrate": 320000,
"content_type": "video\/mp4",
"url": "https:\/\/video.twimg.com\/ext_tw_video\/560070131976392705\/pu\/vid\/320x180\/nXXsvs7vOhcMivwl.mp4"
},
{
"bitrate": 832000,
"content_type": "video\/webm",
"url": "https:\/\/video.twimg.com\/ext_tw_video\/560070131976392705\/pu\/vid\/640x360\/vmLr5JlVs2kBLrXS.webm"
},
{
"bitrate": 832000,
"content_type": "video\/mp4",
"url": "https:\/\/video.twimg.com\/ext_tw_video\/560070131976392705\/pu\/vid\/640x360\/vmLr5JlVs2kBLrXS.mp4"
},
{
"content_type": "application\/x-mpegURL",
"url": "https:\/\/video.twimg.com\/ext_tw_video\/560070131976392705\/pu\/pl\/r1kgzh5PmLgium3-.m3u8"
}
]
最佳答案
试试这个,
CREATE TABLE complex_json (
variants:array<struct<bitrate:int,content_type:string, url:string>>>
)
ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe';
从https://github.com/rcongiu/Hive-JSON-Serde获得Serde
关于arrays - 使用Hive在数组中创建结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32308319/