Hive读取json数据源

本文介绍了如何在Hive中读取和解析JSON数据源,特别是聚焦于将JSON中的time字段提取为年、月、日、时、分、秒,并详细讲解了使用内置函数如json_tuple、cast和from_unixtime等进行数据转换的过程,最终构建了一个大宽表rating_width,为后续的统计分析做准备。
摘要由CSDN通过智能技术生成

1.数据格式如下图

2.创建表并加载数据

hive (test)> create table rating_json(json string);
hive (test)> load data local inpath '/home/hadoop/testdata/json/rating.json' into table rating_json;
Loading data to table test.rating_json
Table test.rating_json stats: [numFiles=1, totalSize=63602280]
OK
Time taken: 0.68 seconds

2.使用build-in 函数json_tuple

hive (test)> desc function json_tuple;
OK
tab_name
json_tuple(jsonStr, p1, p2, ..., pn) - like get_json_object, but it takes multiple names and return a tuple. All the input parameters and output column types are string.
Time taken: 0.004 seconds, Fetched: 1 row(s)

hive (test)> select json_tuple(json,'movie','rate','time','userid') as (
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值