-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathWordCountMapper.java
More file actions
29 lines (23 loc) · 814 Bytes
/
WordCountMapper.java
File metadata and controls
29 lines (23 loc) · 814 Bytes
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
import java.io.IOException;
import java.util.StringTokenizer;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
// Provide key in /value in and k/v out data types
// Generics
public class WordCountMapper extends
Mapper<LongWritable, Text, Text, IntWritable>{
@Override
protected void map(LongWritable key, Text value, Context context)
throws IOException, InterruptedException {
//(0, line )
//String[] words=value.toString().split(" ");
StringTokenizer words=new StringTokenizer(value.toString(), " ");
while(words.hasMoreTokens()){
String word=words.nextToken();
//Send word,1 , convert them into writables
context.write(new Text(word), new IntWritable(1));
}
}
}