gpt4 book ai didi

json - 在 Hive 中分解 json

转载 作者:行者123 更新时间:2023-12-02 04:40:46 25 4
gpt4 key购买 nike

我在配置单元中存储了一个 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/ 中的教程进行操作但我收到以下错误:

失败:SemanticException 1:164 AS 子句的别名数量无效。在 token “用法”附近遇到错误

我的查询:

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中的列名

最佳答案

您提到的示例使用了像 json_map 这样的非标准 HIVE 的 UDF。您必须构建并加载来自 here 的 brickhouse 代码,将它们编译并安装到您的机器上以使用它们。

我认为最简单的方法是使用 json_tuple,因为您的情况相当简单(没有嵌套结构等)。类似下面的内容将提取您需要的字段,然后您可以将其存储在表中。

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

关于json - 在 Hive 中分解 json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37833405/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com