说明:如果数据格式是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;