一、问题
在hive中创建一个映射hbase的外部表,用来查询hbase的数据。查询hive外部表时发现数据重复。
hbase中的建表语句如下:
create 'hbase_table_name',{NAME=>'0',VERSIONS=>1,BLOCKCACHE=>true,BLOOMFILTER=>'ROW',COMPRESSION=>'SNAPPY'},{SPLITS => ['0','1','2','3','4','5','6','7','8','9']}
hive创建的外部表sql如下:
CREATE external TABLE hive_table_name(rowkey binary, col string )
STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
WITH SERDEPROPERTIES (
"hbase.columns.mapping" = ":key,0:col"
)
tblproperties ("hbase.table.name" = "hbase_table_name", "hbase.mapred.output.outputtable" = "hbase_table_name","");
二、解决
1 修改hbase存储格式为binary
修改hive建表语句为如下
CREATE external TABLE hive_table_name(rowkey binary, col string )
STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
WITH SERDEPROPERTIES (
"hbase.columns.mapping" = ":key,0:col"
)
tblproperties ("hbase.table.name" = "hbase_table_name", "hbase.mapred.output.outputtable" = "hbase_table_name","hbase.table.default.storage.type" = "binary");
2 重新建hive表
再查询发现数据已经不重复了
反思
没有搞清楚具体原理,猜测是类型映射问题导致的
参考链接
博客 : https://blog.csdn.net/hai19850514/article/details/84465279
hive官方文档: https://cwiki.apache.org/confluence/display/Hive/HBaseIntegration