求助,不太理解mapreduce中的map函数的参数

CodeMonkeyWang CodeMonkeyWang 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
最近正在学写mapreduce.就拿下面这个例子说吧,这是一个从hbase中读数据写入到另外一张hbase表中的数据.

在map函数中value这个参数是一行的数据.貌似我需要的东西全在value里了.不理解这个map函数的第一个参数ImmutableBytesWritable row传进来的是什么数据.debug一下看实际数据也不是我往表里插的什么数据 求大神解惑.

public class TxtHbase {
public static class MapperClass extends TableMapper<Text, IntWritable> {
private final IntWritable ONE = new IntWritable(1);
private Text text = new Text();

@Override
public void map(ImmutableBytesWritable row, Result value, Context context) throws IOException, InterruptedException {
String val = new String(value.getValue(Bytes.toBytes("cf1"), Bytes.toBytes("c1")));
text.set(val); // we can only emit Writables...

context.write(text, ONE);
}
}

public static class ReducerClass extends TableReducer<Text, IntWritable, ImmutableBytesWritable> {
@Override
public void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
int i = 0;
for (IntWritable val : values) {
i += val.get();
}
Put put = new Put(Bytes.toBytes(key.toString()));
put.add(Bytes.toBytes("cf1"), Bytes.toBytes("count"), Bytes.toBytes(i));

context.write(null, put);
}
}

/**
* @param args
*/
public static void main(String[] args) throws Exception {
Configuration conf = HBaseConfiguration.create();
//String [] argArray=new GenericOptionsParser(conf, args).getRemainingArgs();
conf.set("from.table", "trade_detail_info");
conf.set("to.table", "trade_total");
//conf.set("family", "family1");

Job job = new Job(conf, "hbase to hbase");

job.setJarByClass(TxtHbase.class);
TableMapReduceUtil.initTableMapperJob(conf.get("from.table"), new Scan(), MapperClass.class, Text.class, IntWritable.class, job);
TableMapReduceUtil.initTableReducerJob(conf.get("to.table"), ReducerClass.class, job);
System.exit(job.waitForCompletion(true) ? 0 : 1);

}
}
...全文

相关推荐

评论 2
收藏 已收藏
分享
返回顶部