-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStockCodeQuantityReducer.java
More file actions
32 lines (26 loc) · 983 Bytes
/
StockCodeQuantityReducer.java
File metadata and controls
32 lines (26 loc) · 983 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/**
* The StockCodeQuantityReducer extends the predefined Reducer
* class and overwrites the reduce function. The 4-tuple <Text,
* IntWritable, Text, IntWritable > specifies the types of the
* input and output key-value pair. The type of the input
* key-value pair (<Text, IntWritable>) is the same as the output
* key-value pair of the mapper.
*
* @author Abe Khaleghi
* @version 1.0
*/
import java.io.IOException;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;
public class StockCodeQuantityReducer extends Reducer<Text , IntWritable , Text , IntWritable > {
@Override public void reduce(Text stockCode, Iterable<IntWritable> counts, Context context)
throws IOException, InterruptedException {
// Count totals
int sum = 0;
for ( IntWritable count : counts) {
sum += count.get();
}
context.write(stockCode, new IntWritable(sum));
}
}