Registration for Skill Development Get link Facebook X Pinterest Email Other Apps November 19, 2024 Registration Link: https://forms.gle/XPMjyFQLexhNUJAA8 Get link Facebook X Pinterest Email Other Apps Comments
C Programming Previous Question Papers November 25, 2024 C Programming Previous Question Papers Read more
MapReduce Matrix Multiplication Code January 05, 2021 Mapper Logic : import java.io.IOException; import org.apache.hadoop.conf.*; import org.apache.hadoop.io.*; import org.apache.hadoop.mapreduce.*; public class MatrixMapper extends Mapper<LongWritable, Text, Text, Text> { public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException { Configuration conf = context.getConfiguration(); int m = Integer.parseInt(conf.get("m")); int p = Integer.parseInt(conf.get("p")); String line = value.toString(); String[] indicesAndValue = line.split(","); Text outputKey = new Text(); Text outputValue = new Text(); if (indicesAndValue[0].equals("M")) { for (int k = 0; k < p; k++) { outputKey.set(indicesAndValue[1] + "," + k); outputValue.set("M," + indicesAndValue[2] + "," + indicesAndValue[3]); context.write(outputKey, outputValue); } } else { for (int i = 0; i < m; i++) { outputKey.set(i + "," + indicesAnd... Read more
Word Count MapReduce Code January 04, 2021 Mapper Logic: import java.io.IOException; import java.util.StringTokenizer; import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.io.LongWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Mapper; public class WordCountMapper extends Mapper<LongWritable, Text, Text, IntWritable> { @Override public void map (LongWritable key, Text value, Context con) throws IOException, InterruptedException { String line = value.toString(); String[] words = line.split("\\s"); for(String s:words) { con.write(new Text(s), new IntWritable(1)); } } } Reducer Logic: import java.io.IOException; import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.... Read more
Comments
Post a Comment