Example usage for com.mongodb MapReduceOutput getInputCount

List of usage examples for com.mongodb MapReduceOutput getInputCount

Introduction

In this page you can find the example usage for com.mongodb MapReduceOutput getInputCount.

Prototype

public int getInputCount() 

Source Link

Document

Get the number of documents that were input into the map reduce operation

Usage

From source file:fr.gouv.vitam.mdbes.MainMapReduce.java

License:Open Source License

protected static void oneShot(MongoDbAccess dbvitam) throws InvalidParseOperationException,
        InvalidExecOperationException, InstantiationException, IllegalAccessException {
    // Requesting
    if (map == null) {
        map = "function() {" + "flattened = serializeDocFiltered(this, MAXDEPTH, FILTER);"
                + "for (var key in flattened) {" + "var value = flattened[key];"
                + "var valueType = varietyTypeOf(value);"
                + "var finalvalue = { types : [ valueType ], occurences : 1};"
                //                + "var finalvalue = { occurences : 1};"
                + "emit(key, finalvalue); } }";
    }/*from  w w w.  j  av  a 2  s.c o  m*/
    if (reduce == null) {
        reduce = "function(key,values) {" + "var typeset = new Set();" + "var occur = 0;"
                + "for (var idx = 0; idx < values.length; idx++) {" + "occur += values[idx].occurences;"
                + "typeset.add(values[idx].types);"
                + "} return { types : typeset.asArray(), occurences : occur }; }";
        //                + "} return { occurences : occur }; }";

    }
    if (output == null) {
        output = "AttributeUsage";
    }
    MapReduceCommand mapReduceCommand = new MapReduceCommand(dbvitam.daips.collection, map, reduce, output,
            OutputType.REDUCE, new BasicDBObject());
    if (options != null) {
        String[] optionsArray = options.split(",");
        Map<String, Object> mapScope = new HashMap<String, Object>();
        for (String string : optionsArray) {
            String[] kv = string.split("=");
            mapScope.put(kv[0], getParsedString(kv[1]));
        }
        mapReduceCommand.setScope(mapScope);
    } else {
        Map<String, Object> mapScope = new HashMap<String, Object>();
        mapScope.put("MAXDEPTH", 5);
        mapScope.put("FILTER", "_dds");
        mapReduceCommand.setScope(mapScope);
    }
    mapReduceCommand.addExtraOption("nonAtomic", true);
    mapReduceCommand.addExtraOption("jsMode", true);
    MapReduceOutput output = dbvitam.daips.collection.mapReduce(mapReduceCommand);
    System.out.println("Duration: " + output.getDuration() + " Saved into: " + output.getCollectionName()
            + " Input: " + output.getInputCount() + " Emit: " + output.getEmitCount() + " Output: "
            + output.getOutputCount() + "\nCmd: " + output.getCommand());
    Iterable<DBObject> iterable = output.results();
    for (DBObject dbObject : iterable) {
        System.out.println(dbObject.toString());
    }
}

From source file:org.springframework.data.mongodb.core.mapreduce.MapReduceResults.java

License:Apache License

private static MapReduceCounts parseCounts(final MapReduceOutput mapReduceOutput) {
    return new MapReduceCounts(mapReduceOutput.getInputCount(), mapReduceOutput.getEmitCount(),
            mapReduceOutput.getOutputCount());
}