Esempio n. 1
0
    intrusive_ptr<DocumentSource> DocumentSourceGroup::createMerger() {
	intrusive_ptr<DocumentSourceGroup> pMerger(
	    DocumentSourceGroup::create(pCtx));

	/* the merger will use the same grouping key */
	pMerger->setIdExpression(ExpressionFieldPath::create(
				     Document::idName.c_str()));

	const size_t n = vFieldName.size();
	for(size_t i = 0; i < n; ++i) {
	    /*
	      The merger's output field names will be the same, as will the
	      accumulator factories.  However, for some accumulators, the
	      expression to be accumulated will be different.  The original
	      accumulator may be collecting an expression based on a field
	      expression or constant.  Here, we accumulate the output of the
	      same name from the prior group.
	    */
	    pMerger->addAccumulator(
		vFieldName[i], vpAccumulatorFactory[i],
		ExpressionFieldPath::create(vFieldName[i]));
	}

	return pMerger;
    }
Esempio n. 2
0
    intrusive_ptr<DocumentSource> DocumentSourceGroup::getRouterSource() {
        intrusive_ptr<ExpressionContext> pMergerExpCtx = pExpCtx->clone();
        pMergerExpCtx->setDoingMerge(true);
        intrusive_ptr<DocumentSourceGroup> pMerger(DocumentSourceGroup::create(pMergerExpCtx));

        /* the merger will use the same grouping key */
        pMerger->setIdExpression(ExpressionFieldPath::parse("$$ROOT._id"));

        const size_t n = vFieldName.size();
        for(size_t i = 0; i < n; ++i) {
            /*
              The merger's output field names will be the same, as will the
              accumulator factories.  However, for some accumulators, the
              expression to be accumulated will be different.  The original
              accumulator may be collecting an expression based on a field
              expression or constant.  Here, we accumulate the output of the
              same name from the prior group.
            */
            pMerger->addAccumulator(
                vFieldName[i], vpAccumulatorFactory[i],
                ExpressionFieldPath::parse("$$ROOT." + vFieldName[i]));
        }

        return pMerger;
    }