Kaynağa Gözat

Refs #2061: moving into e6-mungedb-aggregate.

Charles Ezell 13 yıl önce
ebeveyn
işleme
59ce881a8a

+ 2 - 3
README.md

@@ -7,8 +7,8 @@ In general, this code is a port from the MongoDB C++ code (v2.4.0) to JavaScript
 
 
 exports
 exports
 -------
 -------
-aggregate
-Aggregator
+* aggregate
+* Aggregator
 
 
 
 
 Deviations
 Deviations
@@ -35,7 +35,6 @@ Here is a list of the major items where we have deviated from the MongoDB code a
       * DESIGN: The `{FOO}Expression` classes do not provide `create` statics since calling new is easy enough
       * DESIGN: The `{FOO}Expression` classes do not provide `create` statics since calling new is easy enough
         * DESIGN: To further this, the `CompareExpression` class doesn't provide any of it's additional `create{FOO}` helpers so instead I'm binding the appropriate args to the `constructor`
         * DESIGN: To further this, the `CompareExpression` class doesn't provide any of it's additional `create{FOO}` helpers so instead I'm binding the appropriate args to the `constructor`
       * EXTENSIONS: The following are extended `munge`-only expressions that have not been ported back to MongoDB yet
       * EXTENSIONS: The following are extended `munge`-only expressions that have not been ported back to MongoDB yet
-        * `IndexOfExpression` or `$indexOf` - A new `Expression` that returns the index of an item in an `Array` or `String`
     * `DocumentSource` classes
     * `DocumentSource` classes
       * DESIGN: We have implemented a `reset` method for all document sources so that we can reuse them against different streams of data
       * DESIGN: We have implemented a `reset` method for all document sources so that we can reuse them against different streams of data
 
 

+ 0 - 1
lib/pipeline/expressions/Expression.js

@@ -179,7 +179,6 @@ var Expression = module.exports = (function(){
 					new OpDesc("$gte", CompareExpression.bind(null, Expression.CmpOp.GTE), OpDesc.FIXED_COUNT, 2),
 					new OpDesc("$gte", CompareExpression.bind(null, Expression.CmpOp.GTE), OpDesc.FIXED_COUNT, 2),
 					new OpDesc("$hour", require("./HourExpression"), OpDesc.FIXED_COUNT, 1),
 					new OpDesc("$hour", require("./HourExpression"), OpDesc.FIXED_COUNT, 1),
 					new OpDesc("$ifNull", require("./IfNullExpression"), OpDesc.FIXED_COUNT, 2),
 					new OpDesc("$ifNull", require("./IfNullExpression"), OpDesc.FIXED_COUNT, 2),
-					new OpDesc("$indexOf", require("./IndexOfExpression"), OpDesc.FIXED_COUNT, 2),
 					new OpDesc("$lt", CompareExpression.bind(null, Expression.CmpOp.LT), OpDesc.FIXED_COUNT, 2),
 					new OpDesc("$lt", CompareExpression.bind(null, Expression.CmpOp.LT), OpDesc.FIXED_COUNT, 2),
 					new OpDesc("$lte", CompareExpression.bind(null, Expression.CmpOp.LTE), OpDesc.FIXED_COUNT, 2),
 					new OpDesc("$lte", CompareExpression.bind(null, Expression.CmpOp.LTE), OpDesc.FIXED_COUNT, 2),
 					new OpDesc("$minute", require("./MinuteExpression"), OpDesc.FIXED_COUNT, 1),
 					new OpDesc("$minute", require("./MinuteExpression"), OpDesc.FIXED_COUNT, 1),

+ 0 - 46
lib/pipeline/expressions/IndexOfExpression.js

@@ -1,46 +0,0 @@
-"use strict";
-var IndexOfExpression = module.exports = (function(){
-	// CONSTRUCTOR
-	/**
-	 * An $indexOf pipeline expression.
-	 *
-	 * @see evaluate
-	 * @class IndexOfExpression
-	 * @namespace mungedb.aggregate.pipeline.expressions
-	 * @module mungedb-aggregate
-	 * @constructor
-	 **/
-	var klass = function IndexOfExpression(){
-		if(arguments.length !== 0) throw new Error("zero args expected");
-		base.call(this);
-	}, base = require("./NaryExpression"), proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
-
-	// PROTOTYPE MEMBERS
-	proto.getOpName = function getOpName(){
-		return "$indexOf";
-	};
-
-	proto.addOperand = function addOperand(expr) {
-		this.checkArgLimit(2);
-		base.prototype.addOperand.call(this, expr);
-	};
-
-	/**
-	 * Use the $indexOf operator with the following syntax: { $indexOf: [ <needle>, <haystack> ] }
-	 * @method evaluate
-	 **/
-	proto.evaluate = function evaluate(doc){
-		this.checkArgCount(2);
-
-		var left = this.operands[0].evaluate(doc);
-		if (left === undefined) return undefined;
-
-		var right = this.operands[1].evaluate(doc);
-		if (right === undefined) return undefined;
-		if (!(right instanceof Array)) throw new Error("UserAssertion: expected the 2nd arg of the $indexOf expression to be an Array but got " + (typeof right === "object" ? right.constructor.name : typeof right));
-
-		return right.indexOf(left);
-	};
-
-	return klass;
-})();

+ 0 - 1
lib/pipeline/expressions/index.js

@@ -15,7 +15,6 @@ module.exports = {
 	FieldRangeExpression: require("./FieldRangeExpression.js"),
 	FieldRangeExpression: require("./FieldRangeExpression.js"),
 	HourExpression: require("./HourExpression.js"),
 	HourExpression: require("./HourExpression.js"),
 	IfNullExpression: require("./IfNullExpression.js"),
 	IfNullExpression: require("./IfNullExpression.js"),
-	IndexOfExpression: require("./IndexOfExpression.js"),
 	MinuteExpression: require("./MinuteExpression.js"),
 	MinuteExpression: require("./MinuteExpression.js"),
 	ModExpression: require("./ModExpression.js"),
 	ModExpression: require("./ModExpression.js"),
 	MonthExpression: require("./MonthExpression.js"),
 	MonthExpression: require("./MonthExpression.js"),

+ 0 - 70
test/lib/pipeline/expressions/IndexOfExpression.js

@@ -1,70 +0,0 @@
-"use strict";
-var assert = require("assert"),
-	IndexOfExpression = require("../../../../lib/pipeline/expressions/IndexOfExpression"),
-	Expression = require("../../../../lib/pipeline/expressions/Expression");
-
-
-module.exports = {
-
-	"IndexOfExpression": {
-
-		"constructor()": {
-
-			"should not throw Error when constructing without args": function testConstructor(){
-				assert.doesNotThrow(function(){
-					new IndexOfExpression();
-				});
-			}
-
-		},
-
-		"#getOpName()": {
-
-			"should return the correct op name; $indexOf": function testOpName(){
-				assert.equal(new IndexOfExpression().getOpName(), "$indexOf");
-			}
-
-		},
-
-		"#getFactory()": {
-
-			"should return the constructor for this class": function factoryIsConstructor(){
-				assert.strictEqual(new IndexOfExpression().getFactory(), undefined);
-			}
-
-		},
-
-		"#evaluate()": {
-
-			"should return the index of the first match if found": function testFound(){
-				assert.strictEqual(Expression.parseOperand({$indexOf:["$needle", "$haystack"]}).evaluate({needle:1, haystack:[1,2,3]}), 0);
-				assert.strictEqual(Expression.parseOperand({$indexOf:["$needle", "$haystack"]}).evaluate({needle:3, haystack:[1,2,3]}), 2);
-			},
-
-			"should return `-1` if not found": function testNotFound(){
-				assert.strictEqual(Expression.parseOperand({$indexOf:["$needle", "$haystack"]}).evaluate({needle:0, haystack:[1,2,3]}), -1);
-			},
-
-			"should return `undefined` if the 1st arg (the `needle`) is undefined or missing": function testNeedleUndefinedOrMissing(){
-				assert.strictEqual(Expression.parseOperand({$indexOf:["$needle", "$haystack"]}).evaluate({needle:undefined, haystack:[1,2,3]}), undefined);
-				assert.strictEqual(Expression.parseOperand({$indexOf:["$needle", "$haystack"]}).evaluate({haystack:[1,2,3]}), undefined);
-			},
-
-			"should return `undefined` if the 1st arg (the `haystack`) is undefined or missing": function testHaystackUndefinedOrMissing(){
-				assert.strictEqual(Expression.parseOperand({$indexOf:["$needle", "$haystack"]}).evaluate({needle:0, haystack:undefined}), undefined);
-				assert.strictEqual(Expression.parseOperand({$indexOf:["$needle", "$haystack"]}).evaluate({needle:0}), undefined);
-			},
-
-			"should throw if 2nd arg (the `haystack`) is not an `Array`": function testHaystackNonArray(){
-				assert.throws(function(){
-					Expression.parseOperand({$indexOf:["$needle", "$haystack"]}).evaluate({needle:0, haystack:0});
-				});
-			}
-
-		}
-
-	}
-
-};
-
-if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);