项目实战 -hive与HBase整合(二)

一:ke03阻塞启动

  • hive --service metastore

二: ke04 hive增加配置

/opt/bigdata/hive-2.3.4/conf


<property>
    <name>hbase.zookeeper.quorum</name>
    <value>ke02,ke03,ke04</value>
</property>

三: 启动hive,创建hive表 映射Hbase内部表,HIve中执行下方sql

create table hbase_table_1(key int, value string)
stored by 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
with serdeproperties ("hbase.columns.mapping" = ":key, cf1:val")
tblproperties ("hbase.table.name" = "xyz", "hbase.mapred.output.outputtable" = "xyz");

四: 结果: hive创建hbase_table_1,Hbase同步创建了xyz表,HDFS创建了xyz目录

  • hive结果
  • Hbase结果
  • HDFS结果,同时目录下创建空文件:hbase_table_1/.hive-staging_hive_2020-12-16_06-01-33_339_7043895678437004715-1

 五:插入数据

  • hive
    insert into hbase_table_1 values(100, 'test');
    
    当从hive中插入数据,Hbase表中也有对应的数据
    如:  100                                                                 column=cf1:val, timestamp=1608069822673, value=test  
  • Hbase
    put 'xyz', '102', 'cf1:val','new'
    flush
    
    当从HBase中插入数据,Hive表中也有对应的数据
    如:102    new
  • Hbase对应的HDFS数据目录:/hbase/data/default/xyz 
  • 注意: HDFS中, Hbase目录下面是有数据的,Hive目录中是没有数据

六: Hive创建外部表

create external table hbase_table_2(key int, value string)
stored by 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
with serdeproperties ("hbase.columns.mapping" = ":key, cf1:val")
tblproperties ("hbase.table.name" = "some", "hbase.mapred.output.outputtable" = "some");

需要现在Hbase先创建some表:

create 'some','cf1'

  • Hbase插入数据:

    put 'some', '1', 'cf1:val', 'test'
    flush

  • Hive中查询数据

注意:

  1. HBase插入数据需要flush
  2. hive创建Hbase外部表需要先建表
  3. 内部表:HBASE表不存在。   外部表:  Hbase表已经存在。
原文地址:https://www.cnblogs.com/bigdata-familyMeals/p/14151967.html