1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.io.LongWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Mapper;
import java.io.IOException;
public class WordCountMapper extends Mapper<LongWritable, Text, Text, IntWritable> {
@Override protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
String[] wordArray = value.toString().split(" ");
IntWritable one = new IntWritable(1);
for (String word : wordArray) { context.write(new Text(word), one); } } }
|