Pārlūkot izejas kodu

EAGLESIX-812 Fix jshint errors; fix some weird test issues in sort

Chris Sexton 11 gadi atpakaļ
vecāks
revīzija
87ed3598d7

+ 0 - 1
lib/index.js

@@ -79,7 +79,6 @@ exports.SYNC_CALLBACK = function(err, docs){
 exports.aggregate = exports;
 
 //Expose these so that mungedb-aggregate can be extended.
-exports.Cursor = require("./Cursor");
 exports.pipeline = require("./pipeline/");
 exports.query = require("./query/");
 

+ 4 - 5
lib/pipeline/Pipeline.js

@@ -228,8 +228,7 @@ klass.optimizations.sharded.findSplitPoint = function findSplitPoint(shardPipe,
  */
 klass.optimizations.sharded.moveFinalUnwindFromShardsToMerger = function moveFinalUnwindFromShardsToMerger(shardPipe, mergePipe) {
 	if (true) {
-		while(shardPipe.sources !== null && (shardPipe.sources.length > 0
-				&& shardPipe.sources[shardPipe.sources.length-1] instanceof UnwindDocumentSource)) {
+		while(shardPipe.sources !== null && (shardPipe.sources.length > 0 && shardPipe.sources[shardPipe.sources.length-1] instanceof UnwindDocumentSource)) {
 			mergePipe.sources.unshift(shardPipe.sources.pop());
 		}
 	}
@@ -399,11 +398,11 @@ proto.stitch = function stitch() {
 proto.run = function run(callback) {
 	// should not get here in the explain case
 	if(this.explain) throw new Error("Should not be running a pipeline in explain mode!");
-	
+
 	var doc = null,
 		error = null,
 		finalSource = this._getFinalSource();
-	
+
 	async.doWhilst(
 		function iterator(next){
 			return finalSource.getNext(function (err, obj){
@@ -458,7 +457,7 @@ proto.addInitialSource = function addInitialSource(source) {
 //Note: Deviation from Mongo: Mongo 2.6.5 passes a param to getDependencies
 //	to calculate TextScore.  mungedb-aggregate doesn't do this, so no param is needed.
 proto.getDependencies = function getDependencies () {
-    var deps = new DepsTracker(), 
+    var deps = new DepsTracker(),
 		knowAllFields = false;
 
     //NOTE: Deviation from Mongo -- We aren't using Meta and textscore

+ 4 - 3
lib/pipeline/documentSources/GroupDocumentSource.js

@@ -511,17 +511,18 @@ proto._getTypeStr = function _getTypeStr(obj) {
 
 proto.getShardSource = function getShardSource() {
 	return this;
-}
+};
 
 proto.getMergeSource = function getMergeSource() {
-	var merger = klass.create(this.expCtx);
+	var self = this,
+		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));
+		merger.addAccumulator(self.fieldNames[i], self.accumulatorFactories[i], FieldPathExpression.create("$$ROOT." + self.fieldNames[i], vps));
 	}
 
 	return merger;

+ 9 - 20
lib/pipeline/documentSources/SortDocumentSource.js

@@ -179,25 +179,17 @@ proto.makeSortOptions = function makeSortOptions(){
 
 	var opts;
 	if ( this.limitSrc)
-		opts.limit = limitSrc.getLimt();
+		opts.limit = this.limitSrc.getLimt();
 
 	return opts;
-}
+};
 
 
 proto.populate = function populate(callback) {
 	if ( this._mergePresorted ){
 		// Skipping stuff about mergeCursors and commandShards
-
-		if ( this.source instanceof MergeCursorDocumentSouce ){
-			populateFromCursors( this.source);
-		} else if ( this.source instanceof CommandShardsDocumentSource){
-			populateFromJsonArrays(this.source);
-		} else {
-			throw new Error("code 17196; the " + klass.sortName + "can only mergePresorted from MergeCursors and CommandShards");
-		}
+		throw new Error("Merge presorted not implemented.");
 	} else {
-
 		/* pull everything from the underlying source */
 		var self = this,
 			next;
@@ -251,7 +243,7 @@ klass.IteratorFromCursor = (function(){
 	};
 
 	proto.next = function next() {
-		var doc = DocumentSourceMergeCursors(this._cursor);
+		// var doc = new DocumentSourceMergeCursors(this._cursor);
 		// TODO: make_pair for return
 		//return {this._sorter.extractKey(doc): doc};
 	};
@@ -266,7 +258,7 @@ proto.populateFromCursors = function populateFromCursors(cursors){
 
 	this._output.reset( ); // TODO: MySorter::Iterator::merge(iterators, makeSortOptions(), Comparator(*this))
 
-}
+};
 
 klass.IteratorFromBsonArray = (function(){
 	/**
@@ -280,7 +272,7 @@ klass.IteratorFromBsonArray = (function(){
 	}, base = Object, proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
 
 	proto.next = function next() {
-		var doc = DocumentSourceMergeCursors(this._cursor);
+		// var doc = new DocumentSourceMergeCursors(this._cursor);
 		// TODO: make_pair for return
 		//return {this._sorter.extractKey(doc): doc};
 	};
@@ -298,7 +290,8 @@ proto.populateFromBsonArrays = function populateFromBsonArrays(arrays){
 		//this.iterators.push(boost::make_shared<IteratorFromBsonArray>(this, arrays[i]));
 	}
 	this._output.reset( ); // TODO: MySorter::Iterator::merge(iterators, makeSortOptions(), Comparator(*this))
-}
+};
+
 /**
 * Extract the key
 *
@@ -316,7 +309,7 @@ proto.extractKey = function extractKey(d){
 		keys.push(this.vSortKey[i].evaluate(vars));
 	}
 	return keys;
-}
+};
 
 /**
  * Compare two documents according to the specified sort key.
@@ -420,10 +413,6 @@ klass.create = function create(expCtx, sortOrder, limit) {
 		if ( keyField instanceof Object) {
 			// this restriction is due to needing to figure out sort direction
 			throw new Error("code 17312; " + klass.sortName + "the only expression supported by $sort right now is {$meta: 'textScore'}");
-
-			nextSort.vSortKey.push(new ExpressionMeta());
-			nextSort.vAscending.push(false); // best scoring documents first
-			continue;
 		}
 
 		if (typeof sortOrder[keyField] !== "number") throw new Error("code 15974; " + klass.sortName + "$sort key ordering must be specified using a number or {$meta: 'text'}");

+ 2 - 4
test/lib/pipeline/Pipeline.js

@@ -26,10 +26,8 @@ var shardedTest = function(inputPipeString, expectedMergePipeString, expectedSha
 	var shardPipe = mergePipe.splitForSharded();
 	assert.notEqual(shardPipe, null);
 
-	assert.deepEqual(shardPipe.serialize()["pipeline"], 
-		expectedShardPipe["pipeline"]);
-	assert.deepEqual(mergePipe.serialize()["pipeline"],
-		expectedMergePipe["pipeline"]);
+	assert.deepEqual(shardPipe.serialize().pipeline, expectedShardPipe.pipeline);
+	assert.deepEqual(mergePipe.serialize().pipeline, expectedMergePipe.pipeline);
 };
 
 module.exports = {

+ 1 - 1
test/lib/pipeline/documentSources/SortDocumentSource.js

@@ -569,7 +569,7 @@ module.exports = {
 
 				var deps = {fields: {}, needWholeDocument: false, needTextScore: false};
 
-				assert.equal('SEE_NEXT', sds.getDependencies(deps));
+				assert.equal(DocumentSource.GetDepsReturn.SEE_NEXT, sds.getDependencies(deps));
 				// Sort keys are now part of deps fields.
 				assert.equal(3, Object.keys(deps.fields).length);
 			 	assert.equal(1, deps.fields.a);