Hive使用JsonSerDe格式化json数据

hive默认使用分隔符如空格,分号,"|",制表符\t来格式化数据记录,对于复杂数据类型如json,nginx日志等,就没有办法拆分了,这时候需要更加强大的SerDe来处理复杂数据,如使用JsonSerDe或者使用正则表达式RegSerDe来处理。这里介绍如何利用JsonSerDe来处理json数据。

1、下载最新的json-serde-1.3.8-jar-with-dependencies.jarjson-udf-1.3.8-jar-with-dependencies.jar到hive中的lib目录下。

2、创建表。

hive> create table employees(name string,salary int) comment "a json format table" row format serde 'org.openx.data.jsonserde.JsonSerDe' stored as textfile;
OK
Time taken: 3.951 seconds
hive> show tables;
OK
employees
Time taken: 0.14 seconds, Fetched: 1 row(s)

3、加载数据并测试。

hive> load data local inpath 'file:/home/hadoop/spark/examples/src/main/resources/employees.json' overwrite into table employees;
Loading data to table default.employees
OK
Time taken: 2.153 seconds
hive> select * from employees;
OK
Michael	3000
Andy	4500
Justin	3500
Berta	4000
Time taken: 1.467 seconds, Fetched: 4 row(s)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

luffy5459

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值