我有一个存储在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_bytes是my_table
中列的名称答案 0 :(得分:0)
您提到的示例使用非标准HIVE的json_map等UDF。您必须从here构建并加载brickhouse代码,然后在您的机器上编译并安装它们以使用它们。
我认为最简单的方法是使用json_tuple,因为你的情况相当简单(没有嵌套结构等)。类似下面的内容将提取您需要的字段,然后您可以将其存储在表格中。
select x.* from my_table
LATERAL VIEW json_tuple(app_bytes,'SHAREit',
'Google Play Store','Internet','Facebook','YouTube') x ;