Browse Source

EAGLESIX-812 Add splittable functions

Chris Sexton 11 years ago
parent
commit
64893e6dde
1 changed files with 20 additions and 1 deletions
  1. 20 1
      lib/pipeline/documentSources/GroupDocumentSource.js

+ 20 - 1
lib/pipeline/documentSources/GroupDocumentSource.js

@@ -40,9 +40,10 @@ var GroupDocumentSource = module.exports = function GroupDocumentSource(expCtx)
 	this.expressions = [];
 	this.idExpressions = [];
 	this.currentGroupsKeysIndex = 0;
-
 }, klass = GroupDocumentSource, base = DocumentSource, proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
 
+klass.isSplittableDocumentSource = true;
+
 // TODO: Do we need this?
 klass.groupOps = {
 	"$addToSet": Accumulators.AddToSetAccumulator.create,
@@ -507,3 +508,21 @@ proto._getTypeStr = function _getTypeStr(obj) {
 		typeStr = (typeofStr == "object" && obj !== null) ? obj.constructor.name : typeofStr;
 	return typeStr;
 };
+
+proto.getShardSource = function getShardSource() {
+	return this;
+}
+
+proto.getMergeSource = function getMergeSource() {
+	var merger = klass.create(this.expCtx);
+
+	var idGenerator = new VariablesIdGenerator(),
+		vps = new VariablesParseState(idGenerator);
+
+	merger.idExpressions.push(FieldPathExpression.parse("$$ROOT._id", vps));
+	for (var i = 0; i < self.fieldNames.length; i++) {
+		merger.addAccumulator(self.fieldNames[i], self.accumulatorFactories[i], FieldPathExpression("$$ROOT." + self.fieldNames[i], vps));
+	}
+
+	return merger;
+};