public void fold(String key, BSONWritable value, @SuppressWarnings("rawtypes") org.apache.hadoop.mapreduce.Mapper.Context context) throws IOException, InterruptedException {
// 1] Get current state, or create if not there
BSONWritable currVal = _folderState.get(key);
if (null == currVal) {
currVal = new BSONWritable();
_folderState.put(key, currVal);
}
// 2] Processing logic
//TODO: write your logic in here, the key/val can be anything you want, since you control the map code also
// Eg: count the docs
Integer currDocs = (Integer) currVal.get("count");
if (null == currDocs) {
currDocs = 0;
}
currDocs++;
currVal.put("count", currDocs);
//DEBUG:
if (_logMessages) _logger.info("FOLD_IN " + key + ": " + MongoDbUtil.convert(value) + "->" + MongoDbUtil.convert(currVal).toString());
// 3] Emit if state getting too large