Analysis.A3_Total_Users_By_Gender.User_Gender_Count_Reducer.java Source code

Java tutorial

Introduction

Here is the source code for Analysis.A3_Total_Users_By_Gender.User_Gender_Count_Reducer.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Analysis.A3_Total_Users_By_Gender;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 *
 * @author Chintan
 */
public class User_Gender_Count_Reducer extends Reducer<Text, IntWritable, Text, IntWritable> {
    private IntWritable result = new IntWritable();

    public void reduce(Text key, Iterable<IntWritable> values, Context context)
            throws IOException, InterruptedException {
        int count = 0;
        for (IntWritable value : values) {
            count += value.get();
        }

        result.set(count);

        // print gender and count
        context.write(key, result);
    }

}