


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



The objective of this practical is to implement a Word Count program using the MapReduce framework. The goal is to understand the basic operations of MapReduce— specifically the map and reduce functions—and how they can be applied to solve a common data processing task.
MapReduce is a programming model designed for processing large data sets with a distributed algorithm on a cluster. A MapReduce program is composed of two main functions: Map and Reduce.
The map function reads input data (typically a text file) and generates a set of key-value pairs. Each word in the document is treated as a key, and the value is set to 1 (indicating one occurrence of the word). Python Implementation: import sys def map_function(): for line in sys.stdin: words = line.strip().split() for word in words: print(f'{word}\t1') if name == "main": map_function()
The reduce function aggregates the results from the map function. It sums up the values for each unique key (word) to get the total count. Python Implementation: import sys from collections import defaultdict def reduce_function(): current_word = None current_count = 0 word = None for line in sys.stdin: line = line.strip() word, count = line.split('\t', 1) count = int(count) if current_word == word: current_count += count else: if current_word: print(f'{current_word}\t{current_count}') current_word = word current_count = count
The practical implementation of the Word Count program using MapReduce demonstrates the simplicity and power of the MapReduce model for distributed data processing. By breaking down the problem into smaller, manageable tasks (mapping and reducing), large-scale data can be processed efficiently across a distributed environment.