hbase映射为hive表(转载+整理+自己验证)
本文是對[1][2]的整理以及在新版本上的驗(yàn)證
-----------------------------------------------------------------------------------------
環(huán)境版本
?
| 大數(shù)據(jù)組件 | 版本 |
| Hadoop | 3.1.2 |
| Zookeeper | 3.6.0 |
| Hbase | 2.2.4 |
| Hive | 3.0.0 |
-------------------------------------------------
實(shí)驗(yàn)前提:
啟動HDFS集群
啟動Zookeeper集群
啟動Hbase集群
啟動Hive的metastore和hiveserver2
-------------------------------------------------
?
| ? | Hive建表 | hbase中插入數(shù)據(jù) | 查詢hive |
| hbase->hive內(nèi)表 | CREATE TABLE member( | put'member','scutshuxue','info:age','24'
| select * from member; |
| hbase->hive外表 | CREATE EXTERNAL TABLE student( | create 'student','m_id','address','info' put'student','scutshuxue','info:age','24' | select * from student; |
?
調(diào)試tips:
Hive用beeline建表的時(shí)候可能會卡住,這個(gè)時(shí)候可以退出beeline>引擎,采用老的hive>引擎
注意:
上述表格中的任何一條命令,如果超過8秒(我的是5秒,普通的4核8線程電腦),一般是由于故障卡住了,不要盲目等待。
如果hive的metastore清空,想要重新操作,那么上述過程中,必須先清除hbase中的數(shù)據(jù),清除過程以[3]為準(zhǔn)
#------------------列映射---------------------------------
上半部分是全部數(shù)據(jù)從hbase映射到hive,
如果只想映射一部分?jǐn)?shù)據(jù)呢?列映射來了!
列映射表格關(guān)系(根據(jù)不同映射需求,hbase->hive)
| index1 | hbase_table1 | 列映射(單列) |
| index1 | hbase_table2 | 多列映射 |
| index1 | hbase_table3 | 列簇映射 |
?
index1表結(jié)構(gòu)以及實(shí)驗(yàn)數(shù)據(jù)
| Hbase表名:index1 | ||
| Row Key | 列簇(column family):cf0 | |
| cf0:indexId | cf0:muMac | |
| 11 | 11 | ? |
| 13 | 11 | ? |
| 9696 | 100 | ? |
| 9901 | ? | uzzu |
| 990111 | 11 | ? |
| 990_11aa_aza | 11 | ? |
| ? | hbase操作 |
| 建立index1 | create "index1","cf0" |
| 傳入數(shù)據(jù)操作 | create "index1","cf0" scan 'index1'? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? put 'index1',9696,'cf0:indexId',100? ? ? ? ? ? ? ? ? ?? put 'index1',9901,'cf0:muMac','uzzu' |
?
| ? | Hive操作 | 查詢語句 |
| 單列映射 | CREATE EXTERNAL TABLE hbase_table_1(key string, value string)? STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler' WITH SERDEPROPERTIES("hbase.columns.mapping" = "cf0:indexId")? TBLPROPERTIES("hbase.table.name" = "index1", "hbase.mapred.output.outputtable" = "index1"); ? | select * from hbase_table_1; |
| 多列映射 | CREATE EXTERNAL TABLE hbase_table_2(key int, indexId string, muMac string)? STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'? WITH SERDEPROPERTIES ("hbase.columns.mapping" = "cf0:indexId,cf0:muMac")? TBLPROPERTIES("hbase.table.name" = "index1", "hbase.mapred.output.outputtable" = "index1"); | select * from hbase_table_2; |
| 列簇映射 | CREATE EXTERNAL TABLE hbase_table_3(value map<string,string>,row_key string)? STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler' WITH SERDEPROPERTIES ("hbase.columns.mapping" = "cf0:,:key")? TBLPROPERTIES("hbase.table.name" = "index1", "hbase.mapred.output.outputtable" = "index1"); | select * from hbase_table_3; |
?
hbase_table_1結(jié)果:
+--------------------+----------------------+ | hbase_table_1.key | hbase_table_1.value | +--------------------+----------------------+ | 11 | 11 | | 13 | 11 | | 9696 | 100 | | 990111 | 11 | | 990_11aa_aza | 11 | +--------------------+----------------------+?
hbase_table_2結(jié)果:
+--------------------+------------------------+----------------------+ | hbase_table_2.key | hbase_table_2.indexid | hbase_table_2.mumac | +--------------------+------------------------+----------------------+ | 11 | 11 | NULL | | 13 | 11 | NULL | | 9696 | 100 | NULL | | 9901 | NULL | uzzu | | 990111 | 11 | NULL | | NULL | 11 | NULL | +--------------------+------------------------+----------------------+?
hbase_table_3結(jié)果:
+----------------------+------------------------+ | hbase_table_3.value | hbase_table_3.row_key | +----------------------+------------------------+ | {"indexId":"11"} | 11 | | {"indexId":"11"} | 13 | | {"indexId":"100"} | 9696 | | {"muMac":"uzzu"} | 9901 | | {"indexId":"11"} | 990111 | | {"indexId":"11"} | 990_11aa_aza | +----------------------+------------------------+#------------------列映射---------------------------------
Reference:
[1]hive:hbase表映射到hive中
[2]Hbase表映射Hive表三種方法
[3]HBase表創(chuàng)建、刪除、清空
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎總結(jié)
以上是生活随笔為你收集整理的hbase映射为hive表(转载+整理+自己验证)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 结魄灯是谁的梦幻西游 汉典结字的基本解释
- 下一篇: 浦大喜奔app最新版本(汉典浦字的基本解