当前位置: 首页>>代码示例>>Java>>正文


Java AggregationOutput类代码示例

本文整理汇总了Java中com.mongodb.AggregationOutput的典型用法代码示例。如果您正苦于以下问题:Java AggregationOutput类的具体用法?Java AggregationOutput怎么用?Java AggregationOutput使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


AggregationOutput类属于com.mongodb包,在下文中一共展示了AggregationOutput类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getNumberOfDiscoveredLinks

import com.mongodb.AggregationOutput; //导入依赖的package包/类
/**
 * 
 * @return number of total discovered links
 */
public Double getNumberOfDiscoveredLinks() {
	Double numberOfTriples = 0.0;
	try {
		DBCollection collection = DBSuperClass2.getDBInstance().getCollection(LinksetDB.COLLECTION_NAME);

		BasicDBObject groupFields = new BasicDBObject("_id", null);

		groupFields.append("sum", new BasicDBObject("$sum", "$links"));

		DBObject group = new BasicDBObject("$group", groupFields);

		// run aggregation
		List<DBObject> pipeline = Arrays.asList(group);
		AggregationOutput output = collection.aggregate(pipeline);

		for (DBObject result : output.results()) {
			numberOfTriples = Double.valueOf(result.get("sum").toString());
		}

	} catch (Exception e) {
		e.printStackTrace();
	}
	return numberOfTriples;
}
 
开发者ID:AKSW,项目名称:LODVader,代码行数:29,代码来源:LinksetQueries.java

示例2: afterMethod

import com.mongodb.AggregationOutput; //导入依赖的package包/类
@Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
    Class<?>[] argumentsTypes, Object ret) throws Throwable {
    AbstractSpan activeSpan = ContextManager.activeSpan();
    CommandResult cresult = null;
    if (ret instanceof WriteResult) {
        WriteResult wresult = (WriteResult)ret;
        cresult = wresult.getCachedLastError();
    } else if (ret instanceof AggregationOutput) {
        AggregationOutput aresult = (AggregationOutput)ret;
        cresult = aresult.getCommandResult();
    }
    if (null != cresult && !cresult.ok()) {
        activeSpan.log(cresult.getException());
    }
    ContextManager.stopSpan();
    return ret;
}
 
开发者ID:apache,项目名称:incubator-skywalking,代码行数:18,代码来源:MongoDBCollectionMethodInterceptor.java

示例3: setUpPipelineSample

import com.mongodb.AggregationOutput; //导入依赖的package包/类
private static Iterator<DBObject> setUpPipelineSample( String query, int numDocsToSample, DBCollection collection )
  throws KettleException {

  query = query + ", {$limit : " + numDocsToSample + "}"; //$NON-NLS-1$ //$NON-NLS-2$
  List<DBObject> samplePipe = jsonPipelineToDBObjectList( query );

  DBObject first = samplePipe.get( 0 );
  DBObject[] remainder = new DBObject[ samplePipe.size() - 1 ];
  for ( int i = 1; i < samplePipe.size(); i++ ) {
    remainder[ i - 1 ] = samplePipe.get( i );
  }

  AggregationOutput result = collection.aggregate( first, remainder );

  return result.results().iterator();
}
 
开发者ID:pentaho,项目名称:pentaho-mongodb-plugin,代码行数:17,代码来源:MongodbInputDiscoverFieldsImpl.java

示例4: testPipelineQueryIsLimited

import com.mongodb.AggregationOutput; //导入依赖的package包/类
@Test public void testPipelineQueryIsLimited() throws KettleException, MongoDbException {
  setupPerform();

  AggregationOutput aggOutput = mock( AggregationOutput.class );
  Iterable<DBObject> results = mock( Iterable.class );
  when( aggOutput.results() ).thenReturn( results );
  when( results.iterator() ).thenReturn( mock( Iterator.class ) );

  String query = "{$sort : 1}";
  DBObject firstOp = (DBObject) JSON.parse( query );
  DBObject[] remainder = { new BasicDBObject( "$limit", NUM_DOCS_TO_SAMPLE ) };
  when( collection.aggregate( firstOp, remainder ) )
      .thenReturn( aggOutput );

  discoverFields.discoverFields( new MongoProperties.Builder(), "mydb", "mycollection", query, "", true,
      NUM_DOCS_TO_SAMPLE, inputMeta );

  verify( collection ).aggregate( firstOp, remainder );
}
 
开发者ID:pentaho,项目名称:pentaho-mongodb-plugin,代码行数:20,代码来源:MongodbInputDiscoverFieldsImplTest.java

示例5: getSubscriptions

import com.mongodb.AggregationOutput; //导入依赖的package包/类
@Override
protected List<UPSSubscription> getSubscriptions(String uri) {
    List<UPSSubscription> subscriptions = new ArrayList<>();

    List<String> listenerPaths = generatePaths(uri);

    DBObject match = new BasicDBObject("$match", new BasicDBObject("subscriptions.resource-path", new BasicDBObject("$in", listenerPaths)));
    DBObject unwind = new BasicDBObject("$unwind", "$subscriptions");

    // first perform a match to get the object which contains a subscription we want [uses the index]
    // then unwind to get the individual subscriptions
    // then match again to get only the subscriptions we want.
    // NOTE: the first step is not redundant, we need to first narrow down using an index (for performance) before unwinding and ultimately getting only the results we want.
    AggregationOutput aggregate = collection.aggregate(match, unwind, match);
    for (DBObject dbObject : aggregate.results()) {
        UPSSubscription subscription = UPSSubscription.create((DBObject) dbObject.get("subscriptions"));
        if (subscription != null) {
            subscriptions.add(subscription);
        }
    }

    return subscriptions;
}
 
开发者ID:liveoak-io,项目名称:liveoak,代码行数:24,代码来源:AliasUPSSubscription.java

示例6: fetchAllArticleNumbers

import com.mongodb.AggregationOutput; //导入依赖的package包/类
@Override
public Map<String, Id> fetchAllArticleNumbers() {
    Map<String, Id> articleNumbers = new LinkedHashMap<String, Id>();

    Id attributeId = Attributes.getAttributeId(Product.class, "article_number");

    // build the $projection operation
    DBObject fields = new BasicDBObject("attributes.attr_id", 1);
    fields.put("attributes.val.val", 1);
    DBObject project = new BasicDBObject("$project", fields);

    DBObject unwind = new BasicDBObject("$unwind", "$attributes");

    // create our pipeline operations, first with the $match
    DBObject match = new BasicDBObject("$match", new BasicDBObject("attributes.attr_id", attributeId));

    // build the $projection operation
    DBObject project2 = new BasicDBObject("$project", new BasicDBObject("an", "$attributes.val.val"));

    List<DBObject> pipeline = Arrays.asList(project, unwind, match, project2);

    AggregationOutput output = db(Product.class).getCollection(COLLECTION_NAME).aggregate(pipeline);

    for (DBObject result : output.results()) {
        if (result.get("an") != null) {
            articleNumbers.put(String.valueOf(((BasicDBList) result.get("an")).get(0)).trim(),
                Id.valueOf(result.get("_id")));
        }
    }

    return articleNumbers;
}
 
开发者ID:geetools,项目名称:geeCommerce-Java-Shop-Software-and-PIM,代码行数:33,代码来源:DefaultProductDao.java

示例7: fetchIdArticleNumberMap

import com.mongodb.AggregationOutput; //导入依赖的package包/类
@Override
public Map<Id, String> fetchIdArticleNumberMap() {
    Map<Id, String> articleNumbers = new LinkedHashMap<Id, String>();

    Id attributeId = Attributes.getAttributeId(Product.class, "article_number");

    // build the $projection operation
    DBObject fields = new BasicDBObject("attributes.attr_id", 1);
    fields.put("attributes.val.val", 1);
    DBObject project = new BasicDBObject("$project", fields);

    DBObject unwind = new BasicDBObject("$unwind", "$attributes");

    // create our pipeline operations, first with the $match
    DBObject match = new BasicDBObject("$match", new BasicDBObject("attributes.attr_id", attributeId));

    // build the $projection operation
    DBObject project2 = new BasicDBObject("$project", new BasicDBObject("an", "$attributes.val.val"));

    List<DBObject> pipeline = Arrays.asList(project, unwind, match, project2);

    AggregationOutput output = db(Product.class).getCollection(COLLECTION_NAME).aggregate(pipeline);

    for (DBObject result : output.results()) {
        if (result.get("an") != null) {
            articleNumbers.put(Id.valueOf(result.get("_id")),
                String.valueOf(((BasicDBList) result.get("an")).get(0)).trim());
        }
    }

    return articleNumbers;
}
 
开发者ID:geetools,项目名称:geeCommerce-Java-Shop-Software-and-PIM,代码行数:33,代码来源:DefaultProductDao.java

示例8: getSuggestions

import com.mongodb.AggregationOutput; //导入依赖的package包/类
@Override
public List<String> getSuggestions(Id attributeId, String collectionName, String lang, String query) {
    DBObject val = new BasicDBObject("$elemMatch",
        new BasicDBObject("val", new BasicDBObject("$regex", "^" + query + ".*")));

    DBObject elemMathContent = new BasicDBObject("attr_id", attributeId);
    elemMathContent.put("val", val);

    DBObject elemMatch = new BasicDBObject("$elemMatch", elemMathContent);

    List<DBObject> alls = new ArrayList<>();
    alls.add(elemMatch);

    DBObject match = new BasicDBObject("$match", new BasicDBObject("attributes", new BasicDBObject("$all", alls)));

    DBObject matchAdditionalContent = new BasicDBObject("attributes.attr_id", attributeId);
    if (lang != null && !lang.isEmpty()) {
        matchAdditionalContent.put("attributes.val.l", lang);
    }
    matchAdditionalContent.put("attributes.val.val", new BasicDBObject("$regex", "^" + query + ".*"));

    DBObject matchAdditional = new BasicDBObject("$match", matchAdditionalContent);
    AggregationOutput output = ((DB) connections.getFirstConnection("mongodb")).getCollection(collectionName)
        .aggregate(match, new BasicDBObject("$unwind", "$attributes"),
            new BasicDBObject("$unwind", "$attributes.val"), matchAdditional,
            new BasicDBObject("$group", new BasicDBObject("_id", "$attributes.val.val")),
            new BasicDBObject("$sort", new BasicDBObject("_id", 1)));

    List<String> suggestions = new ArrayList<>();

    for (DBObject result : output.results()) {
        suggestions.add((String) result.get("_id"));
    }

    return suggestions;
}
 
开发者ID:geetools,项目名称:geeCommerce-Java-Shop-Software-and-PIM,代码行数:37,代码来源:DefaultAttributeService.java

示例9: aggregate

import com.mongodb.AggregationOutput; //导入依赖的package包/类
public Iterator<BasicDBObject> aggregate(String description, List<DBObject> pipeline) {
  if (log.isDebugEnabled()) {
    log.debug("--"+dbCollection.getName()+"-> "+description+" q="+toString(pipeline));
  }
  AggregationOutput aggregationOutput = dbCollection.aggregate(pipeline);
  return new LoggingIterator(this, aggregationOutput.results().iterator());
}
 
开发者ID:effektif,项目名称:effektif,代码行数:8,代码来源:MongoCollection.java

示例10: getNumberOfTriples

import com.mongodb.AggregationOutput; //导入依赖的package包/类
/**
 * 
 * @return number of total triples read
 */
public Double getNumberOfTriples() {
	Double numberOfTriples = 0.0;
	try {
		DBCollection collection = DBSuperClass2.getDBInstance().getCollection(DistributionDB.COLLECTION_NAME);

		BasicDBObject select = new BasicDBObject("$match",
				new BasicDBObject(DistributionDB.SUCCESSFULLY_DOWNLOADED, true));

		BasicDBObject groupFields = new BasicDBObject("_id", null);

		groupFields.append("sum", new BasicDBObject("$sum", "$triples"));

		DBObject group = new BasicDBObject("$group", groupFields);

		// run aggregation
		List<DBObject> pipeline = Arrays.asList(select, group);
		AggregationOutput output = collection.aggregate(pipeline);

		for (DBObject result : output.results()) {
			numberOfTriples = Double.valueOf(result.get("sum").toString());
		}

	} catch (Exception e) {
		e.printStackTrace();
	}
	return numberOfTriples;
}
 
开发者ID:AKSW,项目名称:LODVader,代码行数:32,代码来源:DistributionQueries.java

示例11: serializeLoadTimes

import com.mongodb.AggregationOutput; //导入依赖的package包/类
private void serializeLoadTimes(JsonGenerator jgen) throws IOException,
		JsonProcessingException {
	jgen.writeArrayFieldStart("LoadTimes");
	/**
	 * db.hubs.aggregate([ {$project: { "loadtimes" : 1}}, {$unwind :
	 * "$loadtimes"}, {$project: { "truckType" : "$loadtimes.truckType",
	 * "loadTime" : "$loadtimes.loadTime"}}])
	 */

	AggregationOutput agg = getDB().getCollection("hubs").aggregate(
			new BasicDBObject().append("$project",
					new BasicDBObject().append("loadtimes", 1)),
			new BasicDBObject().append("$unwind", "$loadtimes"),
			new BasicDBObject().append(
					"$project",
					new BasicDBObject().append("truckType",
							"$loadtimes.truckType").append("loadTime",
							"$loadtimes.loadTime")));

	for (DBObject obj : agg.results()) {
		jgen.writeStartObject();
		jgen.writeStringField("hub", obj.get("_id").toString());
		jgen.writeStringField("truckType", obj.get("truckType").toString());
		jgen.writeNumberField("loadTime",
				((Number) obj.get("loadTime")).intValue());
		jgen.writeEndObject();
	}
	jgen.writeEndArray();
}
 
开发者ID:IBMDecisionOptimization,项目名称:DOcloud-GreenTruck-sample,代码行数:30,代码来源:TruckingJobInput.java

示例12: serializeRoutes

import com.mongodb.AggregationOutput; //导入依赖的package包/类
private void serializeRoutes(JsonGenerator jgen) throws IOException,
		JsonProcessingException {
	jgen.writeArrayFieldStart("Routes");
	/**
	 * db.hubs.aggregate([ {$project: { "routes" : 1}}, {$unwind :
	 * "$routes"}, {$project: { "spoke" : "$routes.spoke", "distance" :
	 * "$routes.distance"}}])
	 */

	AggregationOutput agg = getDB().getCollection("hubs").aggregate(
			new BasicDBObject().append("$project",
					new BasicDBObject().append("routes", 1)),
			new BasicDBObject().append("$unwind", "$routes"),
			new BasicDBObject().append("$project",
					new BasicDBObject().append("spoke", "$routes.spoke")
							.append("distance", "$routes.distance")));

	for (DBObject obj : agg.results()) {
		jgen.writeStartObject();
		jgen.writeStringField("spoke", obj.get("spoke").toString());
		jgen.writeStringField("hub", obj.get("_id").toString());
		jgen.writeNumberField("distance",
				((Number) obj.get("distance")).intValue());
		jgen.writeEndObject();
	}
	jgen.writeEndArray();
}
 
开发者ID:IBMDecisionOptimization,项目名称:DOcloud-GreenTruck-sample,代码行数:28,代码来源:TruckingJobInput.java

示例13: results

import com.mongodb.AggregationOutput; //导入依赖的package包/类
@Override
public Iterable<DBObject> results(){
    if(options == null){
        AggregationOutput output = coll.aggregate(pipeline);
        return output.results();
    }else{
        final Iterator<DBObject> it = coll.aggregate(pipeline, options);
        return new Iterable<DBObject>() {
            @Override
            public Iterator<DBObject> iterator() {
                return it;
            }
        };
    }
}
 
开发者ID:xbwen,项目名称:bugu-mongo,代码行数:16,代码来源:BuguAggregation.java

示例14: getAsBasicDBList

import com.mongodb.AggregationOutput; //导入依赖的package包/类
/**
 * Convert aggregation output to BasicDBList.
 *
 * @param aggregationOutput aggregation output
 * @return BasicDBList
 */
public static BasicDBList getAsBasicDBList(AggregationOutput aggregationOutput) {
    Validate.notNull(aggregationOutput, "aggregation output cannot be null");
    BasicDBList result = new BasicDBList();
    result.addAll(Lists.newArrayList(aggregationOutput.results()));
    return result;
}
 
开发者ID:jmingo-projects,项目名称:jmingo,代码行数:13,代码来源:ConversionUtils.java

示例15: queryForList

import com.mongodb.AggregationOutput; //导入依赖的package包/类
@Override
<T> List<T> queryForList(QueryStatement queryStatement, Class<T> type) {
    DBCollection dbCollection = getDbCollection(queryStatement.getCollectionName());
    BasicDBList query = (BasicDBList) JSON_TO_DB_OBJECT_MARSHALLER.marshall(queryStatement.getPreparedQuery(),
            queryStatement.getParameters());
    AggregationOutput aggregationOutput = performAggregationQuery(dbCollection, query);
    BasicDBList source = getAsBasicDBList(aggregationOutput);
    List<T> result = convertList(type, source, queryStatement.getConverterClass(),
            queryStatement.getConverterMethod());
    return result != null ? result : Lists.<T>newArrayList();
}
 
开发者ID:jmingo-projects,项目名称:jmingo,代码行数:12,代码来源:MongoQueryExecutor.java


注:本文中的com.mongodb.AggregationOutput类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。