Character Count Example In Mapreduce java

Our HadoopTpoint App is now available in google play store,please rate and comment it in play store : W3Schools

Generally we all are know about Word count example in mapreduce java program and that is very basic hadoop mapreduce program in big data like hello world program in java.In our previous program we had discussed about Word count program driver class,mapper class and reducer class very clearly.Now it’s turn to character count example in mapreduce java.

Please check Below code for Character Count Example In Mapreduce java we divide the code by Driver,Mapper and Reducer Part wise

Here we taken an input like this below

In the above input we have many number of lines and all lines contains only “a” “t” “c” and “g” characters only.Here our task is we have to count how many “a” “t” “c” and “g” characters in out input.In below we will clearly discuss about character count driver class,character count mapper class and character count reducer class.

Character Count Example In Mapreduce java

Character Count Driver Class

In the above Driver code we set job mapper class and job reducer classes.Input and output formats taken as TextInputFormat.class and TextOutputFormat.class,output key class taken as Text and output value class taken as IntWritable class.

Character Count Mapper Class

In the above mapper class we taken value as input and converted input values into toString() format and then String values converted into toCharArray() format,by using for each loop we can divide every character count as one.

Character Count In Reducer Class

In the above Reducer code we just simply sum the all Iterable values by using for loop

Character Count Output

This is the final output of Character Count Example In Mapreduce java

Comments

  1. Thanks for the code, it works great. How easy would it be to modify the code so that it counts how many words in a file start with each letter?

    For Example if I had a file with the words ‘hello world hello world’

    the output would be

    h – 2
    w – 2

Speak Your Mind

*