hive存储json数据

1、首先到hive的bin目录下启动hive

./hive

2、创建属于自己的数据库

create database jtest;

3、加载json的hive包

目录如下:xxx/hive-1.2.0/hcatalog/share/hcatalog  

hive> add jar ../hcatalog/share/hcatalog/hive-hcatalog-core-1.2.0.jar;
Added [../hcatalog/share/hcatalog/hive-hcatalog-core-1.2.0.jar] to class path
Added resources: [../hcatalog/share/hcatalog/hive-hcatalog-core-1.2.0.jar]

4、根据准备json数据创建jtest表

注意:一个json数据写成一行的形式,多个json串写成多行
{"deptno":"11","empno":"7839","ename":"QIU","hiredate":"373910400000","job":"PRESIDENT"}
{"deptno":"10","empno":"7839","ename":"KING","hiredate":"373910400000","job":"PRESIDENT"}
create table IF NOT EXISTS jtest(
 deptno string,
 empno string,
 ename string,
 hiredate string,
 job string
)ROW FORMAT SERDE 'org.apache.hive.hcatalog.data.JsonSerDe'
STORED AS TEXTFILE;

5、加载json数据到表中

hive> load data local inpath '/home/software/a.json' into table jtest;
Loading data to table default.jtest
Table default.jtest stats: [numFiles=1, totalSize=433]
OK
Time taken: 1.112 seconds

6、查询数据

hive> select * from jtest;
OK
10    7839    KING    373910400000    PRESIDENT
10    7839    KING    373910400000    PRESIDENT
11    7839    QIU    373910400000    PRESIDENT
Time taken: 0.336 seconds, Fetched: 3 row(s)

 

posted on 2020-11-24 23:35  lhicp  阅读(1196)  评论(0编辑  收藏  举报