Преглед изворни кода

EAGLESIX-812: fixed bug in GroupDocumentSource

Phil Murray пре 11 година
родитељ
комит
20e9d9233e
2 измењених фајлова са 25 додато и 9 уклоњено
  1. 1 1
      lib/pipeline/documentSources/GroupDocumentSource.js
  2. 24 8
      test/lib/aggregate.js

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

@@ -404,7 +404,7 @@ proto.makeDocument = function makeDocument(id, accums, mergeableOutput) {
 	/* add the rest of the fields */
 	this.fieldNames.forEach(function(fieldName, i) {
 		var val = accums[i].getValue(mergeableOutput);
-		if (!val) {
+		if (val === undefined) {
 			out[fieldName] = null;
 		} else {
 			out[fieldName] = val;

+ 24 - 8
test/lib/aggregate.js

@@ -74,7 +74,6 @@ module.exports = {
 	"aggregate": {
 
 		"should be able to use an empty pipeline (no-op)": function(next){
-			debugger;
 			testAggregate({
 				inputs: [1, 2, 3],
 				pipeline: [],
@@ -209,9 +208,6 @@ module.exports = {
 		},
 
 		"should be able to construct an instance with $group operators properly": function(next){
-			// NOTE: Test case broken until expression is fixed
-			
-			debugger;
 			testAggregate({
 				inputs: [
 					{_id:0, a:1},
@@ -245,8 +241,8 @@ module.exports = {
 						//min_a:1,
 						max_a:4,
 						avg_a:2.3,
-						first_b:undefined,
-						last_b:undefined,
+						first_b:null,
+						last_b:null,
 						addToSet_b:[],
 						push_b:[]
 					},
@@ -254,7 +250,7 @@ module.exports = {
 						_id:1,
 						sum_a:0,
 						//min_a:null,
-						max_a:undefined,
+						max_a:null,
 						avg_a:0,
 						first_b:"a",
 						last_b:"c",
@@ -267,7 +263,6 @@ module.exports = {
 		},
 
 		"should be able to construct an instance with $group using concat": function(next){
-			// NOTE: Test case broken until expression is fixed; not sure if that concat is supposed to work
 			testAggregate({
 				inputs: [
 					{_id:0, a:null},
@@ -369,6 +364,27 @@ module.exports = {
 				next: next
 			});
 		},
+		
+		"should be able to handle a large array of inputs": function(next){
+			var inputs = [],
+				expected = [];
+			for(var i = 0; i < 10; i++){
+				inputs.push({a:i});
+				expected.push({foo:i});
+			}
+			testAggregate({
+				inputs: inputs,
+				pipeline: {
+					batchSize:Infinity,
+					pipeline: [
+					{$project:{
+						foo: "$a"
+					}}
+				]},
+				expected: expected,
+				next: next
+			});
+		}
 	}
 
 };