Reduce code is used for addition and statistics,
Package Org. freebird. reducer; import Java. io. ioexception; import Org. apache. hadoop. io. intwritable; import Org. apache. hadoop. mapreduce. CER Cer. context; import Org. apache. hadoop. mapreduce. reducer; public class logreducer <key> extends reducer <key, intwritable, key, intwritable> {private intwritable result = new intwritable (); Public void reduce (Key key, iterable <intwritable> values, context) throws ioexception, interruptedexception {int sum = 0; For (intwritable VAL: values) {sum + = Val. get ();} result. set (SUM); context. write (Key, result );}}
Iterate through values and retrieve all values, which are 1, simple addition.
Then the result is written to the context. Note that the context here is the context of the CER package.
Mapreduce 1.x programming series three reduce stage implementation