MapReduce 方式 Map 函数
public class LineLengthCountMapper
extends Mapper<LongWritable,Text,IntWritable,IntWritable> {
@Override
protected void map(LongWritable lineNumber, Text line, Context context)
throws IOException, InterruptedException {
context.write(new IntWritable(line.getLength()), new IntWritable(1));
}
}
Spark 方式 Map 函数
lines.map(line => (line.length, 1))
上代码中 map() 操作是一个 RDD
有了RDD链式实现就简单多了
|