Difference between revisions of "MapReduce Reducer Assignment"

From CSE231 Wiki
Jump to navigation Jump to search
Line 3: Line 3:
  
 
=Background=
 
=Background=
After much debate, we decided to go with [https://docs.oracle.com/javase/8/docs/api/java/util/stream/Collector.html interface Collector<T,A,R>] from the standard Java streams framework as the basis for the MapReduce assignment.   
+
We debated between creating our own custom Reducer<V,A,R> interface versus adopting the standard [https://docs.oracle.com/javase/8/docs/api/java/util/stream/Collector.html interface Collector<T,A,R>] from the standard Java streams framework as the basis for the MapReduce Frameworks Lab.   
  
It might have been slightly less confusing at the outset if we provided our own custom interface.  Imaging the mythical non-existant interface below:
+
While It might have been slightly less confusing at the outset if we used something like this mythical non-existant interface below:
  
 
  <nowiki>public interface Reducer<V, A, R> {
 
  <nowiki>public interface Reducer<V, A, R> {
Line 14: Line 14:
 
}</nowiki>
 
}</nowiki>
  
 +
we chose to go with the standard Collector<T,A,R>
  
 
[https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/mutable/MutableInt.html class MutableInt]
 
  
 
Mythical Reducer:
 
Mythical Reducer:

Revision as of 17:55, 22 February 2018

Motivation

interface Collector<T,A,R> is fundamental to the MapReduce Frameworks lab.

Background

We debated between creating our own custom Reducer<V,A,R> interface versus adopting the standard interface Collector<T,A,R> from the standard Java streams framework as the basis for the MapReduce Frameworks Lab.

While It might have been slightly less confusing at the outset if we used something like this mythical non-existant interface below:

public interface Reducer<V, A, R> {
	A createMutableContainer();
	void accumulate(A container, V item);
	A combine(A containerA, A containerB);
	R reduce(A container);
}

we chose to go with the standard Collector<T,A,R>


Mythical Reducer:

public class CollectorReducerAdapter<V, A, R> implements Reducer<V, A, R> {
	private final Collector<V,A,R> collector;
	public CollectorReducerAdapter(Collector<V,A,R> collector) {
		this.collector = collector;
	}
	@Override
	public A createMutableContainer() {
		return collector.supplier().get();
	}
	@Override
	public void accumulate(A container, V item) {
		collector.accumulator().accept(container, item);
	}
	@Override
	public A combine(A containerA, A containerB) {
		return collector.combiner().apply(containerA, containerB);
	}
	@Override
	public R reduce(A container) {
		return collector.finisher().apply(container);
	}
}

Code To Implement

ClassicReducer

class: ClassicReducer.java Java.png
methods: supplier
accumulator
combiner
package: mapreduce.collector.studio
source folder: student/src/main/java

IntSumCollector

class: IntSumCollector.java Java.png
methods: supplier
accumulator
combiner
finisher
package: mapreduce.collector.intsum.studio
source folder: student/src/main/java

Testing Your Solution

Correctness

class: CollectorStudioTestSuite.java Junit.png
package: mapreduce
source folder: testing/src/test/java