zoukankan      html  css  js  c++  java
  • Hbase和hive的整合

     

    一、Hbase写入数据到hive中

    1.1  首先在Hbase上创建一张表hbase2hive

    create 'hbase2hive','info'

    1.2  向hbase2hive插入两条数据做测试

    1 put 'hbase2hive','user001','info:name','xiaoming'
    2 put 'hbase2hive','user001','info:age',18
    3 put 'hbase2hive','user002','info:name','xiaohong'
    4 put 'hbase2hive','user002','info:age',17

    1.3  在hive中创建外部表hive_test01并关联到Hbase的hbase2hive

    create exteral table hive_test01 (id string,name string,age int) 
    stored by 'org.apache.hadoop.hive.HbaseStorageHandler' 
    with serdeproperties("hbase.columns.mapping"=":key,info:name,info:info:age") 
    tblproperties("hbase.table.name"="hbase2hive")

    sotred by :表示hive_test的存储格式

    with serdeproperties:序列化和反序列化的设置

    tblproperties:hive表的属性设置(例子中案例表示hive_test关联hbase2hive表数据)

    1.4  接下来就可以在hive_test中查询到Hbase中Hbase2hive表的数据啦!

    二、hive写入数据到Hbase中

    2.1  在Hbase中创建表hive2hbase(数据导入到这个表中)

    create 'hive2hbase','info'

    2.2  在hive表中创建外部表hive_test02

    create exteral table hive_test02 (id string,name string,age int) 
    stored by 'org.apache.hadoop.hive.HbaseStorageHandler' 
    with serdeproperties("hbase.columns.mapping"=":key,info:name,info:info:age") 
    tblproperties("hbase.table.name"="hive2hbase")

    2.3  在hive中创建临时表(将数据写入在hive_test02)

    create temporary table tmp_user(id string,name string,age int) row format delimited fields terminated by '	';

    2.4 向临时表中添加数据

    load data local inpath '/home/test/user.txt' into table hive_test02;

    2.5  在Hbase中查询数据即可

  • 相关阅读:
    gin使用validator库参数校验若干实用技巧
    在gin框架中使用JWT
    使用zap接收gin框架默认的日志并配置日志归档
    gin框架路由拆分与注册
    Gin框架介绍及使用
    GO学习-(39) 优雅地关机或重启
    GO学习-(38) Go语言结构体转map[string]interface{}的若干方法
    WPF中不规则窗体与WindowsFormsHost控件的兼容问题完美解决方案
    [ 夜间模式 ] NightVersion
    HDU1518 Square(DFS)
  • 原文地址:https://www.cnblogs.com/lmr7/p/15407935.html
Copyright © 2011-2022 走看看