Mapreduce Apache Gora Reducer用于使用Hbase的多表输出

Mapreduce Apache Gora Reducer用于使用Hbase的多表输出,mapreduce,hbase,nutch,gora,Mapreduce,Hbase,Nutch,Gora,我在Hbase表中通过Nutch抓取了一些小数据。它允许我们使用ApacheGora作为ORM。我发现了很多在Hbase中处理单个表中数据的示例(mapreduce)。但我的问题是,我必须将数据复制到多个表中(在reducer中)。如果没有Gora,就有一些指导,例如,等等,但是如何为我的情况这样做。我从来没有按照你的要求做过,但是你可能会在报告中看到答案。在这里,有一个减速器配置示例,说明: /* Mappers are initialized with GoraMapper.initMapp

我在Hbase表中通过Nutch抓取了一些小数据。它允许我们使用ApacheGora作为ORM。我发现了很多在Hbase中处理单个表中数据的示例(mapreduce)。但我的问题是,我必须将数据复制到多个表中(在reducer中)。如果没有Gora,就有一些指导,例如,等等,但是如何为我的情况这样做。

我从来没有按照你的要求做过,但是你可能会在报告中看到答案。在这里,有一个减速器配置示例,说明:

/* Mappers are initialized with GoraMapper.initMapper() or 
 * GoraInputFormat.setInput()*/
GoraMapper.initMapperJob(job, inStore, TextLong.class, LongWritable.class
    , LogAnalyticsMapper.class, true);

/* Reducers are initialized with GoraReducer#initReducer().
 * If the output is not to be persisted via Gora, any reducer 
 * can be used instead. */
GoraReducer.initReducerJob(job, outStore, LogAnalyticsReducer.class);
然后,您不必使用
GoraReducer.initReducerJob()
,只需配置自己的reducer即可:

要知道,在前面的示例中,映射器会发出
(TextLong,LongWritable)
键值,因此您的减速机类似于,并且:

公共类MyReducer扩展了TableReducer{
私有静态最终记录器Logger=Logger.getLogger(MyReducer.class);
@抑制警告(“弃用”)
@凌驾
受保护的void reduce(TextLong键、Iterable数据、上下文)引发IOException、InterruptedException{
logger.info(“处理-->”+key.toString());
对于(结果:数据){
Put Put=新Put(res.getRow());
KeyValue[]raw=res.raw();
用于(关键值kv:原始){
增加(千伏);
}
ImmutableBytesWritable键=新的ImmutableBytesWritable(Bytes.toBytes(“tableName”);
context.write(key,put);
}
}
}
再说一次,我从来没有这样做过。。。所以可能不起作用:\

GoraMapper.initMapperJob(job, inStore, TextLong.class, LongWritable.class
    , LogAnalyticsMapper.class, true);
job.setOutputFormatClass(MultiTableOutputFormat.class);
job.setReducerClass(MyReducer.class);
job.setNumReduceTasks(2);
TableMapReduceUtil.addDependencyJars(job);
TableMapReduceUtil.addDependencyJars(job.getConfiguration());
public class MyReducer extends TableReducer<TextLong, LongWritable, Put> {

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

    @SuppressWarnings( "deprecation" )
    @Override
    protected void reduce( TextLong key, Iterable<LongWritable> 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 );
            }

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

        }
    }
}