List of usage examples for org.springframework.data.mongodb.core.mapreduce MapReduceResults iterator
public Iterator<T> iterator()
From source file:fr.cirad.mgdb.exporting.markeroriented.VcfExportHandler.java
/** * Creates the sam sequence dictionary.//ww w.j a va2s . c o m * * @param sModule the module * @param sequenceIDs the sequence i ds * @return the SAM sequence dictionary * @throws Exception the exception */ public SAMSequenceDictionary createSAMSequenceDictionary(String sModule, Collection<String> sequenceIDs) throws Exception { SAMSequenceDictionary dict1 = new SAMSequenceDictionary(); MongoTemplate mongoTemplate = MongoTemplateManager.get(sModule); String sequenceSeqCollName = MongoTemplateManager.getMongoCollectionName(Sequence.class); if (mongoTemplate.collectionExists(sequenceSeqCollName) && sequenceIDs.size() > 1) { long before = System.currentTimeMillis(); Query query = new Query(Criteria.where("_id").in(sequenceIDs)); String mapFunction = "function() { emit(this._id, this." + Sequence.FIELDNAME_SEQUENCE + ".length); }"; String reduceFunction = "function() { }"; MapReduceResults<Map> rs = MongoTemplateManager.get(sModule).mapReduce(query, sequenceSeqCollName, mapFunction, reduceFunction, Map.class); Iterator<Map> it = rs.iterator(); while (it.hasNext()) { Map map = it.next(); dict1.addSequence( new SAMSequenceRecord((String) map.get("_id"), ((Double) map.get("value")).intValue())); } LOG.info("createSAMSequenceDictionary took " + (System.currentTimeMillis() - before) / 1000d + "s to write " + sequenceIDs.size() + " sequences"); } else LOG.info("No sequence data was found. No SAMSequenceDictionary could be created."); return dict1; }
From source file:io.github.microcks.repository.DailyStatisticRepositoryImpl.java
@Override public DailyStatistic aggregateDailyStatistics(String day) { // Build a query to pre-select the statistics that will be aggregated. Query query = new Query(Criteria.where("day").is(day)); // Execute a MapReduce command. MapReduceResults<WrappedDailyStatistic> results = template.mapReduce(query, "dailyStatistic", "classpath:mapDailyStatisticForADay.js", "classpath:reduceDailyStatisticForADay.js", WrappedDailyStatistic.class); // Output some debug messages. if (log.isDebugEnabled()) { log.debug("aggregateDailyStatistics mapReduce for day " + day); log.debug("aggregateDailyStatistics mapReduce result counts: " + results.getCounts()); for (WrappedDailyStatistic wdt : results) { log.debug("aggregateDailyStatistics mapReduce result value: " + wdt.getValue()); }/*from ww w . j a v a 2s. c o m*/ } // We've got a result if we've got an output. if (results.getCounts().getOutputCount() > 0) { return results.iterator().next().getValue(); } // Build and return an empty object otherwise? DailyStatistic statistic = new DailyStatistic(); statistic.setDay(day); statistic.setDailyCount(0); return statistic; }