• 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)
  • 相关阅读:
    基本计算器 II
    查看JVM使用的什么垃圾收集器
    java nio 例子
    获取jvm加载的类
    对上传的二进制视频文件进行第一帧截取
    conda与pip
    微信聊天记录导出与分析
    k8s creationTimestamp 参数
    adb logcat使用及Debug技巧
    聊聊HDR
  • 原文地址:https://www.cnblogs.com/lhicp/p/14033516.html
Copyright © 2020-2023  润新知