在hive中爆炸json

gr8qqesn  于 2021-06-29  发布在  Hive
关注(0)|答案(1)|浏览(629)

我在hive中存储了一个json,看起来像:

{"SHAREit":"4666179584","Google Play Store":"515161408","Internet":"369566560","Facebook":"257369824","YouTube":"173979008"}

我希望以以下方式将此json存储在另一个表中:

|SHAREit           |           4666179584|
|------------------+---------------------+
|Google Play       |           515161408 |
|------------------+---------------------+
|Internet          |           369566560 |
|------------------+---------------------+
|Facebook          |           257369824 |
|------------------+---------------------+
|YouTube           |           173979008 |
+------------------+---------------------+

我试着从链接上看教程https://brickhouseconfessions.wordpress.com/2014/02/07/hive-and-json-made-simple/ 但我得到以下错误: FAILED: SemanticException 1:164 AS clause has an invalid number of aliases. Error encountered near token 'usage' 我的问题:

select  apps,usage from my_table 
LATERAL VIEW explode_map(json_map(app_bytes,'string, string')) appsTable as apps,usage 
where appsTable.day='2016-06-11' and appsTable.event_info.type="TRACK_APP_BYTES";

ps:app\u bytes是我的\u表中列的名称

dbf7pr2w

dbf7pr2w1#

您提到的示例使用了非标准配置单元的自定义项,如json\u map。您必须从这里构建并加载brickhouse代码,编译并安装到您的机器上才能使用它们。
我认为最简单的方法是使用json\u tuple,因为您的案例非常简单(没有嵌套结构等)。下面的内容将提取所需的字段,然后将其存储在表中。

select  x.* from my_table                    
  LATERAL VIEW json_tuple(app_bytes,'SHAREit',
    'Google Play Store','Internet','Facebook','YouTube') x  ;

相关问题