Hive之json数据处理

测试数据:

{"movie":"2797","rate":"3","time":"978302205","userid":"1"}
{"movie":"3595","rate":"5","time":"978302103","userid":"2"}
{"movie":"5462","rate":"4","time":"978303212","userid":"3"}

建表:

create table rating_json(
json string
);

插入数据:

insert into table rating_json values ('{"movie":"2797","rate":"3","time":"978302205","userid":"1"}');
//注意:insert into values语法 Hive 是支持的,但是尽量少用。

重要函数:json_tuple

desc function extended json_tuple;

查询:

select json_tuple(json,'movie','rate','time','userid') as(movie, rate, time, userid) from rating_json;

select userid, movie, rate, time,
from_unixtime(cast(time as bigint)) as time,
year(from_unixtime(cast(time as bigint))) as year
from 
(select json_tuple(json,'movie','rate','time','userid') as(movie, rate, time, userid) from rating_json) t;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值