|
@@ -1,8 +1,7 @@
|
|
|
"use strict";
|
|
"use strict";
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * A base class for all pipeline accumulators. Uses NaryExpression as a base class.
|
|
|
|
|
- *
|
|
|
|
|
|
|
+ * A base class for all pipeline accumulators.
|
|
|
* @class Accumulator
|
|
* @class Accumulator
|
|
|
* @namespace mungedb-aggregate.pipeline.accumulators
|
|
* @namespace mungedb-aggregate.pipeline.accumulators
|
|
|
* @module mungedb-aggregate
|
|
* @module mungedb-aggregate
|
|
@@ -10,66 +9,59 @@
|
|
|
**/
|
|
**/
|
|
|
var Accumulator = module.exports = function Accumulator(){
|
|
var Accumulator = module.exports = function Accumulator(){
|
|
|
if (arguments.length !== 0) throw new Error("zero args expected");
|
|
if (arguments.length !== 0) throw new Error("zero args expected");
|
|
|
- this._memUsageBytes = 0;
|
|
|
|
|
base.call(this);
|
|
base.call(this);
|
|
|
}, klass = Accumulator, base = Object, proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
|
|
}, klass = Accumulator, base = Object, proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
|
|
|
|
|
|
|
|
-// DEPENDENCIES
|
|
|
|
|
-// var Value = require("../Value"),
|
|
|
|
|
-
|
|
|
|
|
-proto.memUsageForSorter = function memUsageForSorter() {
|
|
|
|
|
- return this._memUsageBytes;
|
|
|
|
|
-};
|
|
|
|
|
-
|
|
|
|
|
-proto.getFactory = function getFactory(){
|
|
|
|
|
- return klass; // using the ctor rather than a separate .create() method
|
|
|
|
|
-};
|
|
|
|
|
-
|
|
|
|
|
/** Process input and update internal state.
|
|
/** Process input and update internal state.
|
|
|
- * merging should be true when processing outputs from getValue(true).
|
|
|
|
|
|
|
+ * merging should be true when processing outputs from getValue(true).
|
|
|
|
|
+ * @method process
|
|
|
|
|
+ * @param input {Value}
|
|
|
|
|
+ * @param merging {Boolean}
|
|
|
*/
|
|
*/
|
|
|
-proto.process = function process(input, merging){
|
|
|
|
|
|
|
+proto.process = function process(input, merging) {
|
|
|
this.processInternal(input, merging);
|
|
this.processInternal(input, merging);
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
-proto.toJSON = function toJSON(isExpressionRequired){
|
|
|
|
|
- var rep = {};
|
|
|
|
|
- rep[this.getOpName()] = this.operands[0].toJSON(isExpressionRequired);
|
|
|
|
|
- return rep;
|
|
|
|
|
|
|
+/** Marks the end of the evaluate() phase and return accumulated result.
|
|
|
|
|
+ * toBeMerged should be true when the outputs will be merged by process().
|
|
|
|
|
+ * @method getValue
|
|
|
|
|
+ * @param toBeMerged {Boolean}
|
|
|
|
|
+ * @return {Value}
|
|
|
|
|
+ */
|
|
|
|
|
+proto.getValue = function getValue(toBeMerged) {
|
|
|
|
|
+ throw new Error("You need to define this function on your accumulator");
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * If this function is not overridden in the sub classes,
|
|
|
|
|
- * then throw an error
|
|
|
|
|
- *
|
|
|
|
|
- **/
|
|
|
|
|
|
|
+ * The name of the op as used in a serialization of the pipeline.
|
|
|
|
|
+ * @method getOpName
|
|
|
|
|
+ * @return {String}
|
|
|
|
|
+ */
|
|
|
proto.getOpName = function getOpName() {
|
|
proto.getOpName = function getOpName() {
|
|
|
throw new Error("You need to define this function on your accumulator");
|
|
throw new Error("You need to define this function on your accumulator");
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+//NOTE: DEVIATION FROM MONGO: not implementing this
|
|
|
|
|
+//int memUsageForSorter() const {}
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
- * If this function is not overridden in the sub classes,
|
|
|
|
|
- * then throw an error
|
|
|
|
|
- *
|
|
|
|
|
- **/
|
|
|
|
|
-proto.getValue = function getValue(toBeMerged) {
|
|
|
|
|
|
|
+ * Reset this accumulator to a fresh state ready to receive input.
|
|
|
|
|
+ * @method reset
|
|
|
|
|
+ */
|
|
|
|
|
+proto.reset = function reset() {
|
|
|
throw new Error("You need to define this function on your accumulator");
|
|
throw new Error("You need to define this function on your accumulator");
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * If this function is not overridden in the sub classes,
|
|
|
|
|
- * then throw an error
|
|
|
|
|
- *
|
|
|
|
|
- **/
|
|
|
|
|
|
|
+ * Update subclass's internal state based on input
|
|
|
|
|
+ * @method processInternal
|
|
|
|
|
+ * @param input {Value}
|
|
|
|
|
+ * @param merging {Boolean}
|
|
|
|
|
+ */
|
|
|
proto.processInternal = function processInternal(input, merging) {
|
|
proto.processInternal = function processInternal(input, merging) {
|
|
|
throw new Error("You need to define this function on your accumulator");
|
|
throw new Error("You need to define this function on your accumulator");
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
-/**
|
|
|
|
|
- * If this function is not overridden in the sub classes,
|
|
|
|
|
- * then throw an error
|
|
|
|
|
- *
|
|
|
|
|
- **/
|
|
|
|
|
-proto.reset = function reset() {
|
|
|
|
|
- throw new Error("You need to define this function on your accumulator");
|
|
|
|
|
-};
|
|
|
|
|
|
|
+//NOTE: DEVIATION FROM MONGO: not implementing this
|
|
|
|
|
+// /// subclasses are expected to update this as necessary
|
|
|
|
|
+// int _memUsageBytes;
|