如何在hbase中加入表 [英] how to join tables in hbase
问题描述
我必须在 Hbase 中加入表.
I have to join tables in Hbase.
我集成了 HIVE 和 HBase,效果很好.我可以使用 HIVE 进行查询.
I integrated HIVE and HBase and that is working well. I can query using HIVE.
但是有人可以帮助我如何在不使用 HIVE 的情况下加入 HBase 中的表.我认为使用 mapreduce 我们可以实现这一点,如果可以的话,任何人都可以分享一个我可以参考的工作示例.
But can somebody help me how to join tables in HBase without using HIVE. I think using mapreduce we can achieve this, if so can anybody share a working example that I can refer.
请分享您的意见.
我有一个办法.也就是说,
I have an approach in mind. That is,
如果我需要加入表 A x B x C;我可以使用 TableMapReduceUtil 来迭代 A,然后在 TableMapper 中从 B 和 C 获取数据.然后使用 TableReducer 写回另一个表 Y.
If I need to JOIN tables A x B x C; I may use TableMapReduceUtil to iterate over A, then get Data from B and C inside the TableMapper. Then use the TableReducer to write back to another table Y.
这种方法会很好吗?
推荐答案
这当然是一种方法,但是如果您对每个扫描的行进行 2 次随机读取,那么您的速度将会直线下降.如果您正在显着过滤行或在 A 中有一个小数据集,这可能不是问题.
That is certainly an approach, but if you are doing 2 random reads per scanned row then your speed will plummet. If you are filtering the rows out significantly or have a small dataset in A that may not be an issue.
但是,在 HBase 0.96 中可用的最佳方法是 MultipleTableInput 方法.这意味着它将扫描表 A 并使用允许表 B 匹配的唯一键写入其输出.
However the best approach, which will be available in HBase 0.96, is the MultipleTableInput method. This means that it will scan table A and write it's output with a unique key that will allow table B to match up.
例如表 A 发出 (b_id, a_info) 和表 B 将发出 (b_id, b_info) 在 reducer 中合并在一起.
E.g. Table A emits (b_id, a_info) and Table B will emit (b_id, b_info) merging together in the reducer.
这是一个排序合并连接的示例.
This is an example of a sort-merge join.
如果您在行键上加入或加入属性按照表 B 排序,则您可以在每个任务中拥有一个扫描仪实例,该实例依次从表 B 中读取,直到找到它要查找的内容.
If you are joining on the row key or the joining attribute is sorted in line with table B, you can have a instance of a scanner in each task which sequentially reads from table B until it finds what it's looking for.
例如表 A 行键 = companyId",表 B 行键 = companyId_employeeId".然后对于表 A 中的每个公司,您可以使用嵌套循环算法获取所有员工.
E.g. Table A row key = "companyId" and Table B row key = "companyId_employeeId". Then for each Company in Table A you can get all the employees using the nest-loop algorithm.
for(company in TableA):
for(employee in TableB):
if employee.company_id == company.id:
emit(company.id, employee)
这是一个嵌套循环连接的示例.
This is an example of a nest-loop join.
- http://en.wikipedia.org/wiki/Nested_loop_join
- http://en.wikipedia.org/wiki/Hash_join
- http://en.wikipedia.org/wiki/Sort-merge_join
这篇关于如何在hbase中加入表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!