|
|
@@ -108,14 +108,20 @@ proto.getNext = function getNext(callback) {
|
|
|
if(self.currentGroupsKeysIndex === self.groupsKeys.length) {
|
|
|
return next(null, null);
|
|
|
}
|
|
|
-
|
|
|
- var id = self.originalGroupsKeys[self.currentGroupsKeysIndex],
|
|
|
- stringifiedId = self.groupsKeys[self.currentGroupsKeysIndex],
|
|
|
- accumulators = self.groups[stringifiedId],
|
|
|
+
|
|
|
+ var out;
|
|
|
+ try {
|
|
|
+ var id = self.originalGroupsKeys[self.currentGroupsKeysIndex],
|
|
|
+ stringifiedId = self.groupsKeys[self.currentGroupsKeysIndex],
|
|
|
+ accumulators = self.groups[stringifiedId];
|
|
|
+
|
|
|
out = self.makeDocument(id, accumulators, self.expCtx.inShard);
|
|
|
|
|
|
- if(++self.currentGroupsKeysIndex === self.groupsKeys.length) {
|
|
|
- self.dispose();
|
|
|
+ if(++self.currentGroupsKeysIndex === self.groupsKeys.length) {
|
|
|
+ self.dispose();
|
|
|
+ }
|
|
|
+ } catch (ex) {
|
|
|
+ return next(ex);
|
|
|
}
|
|
|
|
|
|
return next(null, out);
|
|
|
@@ -300,44 +306,46 @@ proto.populate = function populate(callback) {
|
|
|
input = doc;
|
|
|
return cb(); //Need to stop now, no new input
|
|
|
}
|
|
|
+ try {
|
|
|
+ input = doc;
|
|
|
+ self.variables.setRoot(input);
|
|
|
|
|
|
- input = doc;
|
|
|
- self.variables.setRoot(input);
|
|
|
-
|
|
|
- /* get the _id value */
|
|
|
- var id = self.computeId(self.variables);
|
|
|
+ /* get the _id value */
|
|
|
+ var id = self.computeId(self.variables);
|
|
|
|
|
|
- if(undefined === id) id = null;
|
|
|
+ if(undefined === id) id = null;
|
|
|
|
|
|
- var groupKey = JSON.stringify(id),
|
|
|
- group = self.groups[groupKey];
|
|
|
+ var groupKey = JSON.stringify(id),
|
|
|
+ group = self.groups[groupKey];
|
|
|
|
|
|
- if(!group) {
|
|
|
- self.originalGroupsKeys.push(id);
|
|
|
- self.groupsKeys.push(groupKey);
|
|
|
- group = [];
|
|
|
- self.groups[groupKey] = group;
|
|
|
- // Add the accumulators
|
|
|
- for(var afi = 0; afi<self.accumulatorFactories.length; afi++) {
|
|
|
- group.push(new self.accumulatorFactories[afi]());
|
|
|
+ if(!group) {
|
|
|
+ self.originalGroupsKeys.push(id);
|
|
|
+ self.groupsKeys.push(groupKey);
|
|
|
+ group = [];
|
|
|
+ self.groups[groupKey] = group;
|
|
|
+ // Add the accumulators
|
|
|
+ for(var afi = 0; afi<self.accumulatorFactories.length; afi++) {
|
|
|
+ group.push(new self.accumulatorFactories[afi]());
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- //NOTE: Skipped memory usage stuff for case when group already existed
|
|
|
+ //NOTE: Skipped memory usage stuff for case when group already existed
|
|
|
|
|
|
- if(numAccumulators !== group.length) {
|
|
|
- throw new Error('Group must have one of each accumulator');
|
|
|
- }
|
|
|
-
|
|
|
- //NOTE: passing the input to each accumulator
|
|
|
- for(var gi=0; gi<group.length; gi++) {
|
|
|
- group[gi].process(self.expressions[gi].evaluate(self.variables, self.doingMerge));
|
|
|
- }
|
|
|
+ if(numAccumulators !== group.length) {
|
|
|
+ throw new Error('Group must have one of each accumulator');
|
|
|
+ }
|
|
|
|
|
|
- // We are done with the ROOT document so release it.
|
|
|
- self.variables.clearRoot();
|
|
|
+ //NOTE: passing the input to each accumulator
|
|
|
+ for(var gi=0; gi<group.length; gi++) {
|
|
|
+ group[gi].process(self.expressions[gi].evaluate(self.variables, self.doingMerge));
|
|
|
+ }
|
|
|
|
|
|
- //NOTE: Skipped the part about sorted files
|
|
|
+ // We are done with the ROOT document so release it.
|
|
|
+ self.variables.clearRoot();
|
|
|
|
|
|
+ //NOTE: Skipped the part about sorted files
|
|
|
+ } catch (ex) {
|
|
|
+ return cb(ex);
|
|
|
+ }
|
|
|
return cb();
|
|
|
});
|
|
|
},
|