MapReduce Char Count Example
In MapReduce char count example, we find out the frequency of each character. Here, the role of Mapper is to map the keys to the existing values and the role of Reducer is to aggregate the keys of common values. So, everything is represented in the form of Key-value pair.
- Java Installation - Check whether the Java is installed or not using the following command.
- Hadoop Installation - Check whether the Hadoop is installed or not using the following command.
If any of them is not installed in your system, follow the below link to install it.
Steps to execute MapReduce char count example
- Create a text file in your local machine and write some text into it.
$ nano info.txt
- Check the text written in the info.txt file.
$ cat info.txt
In this example, we find out the frequency of each char value exists in this text file.
- Create a directory in HDFS, where to kept text file.
$ hdfs dfs -mkdir /count
- Upload the info.txt file on HDFS in the specific directory.
$ hdfs dfs -put /home/codegyani/info.txt /count
- Write the MapReduce program using eclipse.
Download the source code.
- Create the jar file of this program and name it charcountdemo.jar.
- Run the jar file
hadoop jar /home/codegyani/charcountdemo.jar com.javatpoint.WC_Runner /count/info.txt /char_output
- The output is stored in /char_output/part-00000
- Now execute the command to see the output.
hdfs dfs -cat /r_output/part-00000