我可以从我的 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/