Javatpoint Logo
Javatpoint Logo

MapReduce Word Count Example

In MapReduce word count example, we find out the frequency of each word. 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.

Pre-requisite

  • Java Installation - Check whether the Java is installed or not using the following command.
    java -version
  • Hadoop Installation - Check whether the Hadoop is installed or not using the following command.
    hadoop version

If any of them is not installed in your system, follow the below link to install it.

www.javatpoint.com/hadoop-installation

Steps to execute MapReduce word count example

  • Create a text file in your local machine and write some text into it.
    $ nano data.txt
MapReduce Word Count Example
  • Check the text written in the data.txt file.
    $ cat data.txt
MapReduce Word Count Example

In this example, we find out the frequency of each word exists in this text file.

  • Create a directory in HDFS, where to kept text file.
    $ hdfs dfs -mkdir /test
  • Upload the data.txt file on HDFS in the specific directory.
    $ hdfs dfs -put /home/codegyani/data.txt /test
MapReduce Word Count Example
  • Write the MapReduce program using eclipse.

File: WC_Mapper.java

File: WC_Reducer.java

File: WC_Runner.java

Download the source code.

  • Create the jar file of this program and name it countworddemo.jar.
  • Run the jar file
    hadoop jar /home/codegyani/wordcountdemo.jar com.javatpoint.WC_Runner /test/data.txt /r_output
  • The output is stored in /r_output/part-00000
MapReduce Word Count Example
  • Now execute the command to see the output.
    hdfs dfs -cat /r_output/part-00000
MapReduce Word Count Example
Next TopicChar Count Example





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA