我可以从我的reducer向hbase中的多个表写入输出吗?我浏览了不同的博客文章,但马找不到一个方法,甚至使用 MultiTableOutputFormat
.
我提到过:在hbase中写入多个表
但无法找出 context.write
打电话。
减速机代码:
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条答案
按热度按时间b4wnujal1#
要标识表名,应该将表名作为键传递给
context.write(key, put)
方法:但是,如果您想通过mapreduce作业一次加载大量数据,那么使用它可能会很有趣
MultiTableHFileOutputFormat
. 这种输出格式为您需要的每个hbase表创建hfiles,然后您可以轻松地加载这些文件LoadIncrementalHFiles
工具:你可以阅读更多关于
MultiTableHFileOutputFormat
在文章中:http://tech.adroll.com/blog/data/2014/07/15/multi-table-bulk-import.html