The Input is a text file named Wiki-micro.txt ... The word count program is running fine .. What i need is to modify it & change its output format from (Word count) to (Word####Filename count) I want my output in format (Word#####Filename count), Can you please let me know where i am going wrong? I used the Input Split but its not working .. Kindly, help me in that.
public static class Map extends Mapper<LongWritable , Text , Text , IntWritable > {
private final static IntWritable one = new IntWritable( 1);
private Text word = new Text();
private static final Pattern WORD_BOUNDARY = Pattern .compile("\\s*\\b\\s*");
public void map( LongWritable offset, Text lineText, Context context)
throws IOException, InterruptedException {
String line = lineText.toString();
Text currentWord = new Text();
InputSplit input_split = context.getInputSplit();
String FName = ((FileSplit) input_split).getPath().getName();
for ( String word : WORD_BOUNDARY .split(line)) {
if (word.isEmpty()) {
continue;
}
currentWord = new Text(word);
context.write(currentWord, one);
context.write(new Text(FName), one);
}
}
}
Not sure, but what happens if you replace the last 3 lines:
currentWord = new Text(word);
context.write(currentWord, one);
context.write(new Text(FName), one);
with
currentWord = new Text(word + "####" + FName);
context.write(currentWord, one);
context.write(new Text(FName), one);