# 创建hbase表
hbase(main):087:0* create "test_hbase_mapping_hive", "f"
0 row(s) in 1.2400 seconds
=> Hbase::Table - test_hbase_mapping_hive
# put的数据
put "test_hbase_mapping_hive", "001","f:id","001"
put "test_hbase_mapping_hive", "001","f:name","luyi"
创建hbase到hive的映射表
# hive外表
create external table test_hbase_mapping_hive(rowkey string, id string, name string) STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler' WITH SERDEPROPERTIES ("hbase.columns.mapping" = "property:id, property:name") TBLPROPERTIES ("hbase.table.name" = "default:test_hbase_mapping_hive");
hbase的rowkey会默认映射到被映射的hive表的第一列,其他的qaulifier按照“hbase.columns.mapping”的顺序与hive表字段一一对应。
# hive内表
create table test_hbase_mapping_hive(rowkey string, id string, name string) STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler' WITH SERDEPROPERTIES ("hbase.columns.mapping" = "property:id, property:name") TBLPROPERTIES ("hbase.table.name" = "default:test_hbase_mapping_hive");
hive外表与内表的区别:
删除映射后的hive表:
外表:对hbase原始表没有影响;
内表:删除hive同时,也会删除hbase原始表