hive与json:使用HDFS上的json格式数据建立hive表

1 下载对应版本的 jar包
http://mvnrepository.com/artifact/org.apache.hive.hcatalog/hive-hcatalog-core

add jar  /home/xxx/hive-hcatalog-core-2.1.0.jar

2.创建表

CREATE TABLE json_table(id bigint, sourceType int)
ROW FORMAT SERDE 'org.apache.hive.hcatalog.data.JsonSerDe'
STORED AS TEXTFILE;

3.加载数据

load data local inpath '/home/xxx/json.txt' into table json_table;

文件如下

{"id":5644228109524316032,"sourceType":1}
{"id":-736866360508848202,"sourceType":3}

4.

select * from json_table;
OK
5644228109524316032     1
-736866360508848202     3

参考
https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL#LanguageManualDDL-RowFormats&SerDe

注:本人是用的Hive的2.1.0版本

你可能感兴趣的:(hadoop,hive,json,hdfs)