Package com.mongodb

Examples of com.mongodb.MapReduceCommand


     *             If an error occurred
     */
    @Deprecated
    public com.mongodb.MapReduceOutput mapReduce(String map, String reduce,
            String outputTarget, DBObject query) throws MongoException {
        return mapReduce(new MapReduceCommand(dbCollection, map, reduce,
                outputTarget, MapReduceCommand.OutputType.REPLACE,
                serializeFields(query)));
    }
View Full Code Here


     */
    @Deprecated
    public com.mongodb.MapReduceOutput mapReduce(String map, String reduce,
            String outputTarget, MapReduceCommand.OutputType outputType,
            DBObject query) throws MongoException {
        return mapReduce(new MapReduceCommand(dbCollection, map, reduce,
                outputTarget, outputType, serializeFields(query)));
    }
View Full Code Here

        }

        String outDB = getStringFieldValue(Item.mrOutDB);
        DBObject query = ((DocBuilderField) getBoundUnit(Item.mrQuery)).getDBObject();
        int limit = getIntFieldValue(Item.mrLimit);
        final MapReduceCommand cmd = new MapReduceCommand(col, map, reduce, out, type, query);
        DBObject sort = ((DocBuilderField) getBoundUnit(Item.mrSort)).getDBObject();
        if (sort != null) {
            cmd.setSort(sort);
        }
        if (!outDB.isEmpty()) {
            cmd.setOutputDB(outDB);
        }
        if (!finalize.isEmpty()) {
            cmd.setFinalize(finalize);
        }
        if (limit > 0) {
            cmd.setLimit(limit);
        }

        if (getBooleanFieldValue(Item.mrJSMode)) {
            cmd.addExtraOption("jsMode", true);
        }

        final BasicDBObject cmdobj = (BasicDBObject) cmd.toDBObject();
        if (getBooleanFieldValue(Item.mrOutSharded)) {
            ((BasicDBObject) cmdobj.get("out")).put("sharded", true);
        }
        if (getBooleanFieldValue(Item.mrNonAtomic)) {
            ((BasicDBObject) cmdobj.get("out")).put("nonAtomic", true);
        }

        new DbJob() {
            MapReduceOutput output;

            @Override
            public Object doRun() {
//                output = col.mapReduce(cmd);

                // if type in inline, then query options like slaveOk is fine
                CommandResult res = null;
                if (type == MapReduceCommand.OutputType.INLINE) {
                    res = col.getDB().command(cmdobj, col.getOptions());
                    return res;
                }

                res = col.getDB().command(cmdobj);
                res.throwOnError();
                output = new MapReduceOutput(col, cmdobj, res);
                return output;
            }

            @Override
            public void wrapUp(Object res) {
                if (output != null) {
                    if (cmd.getOutputType() == OutputType.INLINE) {
                        res = output.results();
                    } else {
                        // spawn a find
                        doFind(output.getOutputCollection(), null);
                        res = output.getRaw();
View Full Code Here

                break;
        }

        DBCollection dbColl = q.getCollection();

        MapReduceCommand cmd = new MapReduceCommand(dbColl, baseCommand.getMap(), baseCommand.getReduce(), baseCommand.getOutputTarget(), outType, q.getQueryObject());
        cmd.setFinalize(baseCommand.getFinalize());
        cmd.setScope(baseCommand.getScope());

        if (q.getLimit() > 0)
            cmd.setLimit(q.getLimit());
        if (q.getSortObject() != null)
            cmd.setSort(q.getSortObject());

        if (log.isTraceEnabled())
            log.info("Executing " + cmd.toString());

        MapReduceOutput mpo = dbColl.mapReduce(baseCommand);
        MapreduceResults mrRes = (MapreduceResults) mapr.fromDBObject(MapreduceResults.class, mpo.getRaw(), createCache());

        QueryImpl baseQ = null;
View Full Code Here

            default:
                outType = OutputType.REPLACE;
                break;
        }

        MapReduceCommand cmd = new MapReduceCommand(dbColl, map, reduce, outColl, outType, query.getQueryObject());

        if (query.getLimit() > 0)
            cmd.setLimit(query.getLimit());
        if (query.getSortObject() != null)
            cmd.setSort(query.getSortObject());

        if (finalize != null && finalize.length() > 0)
            cmd.setFinalize(finalize);

        if (scopeFields != null && scopeFields.size() > 0)
            cmd.setScope(scopeFields);

        return mapReduce(type, query, outputType, cmd);
    }
View Full Code Here

      String reduceFunction, MapReduceOptions mapReduceOptions, Class<T> entityClass) {

    String mapFunc = replaceWithResourceIfNecessary(mapFunction);
    String reduceFunc = replaceWithResourceIfNecessary(reduceFunction);
    DBCollection inputCollection = getCollection(inputCollectionName);
    MapReduceCommand command = new MapReduceCommand(inputCollection, mapFunc, reduceFunc,
        mapReduceOptions.getOutputCollection(), mapReduceOptions.getOutputType(), null);

    DBObject commandObject = copyQuery(query, copyMapReduceOptions(mapReduceOptions, command));

    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug("Executing MapReduce on collection [" + command.getInput() + "], mapFunction [" + mapFunc
          + "], reduceFunction [" + reduceFunc + "]");
    }

    CommandResult commandResult = command.getOutputType() == MapReduceCommand.OutputType.INLINE ? executeCommand(
        commandObject, getDb().getOptions()) : executeCommand(commandObject);
    handleCommandError(commandResult, commandObject);

    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug("MapReduce command result = [{}]", serializeToJsonSafely(commandObject));
View Full Code Here

      || mapReduce.getOutputCollectionName().trim().length()==0) {
      throw new IllegalArgumentException("Invalid output collection name");
    }

    // create command
    MapReduceCommand cmd = new MapReduceCommand(
      getCollection(collection),
      mapReduce.getMapFunction(),
      mapReduce.getReduceFunction(),
      mapReduce.getOutputCollectionName(),
      mapReduce.getOutputType(),
      mapReduce.getQuery());
   
    if (mapReduce.getSort()!=null) {
      cmd.setSort(mapReduce.getSort());
    }
    if (mapReduce.getLimit()!=null) {
      cmd.setLimit(mapReduce.getLimit().intValue());
    }
    if (mapReduce.getFinalizeFunction()!=null) {
      cmd.setFinalize(mapReduce.getFinalizeFunction());
    }
    if (mapReduce.getScope()!=null) {
      cmd.setScope(mapReduce.getScope());
    }
    if (mapReduce.getVerbose()!=null) {
      cmd.setVerbose(mapReduce.getVerbose());
    }
    if (mapReduce.getOutputDBName()!=null) {
      cmd.setOutputDB(mapReduce.getOutputDBName());
    }

    // execute and return
    return new MapReduceResult(
      getCollection(collection).mapReduce(cmd));
View Full Code Here

                            .isExists(), equalTo(true));

            String map = "function() { emit(this.cust_id, this.amount); }";
            String reduce = "function (key, values) { return Array.sum( values ) }";

            MapReduceCommand cmd = new MapReduceCommand(mongoCollection, map, reduce, outputCollection,
                    MapReduceCommand.OutputType.REPLACE, null);

            MapReduceOutput out = mongoCollection.mapReduce(cmd);
            logger.debug("MapReduceOutput: {}", out);
            Thread.sleep(wait);
View Full Code Here

                break;
        }

        final DBCollection dbColl = query.getCollection();

        final MapReduceCommand cmd = new MapReduceCommand(dbColl, baseCommand.getMap(), baseCommand.getReduce(),
                                                          baseCommand.getOutputTarget(), outType, query.getQueryObject());
        cmd.setFinalize(baseCommand.getFinalize());
        cmd.setScope(baseCommand.getScope());

        if (query.getLimit() > 0) {
            cmd.setLimit(query.getLimit());
        }
        if (query.getSortObject() != null) {
            cmd.setSort(query.getSortObject());
        }

        if (LOG.isTraceEnabled()) {
            LOG.info("Executing " + cmd.toString());
        }

        final EntityCache cache = createCache();
        MapreduceResults<T> results = new MapreduceResults<T>(dbColl.mapReduce(baseCommand));
View Full Code Here

            default:
                outType = OutputType.REPLACE;
                break;
        }

        final MapReduceCommand cmd = new MapReduceCommand(dbColl, map, reduce, outColl, outType, query.getQueryObject());

        if (query.getLimit() > 0) {
            cmd.setLimit(query.getLimit());
        }
        if (query.getSortObject() != null) {
            cmd.setSort(query.getSortObject());
        }

        if (finalize != null && finalize.length() != 0) {
            cmd.setFinalize(finalize);
        }

        if (scopeFields != null && !scopeFields.isEmpty()) {
            cmd.setScope(scopeFields);
        }

        return mapReduce(type, query, outputType, cmd);
    }
View Full Code Here

TOP

Related Classes of com.mongodb.MapReduceCommand

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.