Hive -案例1- 利用JsonSerDe 来解析json字符串

  说明:如果数据格式是Json格式,如果按照常规的思路我们要使用自定义函数去解析, 那么在这里使用 JSonSerde就可以直接读取Json格式的文件,不需要做转化。

  1、数据准备: 

ip6.json 

{"id":188,"ip":"112.168.10.129","domain":"www.baidu.com"}
{"id":267,"ip":"132.158.140.119","domain":"www.baidu1.com"}
{"id":3445,"ip":"112.168.10.129","domain":"www.alibaba.com"}
{"id":4535,"ip":"132.158.120.119","domain":"www.baidu1.com"}
{"id":14534,"ip":"102.118.10.129","domain":"www.360.com"}
{"id":22332,"ip":"12.8.140.119","domain":"www.sina.com"}

2、步骤:

  #1、如果是第三方jar包或者是自己写的,就必须要先加载jar包:

   hive> add jar /hivedata/json-serde-1.3.8-jar-with-dependencies.jar;

  #2、还要将包导入到hadoop这个目录下:/usr/local/hadoop/share/hadoop/mapreduce/

  #3、执行 set hive.exec.compress.output=fase;  --一般默认是false

  #4、创建表

hive (demo)> create table if not exists ip6(
           > id int,
           > ip string,
           > demain string
           > )
           > row format serde "org.openx.data.jsonserde.JsonSerDe";

  #5、导入数据

hive (demo)> load data local inpath 'hivedata/ip6.json' into table ip6;

 #6、查询表中数据

hive (demo)> select * from ip6;

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值