Difference between revisions of "MapReduce Reducer Assignment"
Line 44: | Line 44: | ||
} | } | ||
}</nowiki> | }</nowiki> | ||
+ | |||
+ | =Code To Use= | ||
+ | [https://docs.oracle.com/javase/8/docs/api/java/util/stream/Collector.html interface Collector<T,A,R>] | ||
+ | |||
+ | [https://docs.oracle.com/javase/8/docs/api/java/util/function/Supplier.html interface Supplier<T>] | ||
+ | |||
+ | [https://docs.oracle.com/javase/8/docs/api/java/util/function/BiConsumer.html interface BiConsumer<T,U>] | ||
+ | |||
+ | [https://docs.oracle.com/javase/8/docs/api/java/util/function/BinaryOperator.html interface BinaryOperator<T>] | ||
+ | |||
+ | [https://docs.oracle.com/javase/8/docs/api/java/util/function/Function.html interface Function<T,R>] | ||
+ | |||
+ | [https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/mutable/MutableInt.html class MutableInt] | ||
=Code To Implement= | =Code To Implement= | ||
Line 51: | Line 64: | ||
==IntSumCollector== | ==IntSumCollector== | ||
{{CodeToImplement|IntSumCollector|supplier<br>accumulator<br>combiner<br>finisher|mapreduce.collector.intsum.studio}} | {{CodeToImplement|IntSumCollector|supplier<br>accumulator<br>combiner<br>finisher|mapreduce.collector.intsum.studio}} | ||
− | |||
− | |||
=Testing Your Solution= | =Testing Your Solution= | ||
==Correctness== | ==Correctness== | ||
{{TestSuite|CollectorStudioTestSuite|mapreduce}} | {{TestSuite|CollectorStudioTestSuite|mapreduce}} |
Revision as of 18:11, 22 February 2018
Contents
Motivation
interface Collector<T,A,R>
is fundamental to the MapReduce Frameworks lab. Your frameworks will be general enough such that MapReduce is just a subset of what you will support.
In this studio we will build a ClassicReducer Collector which will implement the MapReduce style of accumulating all of the emitted values per key in a List.
We will also build a custom IntSumCollector to demonstrate the desired flexibility of the Collector interface.
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> despite the extra level of indirection it requires (returning @Functional interfaces whose single abstract methods do the work).
We provide this mythical class CollectorReducerAdapter
as a Rosetta Stone of sorts in an effort to reveal what each method is responsible for:
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 Use
Code To Implement
ClassicReducer
class: | ClassicReducer.java | |
methods: | supplier accumulator combiner |
|
package: | mapreduce.collector.studio | |
source folder: | student/src/main/java |
IntSumCollector
class: | IntSumCollector.java | |
methods: | supplier accumulator combiner finisher |
|
package: | mapreduce.collector.intsum.studio | |
source folder: | student/src/main/java |
Testing Your Solution
Correctness
class: | CollectorStudioTestSuite.java | |
package: | mapreduce | |
source folder: | testing/src/test/java |