Created
April 6, 2014 19:26
-
-
Save sdpatil/10010442 to your computer and use it in GitHub Desktop.
WordCountMapper.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.spnotes.hadoop; | |
| 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; | |
| import org.slf4j.LoggerFactory; | |
| public class WordCountMapper extends Mapper<LongWritable, Text, Text, IntWritable>{ | |
| org.slf4j.Logger logger = LoggerFactory.getLogger(WordCountMapper.class); | |
| private final static IntWritable one = new IntWritable(1); | |
| private Text word = new Text(); | |
| @Override | |
| protected void map(LongWritable key, Text value, | |
| Context context) | |
| throws IOException, InterruptedException { | |
| logger.debug("Entering WordCountMapper.map() " + this); | |
| String line = value.toString(); | |
| StringTokenizer st = new StringTokenizer(line," "); | |
| while(st.hasMoreTokens()){ | |
| word.set(st.nextToken()); | |
| context.write(word,one); | |
| } | |
| logger.debug("Exiting WordCountMapper.map()"); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment