zoukankan      html  css  js  c++  java
  • 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)
  • 相关阅读:
    [HNOI2006] 公路修建问题
    [8.16模拟赛] 玩具 (dp/字符串)
    [NOI2014] 动物园
    [CF816E] Karen and Supermarket1 [树形dp]
    [POI2006] OKR-period of words
    [BZOJ4260] Codechef REBXOR
    [POJ3630] Phone List
    正确答案 [Hash/枚举]
    The xor-longest Path [Trie]
    [NOI1999] 生日蛋糕
  • 原文地址:https://www.cnblogs.com/lhicp/p/14033516.html
Copyright © 2011-2022 走看看