将输出写入REDUCER的多个表

时间:2016-05-25 11:42:32

标签: hadoop mapreduce hbase

我可以从reducer中将输出写入HBase中的多个表吗?我浏览了不同的博文,但即使使用MultiTableOutputFormat,也无法找到方法。

我提到了这个:Write to multiple tables in HBASE

但无法确定context.write来电的API签名。

减速机代码:

public class MyReducer extends TableReducer<Text, Result, Put> {

    private static final Logger logger = Logger.getLogger( MyReducer.class );

    @SuppressWarnings( "deprecation" )
    @Override
    protected void reduce( Text key, Iterable<Result> data, Context context ) throws IOException, InterruptedException {
        logger.info( "Working on ---> " + key.toString() );
        for ( Result res : data ) {
            Put put = new Put( res.getRow() );
            KeyValue[] raw = res.raw();
            for ( KeyValue kv : raw ) {
                put.add( kv );
            }

            context.write( obj, put );
            **// I dont know how to give table name here.**

        }
    }
}

1 个答案:

答案 0 :(得分:1)

要识别表名,您应该将表名作为context.write(key, put)方法的键:

ImmutableBytesWritable key = new ImmutableBytesWritable(Bytes.toBytes("tableName"));
context.write(key, put);

但是,如果您想立即通过MapReduce作业加载大量数据,那么使用MultiTableHFileOutputFormat可能会很有趣。此输出格式为您需要的每个HBase表创建HFile,然后您可以使用LoadIncrementalHFiles工具轻松加载这些文件:

hbase org.apache.hadoop.hbase.mapreduce.LoadIncrementalHFiles /tmp/multiTableJobResult hbaseTable

您可以在文章中详细了解MultiTableHFileOutputFormathttp://tech.adroll.com/blog/data/2014/07/15/multi-table-bulk-import.html

相关问题