Hive、Hbase配合使用

1 、先在hive上创建hbase能识别的表
CREATE TABLE hbase_scores(key string, grade string,math string,art string) 
STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler' 
WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,grade:grade,course:math,course:art") 
TBLPROPERTIES ("hbase.table.name" = "hbase_scores");

2、创建hive表,并导入数据
CREATE TABLE scores(key string, grade string,math string,art string) 
row format delimited fields terminated by '\t';

3、把hive表导入hbase能识别的表,就可以在hive和hbase中查询了和使用了。
INSERT OVERWRITE TABLE hbase_scores SELECT * FROM scores;


------------
hbase表只有列族,没有列的,对应关系应该怎么写?
CREATE TABLE hbase_scores1(key string, grade string) 
STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler' 
WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,grade:,course:math,course:art") 
TBLPROPERTIES ("hbase.table.name" = "hbase_scoresjin");


-----
hbase上已经存在表,在hive上创建外部表
CREATE EXTERNAL  TABLE scores_h(key string,math string,art string) 
STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler' 
WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,course:math,course:art") 
TBLPROPERTIES ("hbase.table.name" = "scores");
hive关联hbase的外部表无法用load导入数据。

猜你喜欢

转载自skambc.iteye.com/blog/2070006