且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在HBASE中写入多个表

更新时间:2023-01-23 10:02:49

要在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);

而不是这样写:

Instead of this write:

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);