写入 HBASE 中的多个表 [英] Write to multiple tables in HBASE

查看:40
本文介绍了写入 HBASE 中的多个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里遇到一种情况,我需要写入两个 hbase 表,比如 table1,table 2.每当表 1 上发生写入时,我需要对表 2 执行一些操作,比如在表 2 中增加一个计数器(比如触发).为此,我需要在 map-reduce 程序的同一任务中访问(写入)两个表.我听说可以使用 MultiTableOutputFormat 来完成.但我找不到任何详细解释的好例子.有人可以回答是否可以这样做.如果是这样,我该怎么做/应该做.提前致谢.

I have a situation here where I need to write to two of the hbase tables say table1,table 2. Whenever a write happens on table 1, I need to do some operation on table 2 say increment a counter in table 2 (like triggering). For this purpose I need to access (write) to two tables in the same task of a map-reduce program. I heard that it can be done using MultiTableOutputFormat. But I could not find any good example explaining in detail. Could some one please answer whether is it possible to do so. If so how can/should I do it. Thanks in advance.

请给我一个不应包含协处理器的答案.

Please provide me an answer that should not include co-processors.

推荐答案

要在 map-reduce 作业中写入多个表,您必须在作业配置中指定.你是对的,这可以使用 MultiTableOutputFormat 来完成.通常对于您使用的单个表:

To write into more than one table in map-reduce job, you have to specify that in job configuration. You are right this can be done using MultiTableOutputFormat. Normally for a single table you use like:

TableMapReduceUtil.initTableReducerJob("tableName", MyReducer.class, job);

而不是这样写:

job.setOutputFormatClass(MultiTableOutputFormat.class);
job.setMapperClass(MyMapper.class);
job.setReducerClass(MyReducer.class);
job.setNumReduceTasks(2);
TableMapReduceUtil.addDependencyJars(job);
TableMapReduceUtil.addDependencyJars(job.getConfiguration());

现在在表中写入数据时写为:

Now at the time of writing data in table write as:

context.write(new ImmutableBytesWritable(Bytes.toBytes("tableName1")),put1);
context.write(new ImmutableBytesWritable(Bytes.toBytes("tableName2")),put2);

这篇关于写入 HBASE 中的多个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆