import [Link].
Configuration;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
class MatrixMultiplication {
public static class MatrixMultiplicationMapper extends Mapper<Object, Text, Text, IntWritable> {
private static final int A = 0;
private static final int B = 1;
@Override
public void map(Object key, Text value, Context context) throws IOException, InterruptedException {
String line = [Link]().trim();
String[] elements = [Link]("\\s+");
if ([Link]().contains("A")) {
for (int k = 0; k < [Link]; k++) {
[Link](new Text("A#" + [Link]().split("_")[0] + "," + k), new
IntWritable([Link](elements[k])));
}
} else if ([Link]().contains("B")) {
for (int j = 0; j < [Link]; j++) {
[Link](new Text("B#" + j + "," + [Link]().split("_")[1]), new
IntWritable([Link](elements[j])));
}
}
}
}
public static class MatrixMultiplicationReducer extends Reducer<Text, IntWritable, Text, IntWritable> {
@Override
public void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException,
InterruptedException {
List<Integer> A_values = new ArrayList<>();
List<Integer> B_values = new ArrayList<>();
for (IntWritable value : values) {
String[] parts = [Link]().split("#");
String matrix = parts[0];
if ([Link]("A")) {
A_values.add([Link]());
} else if ([Link]("B")) {
B_values.add([Link]());
}
}
int sum = 0;
for (int i = 0; i < A_values.size(); i++) {
sum += A_values.get(i) * B_values.get(i);
}
[Link](key, new IntWritable(sum));
}
}
public static class MatrixMultiplicationDriver {
public static void main(String[] args) throws Exception {
if ([Link] != 2) {
[Link]("Usage: MatrixMultiplication <input_path><output_path>");
[Link](-1);
}
Configuration conf = new Configuration();
Job job = [Link](conf, "Matrix Multiplication");
[Link]([Link]);
[Link]([Link]);
[Link]([Link]);
[Link]([Link]);
[Link]([Link]);
[Link](job, new Path(args[0]));
[Link](job, new Path(args[1]));
}
}
}
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
class WordCountMapper implements Mapper<LongWritable, Text, Text, IntWritable> {
private final static IntWritable one = new IntWritable(1);
private Text word = new Text();
@Override
public void configure(JobConf job) {}
@Override
public void map(LongWritable key, Text value, OutputCollector<Text, IntWritable> output, Reporter
reporter) throws IOException {
String line = [Link]();
StringTokenizer tokenizer = new StringTokenizer(line);
while ([Link]()) {
[Link]([Link]());
[Link](word, one);
}
}
@Override
public void close() throws IOException {}
}
class WordCountReducer implements Reducer<Text, IntWritable, Text, IntWritable> {
private IntWritable result = new IntWritable();
@Override
public void configure(JobConf job) {}
@Override
public void reduce(Text key, Iterator<IntWritable> values, OutputCollector<Text, IntWritable> output,
Reporter reporter) throws IOException {
int sum = 0;
while ([Link]()) {
sum += [Link]().get();
}
[Link](sum);
[Link](key, result);
}
@Override
public void close() throws IOException {}
}
public class WordCountDriver {
public static void main(String[] args) throws Exception {
if ([Link] != 2) {
[Link]("Usage: WordCountDriver <input path> <output path>");
[Link](-1);
}
Configuration conf = new Configuration();
JobConf job = new JobConf(conf, [Link]);
[Link]("Word Count");
[Link]([Link]);
[Link]([Link]);
[Link]([Link]);
[Link]([Link]);
[Link]([Link]);
[Link]([Link]);
[Link](job, new Path(args[0]));
[Link](job, new Path(args[1]));
[Link](job);
}
}