如何将表从HBase转移到Hive?

时间:2015-10-30 16:02:04

标签: hadoop hive hbase hiveql

如何正确地将HBase表传输到Hive?

我之前尝试过的是你能读到这个问题吗? How insert overwrite table in hive with diffrent where clauses? (我创建了一个表来导入所有数据。这里的问题是数据仍然是行而不是列。所以我为新闻,社交和所有具有特定where子句创建了3个表。之后我创建了2个联接给我结果表的表。所以我有6个表,这些表并不是真正的表现!)

总结我的问题:在HBase中是列族,它们保存为这样的行。

count   verpassen   news    1
count   verpassen   social  0
count   verpassen   all 1

我想在Hive中实现的是这样的数据结构:

name      news    social   all
verpassen 1       0        1

我该怎么做?

1 个答案:

答案 0 :(得分:0)

以下是可以使用的方法。

使用hbase存储处理程序在hive中创建表

示例脚本

  

CREATE TABLE hbase_table_1(键字符串,值字符串)STORED BY   ' org.apache.hadoop.hive.hbase.HBaseStorageHandler' WITH   SERDEPROPERTIES(" hbase.columns.mapping" =":key,f1:val")   TBLPROPERTIES(" hbase.table.name" =" test");

我将您提供的样本数据加载到hive外部表中。

enter image description here

  

从TESTTABLE中选择名称,collect_set(concat_ws(',',type,val))输入   按名称分组;

我按名称对数据进行分组。上述查询的结果输出将为 enter image description here

现在我编写了一个自定义映射器,它将输入作为输入参数并发出值。

  

来自(选择' ["全部,1","社交,0","新闻,1"]&#39 ;来自TESTTABLE组的名称输入)d MAP d.input使用' python test.py'如   总之,社会,新闻

enter image description here

或者你可以使用输出插入到另一个具有列名name,all,social,news

的表中

希望这有帮助