We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Map Reduce Advanced - Count number of friends
Map Reduce Advanced - Count number of friends
Sort by
recency
|
21 Discussions
|
Please Login in order to post a comment
MapReduce Advanced allows efficient counting of the number of friends by parallelizing tasks across multiple nodes, where the Map phase assigns key-value pairs of users and friends, and the Reduce phase aggregates the total count for each user. This approach enables handling large-scale datasets by distributing computation, optimizing speed and scalability. Lion567
I think the mapper function extracts friend pairs from the input record and emits each friend pair with count 1. It also logs the emitted values to the error stream for better understanding. The main driver code reads input data, blue light filter, applies the mapper, and then sorts and groups the emitted values. The reducer function is called for each group and counts the number of occurrences for each friend. It emits the result in the required format. Note: This code assumes that the input is read from stdin and the output is printed to stdout. Also, it uses sys.stderr to log intermediate steps to the error stream. Make sure to adjust the input/output handling based on the actual requirements of your MapReduce framework.
!/usr/bin/env python2.7
from collections import OrderedDict import sys
class MapReduce: def init(self): self.intermediate = OrderedDict() self.result = []
mapReducer = MapReduce()
def mapper(record): #Start writing the Map code here fields = record.replace('\n', '').split(',')
def reducer(key, list_of_values): #Start writing the Reduce code here person_names = [] department_names = [] for label, value in list_of_values: if label == 'Employee': person_names.append(value) else: department_names.append(value)
if name == 'main': inputData = [] for line in sys.stdin: inputData.append(line) mapReducer.execute(inputData, mapper, reducer)
Simple way: