mirror of https://gitee.com/bigwinds/arangodb
Merge branch 'devel' of https://github.com/triAGENS/ArangoDB into devel
This commit is contained in:
commit
8b13d4687a
|
@ -1615,6 +1615,78 @@ function ArangoCollection (database, data) {
|
|||
this._type = requestResult['type'];
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief iterators over some elements of a collection
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ArangoCollection.prototype.iterate = function (iterator, options) {
|
||||
var probability = 1.0;
|
||||
var limit = null;
|
||||
var stmt;
|
||||
var cursor;
|
||||
var pos;
|
||||
|
||||
if (options !== undefined) {
|
||||
if (options.hasOwnProperty("probability")) {
|
||||
probability = options.probability;
|
||||
}
|
||||
|
||||
if (options.hasOwnProperty("limit")) {
|
||||
limit = options.limit;
|
||||
}
|
||||
}
|
||||
|
||||
if (limit === null) {
|
||||
if (probability >= 1.0) {
|
||||
cursor = this.all();
|
||||
}
|
||||
else {
|
||||
stmt = internal.sprintf("FOR d IN %s FILTER rand() >= @prob RETURN d", this.name());
|
||||
stmt = internal.db._createStatement({ query: stmt });
|
||||
|
||||
if (probability < 1.0) {
|
||||
stmt.bind("prob", probability);
|
||||
}
|
||||
|
||||
cursor = stmt.execute();
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (typeof limit !== "number") {
|
||||
var error = new ArangoError();
|
||||
error.errorNum = internal.errors.ERROR_ILLEGAL_NUMBER.code;
|
||||
error.errorMessage = "expecting a number, got " + String(limit);
|
||||
|
||||
throw error;
|
||||
}
|
||||
|
||||
if (probability >= 1.0) {
|
||||
cursor = this.all().limit(limit);
|
||||
}
|
||||
else {
|
||||
stmt = internal.sprintf("FOR d IN %s FILTER rand() >= @prob LIMIT %d RETURN d",
|
||||
this.name(), limit);
|
||||
stmt = internal.db._createStatement({ query: stmt });
|
||||
|
||||
if (probability < 1.0) {
|
||||
stmt.bind("prob", probability);
|
||||
}
|
||||
|
||||
cursor = stmt.execute();
|
||||
}
|
||||
}
|
||||
|
||||
pos = 0;
|
||||
|
||||
while (cursor.hasNext()) {
|
||||
var document = cursor.next();
|
||||
|
||||
iterator(document, pos);
|
||||
|
||||
pos++;
|
||||
}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -542,6 +542,15 @@
|
|||
internal.print = internal.printBrowser;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief global print
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
internal.printf = function () {
|
||||
var text = internal.sprintf.apply(internal.springf, arguments);
|
||||
internal.output(text);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief start pager
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -242,10 +242,17 @@
|
|||
|
||||
if (limit === null) {
|
||||
if (probability >= 1.0) {
|
||||
stmt = internal.sprintf("FOR d IN %s RETURN d", this.name());
|
||||
cursor = this.all();
|
||||
}
|
||||
else {
|
||||
stmt = internal.sprintf("FOR d IN %s FILTER rand() >= @prob RETURN d", this.name());
|
||||
stmt = internal.db._createStatement({ query: stmt });
|
||||
|
||||
if (probability < 1.0) {
|
||||
stmt.bind("prob", probability);
|
||||
}
|
||||
|
||||
cursor = stmt.execute();
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -258,21 +265,21 @@
|
|||
}
|
||||
|
||||
if (probability >= 1.0) {
|
||||
stmt = internal.sprintf("FOR d IN %s LIMIT %d RETURN d", this.name(), limit);
|
||||
cursor = this.all().limit(limit);
|
||||
}
|
||||
else {
|
||||
stmt = internal.sprintf("FOR d IN %s FILTER rand() >= @prob LIMIT %d RETURN d",
|
||||
this.name(), limit);
|
||||
stmt = internal.db._createStatement({ query: stmt });
|
||||
|
||||
if (probability < 1.0) {
|
||||
stmt.bind("prob", probability);
|
||||
}
|
||||
|
||||
cursor = stmt.execute();
|
||||
}
|
||||
}
|
||||
|
||||
stmt = internal.db._createStatement({ query: stmt });
|
||||
|
||||
if (probability < 1.0) {
|
||||
stmt.bind("prob", probability);
|
||||
}
|
||||
|
||||
cursor = stmt.execute();
|
||||
pos = 0;
|
||||
|
||||
while (cursor.hasNext()) {
|
||||
|
|
Loading…
Reference in New Issue