hadoop - 从 REDUCER 将输出写入多个表

标签 hadoop mapreduce hbase

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

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

但无法找出 context.write 调用的 API 签名。

reducer 代码:

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.**

        }
    }
}

最佳答案

要识别表名,您应该将表名作为键传递给 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

您可以在文章中阅读有关 MultiTableHFileOutputFormat 的更多信息:http://tech.adroll.com/blog/data/2014/07/15/multi-table-bulk-import.html

关于hadoop - 从 REDUCER 将输出写入多个表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37436095/

相关文章:

hadoop - 在 HBase 中删除一行的单元格

hadoop - 在 spark join 中,表顺序是否像 pig 一样重要?

java - Scala MapReduce 框架提供类型不匹配

hadoop - 为什么 MultipleOutputs 不适用于此 Map Reduce 程序?

hadoop - 什么时候我们不在 Mapreduce 中使用 Combiner?

hbase - 在HBase中,如何存储列表或数组结构

hadoop - 如何/在哪里可以写入时间序列数据?作为 Hadoop、HBase、Cassandra 的 Parquet 格式?

java - hadoop中的 transient 变量和静态方法,dev求教

hadoop - Hive 中的多个 Where 子查询不起作用

date - 如何在配置单元中将字符串格式转换为日期格式