Job端的变化:
通过设置conf,配置输出表,在reduce中获取输出表名字
Configuration conf = job.getConfiguration();
//输出表1
conf.set("usertag_output", "usertag");
//输出表2
conf.set("prodtag_output", "prodtag");
job.setReducerClass(LabelReducer.class);
job.setOutputValueClass(Put.class);
job.setOutputFormatClass(MultiTableOutputFormat.class);
LabelReducer:
@Override
public void reduce(Text key, Iterable<Text> values, Context context)
throws IOException, InterruptedException
{
.......
Put put = new Put(userid.getBytes());
put.add("usertags".getBytes(), "usertags".getBytes(), outputlabel.toString().getBytes());
............
ImmutableBytesWritable ib = new ImmutableBytesWritable();
ib.set(Bytes.toBytes(usertag_output)); // 将结果存入hbase表
context.write(ib, put);
}