Difference between revisions of "MapReduce Reducer Assignment"
Jump to navigation
Jump to search
Line 6: | Line 6: | ||
[https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/mutable/MutableInt.html class MutableInt] | [https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/mutable/MutableInt.html class MutableInt] | ||
+ | |||
+ | Mythical Reducer: | ||
+ | |||
+ | <nowiki>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); | ||
+ | } | ||
+ | }</nowiki> | ||
=Code To Implement= | =Code To Implement= |
Revision as of 17:47, 22 February 2018
Contents
Motivation
Collector is fundamental to the MapReduce Framework lab.
Background
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 | |
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 |