plywood
Version:
A query planner and executor
64 lines (63 loc) • 2.48 kB
JavaScript
import { __extends } from "tslib";
import { ApplyExpression } from './applyExpression';
import { ChainableExpression, Expression } from './baseExpression';
var LimitExpression = (function (_super) {
__extends(LimitExpression, _super);
function LimitExpression(parameters) {
var _this = _super.call(this, parameters, dummyObject) || this;
_this._ensureOp('limit');
_this._checkOperandTypes('DATASET');
var value = parameters.value;
if (value == null)
value = Infinity;
if (value < 0)
throw new Error("limit value can not be negative (is ".concat(value, ")"));
_this.value = value;
_this.type = 'DATASET';
return _this;
}
LimitExpression.fromJS = function (parameters) {
var value = ChainableExpression.jsToValue(parameters);
value.value = parameters.value || parameters.limit;
return new LimitExpression(value);
};
LimitExpression.prototype.valueOf = function () {
var value = _super.prototype.valueOf.call(this);
value.value = this.value;
return value;
};
LimitExpression.prototype.toJS = function () {
var js = _super.prototype.toJS.call(this);
js.value = this.value;
return js;
};
LimitExpression.prototype.equals = function (other) {
return _super.prototype.equals.call(this, other) && this.value === other.value;
};
LimitExpression.prototype._toStringParameters = function (_indent) {
return [String(this.value)];
};
LimitExpression.prototype._calcChainableHelper = function (operandValue) {
return operandValue ? operandValue.limit(this.value) : null;
};
LimitExpression.prototype._getSQLChainableHelper = function (_dialect, _operandSQL) {
return "LIMIT ".concat(this.value);
};
LimitExpression.prototype.specialSimplify = function () {
var _a = this, operand = _a.operand, value = _a.value;
if (!isFinite(value))
return operand;
if (operand instanceof LimitExpression) {
var x = operand.operand, a = operand.value;
return x.limit(Math.min(a, value));
}
if (operand instanceof ApplyExpression) {
return this.swapWithOperand();
}
return this;
};
LimitExpression.op = 'Limit';
return LimitExpression;
}(ChainableExpression));
export { LimitExpression };
Expression.register(LimitExpression);