求助,不太理解mapreduce中的map函数的参数
最近正在学写mapreduce.就拿下面这个例子说吧,这是一个从hbase中读数据写入到另外一张hbase表中的数据.
在map函数中value这个参数是一行的数据.貌似我需要的东西全在value里了.不理解这个map函数的第一个参数ImmutableBytesWritable row传进来的是什么数据.debug一下看实际数据也不是我往表里插的什么数据 求大神解惑.
在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);
}
}
...全文
相关推荐
MapReduce之Wordcount实现
首先,理解MapReduce的两个主要处理阶段:Map阶段和Reduce阶段。Map阶段处理输入的数据,并输出键值对(key-value pairs),而Reduce阶段则对这些键值对进行汇总处理。
python中map()函数的使用方法示例
在Python编程语言中,`map()`函数是一个强大而优雅的工具,它体现了函数式编程的简洁理念。它的基本概念源自于Lisp等函数式语言中的map和reduce概念,MapReduce的工作原理正是受
mapreduce框架学习之天气统计
本学习案例聚焦于MapReduce框架在天气统计中的应用,通过实际编程实践加深对框架的理解。首先,MapReduce的工作原理可以概括为两个主要阶段:Map阶段和Reduce阶段。
MapReduce技术原理深入理解.pdf
默认,框架对每个InputSplit中的每一行,解析成一个<k1,v1>。框架调用Mapper类中的map(...)函数,map函数的形参是<k1,v1>对,输出是<k2,v2>对。
MongoDB中的MapReduce简介
MongoDB的MapReduce操作可以通过`db.runCommand`命令启动,提供`mapreduce`集合名称、`map`函数和`reduce`函数作为参数。


