Browse Source

EAGLESIX-3087: Working toward working tests.

Jason Walton 11 years ago
parent
commit
87ac09299b
2 changed files with 37 additions and 35 deletions
  1. 36 34
      lib/pipeline/Pipeline.js
  2. 1 1
      test/lib/pipeline/Pipeline.js

+ 36 - 34
lib/pipeline/Pipeline.js

@@ -16,6 +16,8 @@ var Pipeline = module.exports = function Pipeline(theCtx){
 	this.SYNC_MODE = false;
 }, klass = Pipeline, base = Object, proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
 
+var DepsTracker = require("./DepsTracker");
+
 var DocumentSource = require("./documentSources/DocumentSource"),
 	LimitDocumentSource = require('./documentSources/LimitDocumentSource'),
 	MatchDocumentSource = require('./documentSources/MatchDocumentSource'),
@@ -237,39 +239,39 @@ klass.optimizations.sharded.moveFinalUnwindFromShardsToMerger = function moveFin
  * @param shardPipe shard sources
  * @param mergePipe merge sources
  */
-klass.optimizations.sharded.limitFieldsSentFromShardsToMerger = function limitFieldsSentFromShardsToMerger(shardPipe, mergePipe) {
-	var mergeDeps = mergePipe.getDependencies(shardPipe.getInitialQuery());
-	if (mergeDeps.needWholeDocument) {
-		return;
-	}
-	if (mergeDeps.fields == null) {
-		mergeDeps.fields = {};
-	}
-	if (mergeDeps.fields.length == 0) {
-		mergeDeps.fields["_id"] = 0;
-	}
-	if (shardPipe.sources == null) {
-		shardPipe.sources = {};
-	}
-	//NOTE: Deviation from Mongo: not setting mergeDeps.needTextScore because we aren't handling that (Document meta stuff)
-
-    // HEURISTIC: only apply optimization if none of the shard stages have an exhaustive list of
-    // field dependencies. While this may not be 100% ideal in all cases, it is simple and
-    // avoids the worst cases by ensuring that:
-    // 1) Optimization IS applied when the shards wouldn't have known their exhaustive list of
-    //    dependencies. This situation can happen when a $sort is before the first $project or
-    //    $group. Without the optimization, the shards would have to reify and transmit full
-    //    objects even though only a subset of fields are needed.
-    // 2) Optimization IS NOT applied immediately following a $project or $group since it would
-    //    add an unnecessary project (and therefore a deep-copy).
-    for (var i = 0; i < shardPipe.sources.length; i++) {
-        if (shardPipe.sources.getDependencies() & DocumentSource.GetDepsReturn.EXHAUSTIVE_FIELDS)
-            return;
-    }
-
-    // if we get here, add the project.
-    shardPipe.sources.push(ProjectDocumentSource.createFromJson({"$project": mergeDeps.toProjection()[0]}, shardPipe.ctx));
-};
+// klass.optimizations.sharded.limitFieldsSentFromShardsToMerger = function limitFieldsSentFromShardsToMerger(shardPipe, mergePipe) {
+// 	var mergeDeps = mergePipe.getDependencies(shardPipe.getInitialQuery());
+// 	if (mergeDeps.needWholeDocument) {
+// 		return;
+// 	}
+// 	if (mergeDeps.fields == null) {
+// 		mergeDeps.fields = {};
+// 	}
+// 	if (mergeDeps.fields.length == 0) {
+// 		mergeDeps.fields["_id"] = 0;
+// 	}
+// 	if (shardPipe.sources == null) {
+// 		shardPipe.sources = {};
+// 	}
+// 	//NOTE: Deviation from Mongo: not setting mergeDeps.needTextScore because we aren't handling that (Document meta stuff)
+
+//     // HEURISTIC: only apply optimization if none of the shard stages have an exhaustive list of
+//     // field dependencies. While this may not be 100% ideal in all cases, it is simple and
+//     // avoids the worst cases by ensuring that:
+//     // 1) Optimization IS applied when the shards wouldn't have known their exhaustive list of
+//     //    dependencies. This situation can happen when a $sort is before the first $project or
+//     //    $group. Without the optimization, the shards would have to reify and transmit full
+//     //    objects even though only a subset of fields are needed.
+//     // 2) Optimization IS NOT applied immediately following a $project or $group since it would
+//     //    add an unnecessary project (and therefore a deep-copy).
+//     for (var i = 0; i < shardPipe.sources.length; i++) {
+//         if (shardPipe.sources.getDependencies() & DocumentSource.GetDepsReturn.EXHAUSTIVE_FIELDS)
+//             return;
+//     }
+
+//     // if we get here, add the project.
+//     shardPipe.sources.push(ProjectDocumentSource.createFromJson({$project: mergeDeps.toProjection()[0]}, shardPipe.ctx));
+// };
 
 /**
  * Create an `Array` of `DocumentSource`s from the given JSON pipeline
@@ -526,7 +528,7 @@ proto.getDependencies = function getDependencies (initialQuery) {
     var deps, knowAllFields = false;
 
     if (this.sources == null || this.sources.length == 0)
-    	return {};
+    	return new DepsTracker();
 
     //NOTE: Deviation from Mongo -- We aren't using Meta and textscore
     for (var i=0; i < this.sources.length() && !knowAllFields; i++) {

+ 1 - 1
test/lib/pipeline/Pipeline.js

@@ -164,7 +164,7 @@ module.exports = {
 
 			"should handle two unwinds": function () {
 				var inputPipe = "[{$unwind: '$a'}, {$unwind: '$b'}]}",
-					expectedMergePipe = "[]}",
+					expectedMergePipe = "[]",
 					expectedShardPipe = "[{$unwind: '$a'}, {$unwind: '$b'}]}";
 				shardedTest(inputPipe, expectedMergePipe, expectedShardPipe);