mirror of https://gitee.com/bigwinds/arangodb
allow "stream" attribute on top level (#9195)
This commit is contained in:
parent
12ec86c2b1
commit
074397d367
|
@ -447,15 +447,19 @@ void RestCursorHandler::buildOptions(VPackSlice const& slice) {
|
||||||
bool hasCache = false;
|
bool hasCache = false;
|
||||||
bool hasMemoryLimit = false;
|
bool hasMemoryLimit = false;
|
||||||
VPackSlice opts = slice.get("options");
|
VPackSlice opts = slice.get("options");
|
||||||
bool isStream = false;
|
// "stream" option is important, so also accept it on top level and not only
|
||||||
|
// inside options
|
||||||
|
bool isStream = VelocyPackHelper::getBooleanValue(slice, "stream", false);
|
||||||
if (opts.isObject()) {
|
if (opts.isObject()) {
|
||||||
isStream = VelocyPackHelper::getBooleanValue(opts, "stream", false);
|
if (!isStream) {
|
||||||
|
isStream = VelocyPackHelper::getBooleanValue(opts, "stream", false);
|
||||||
|
}
|
||||||
for (auto const& it : VPackObjectIterator(opts)) {
|
for (auto const& it : VPackObjectIterator(opts)) {
|
||||||
if (!it.key.isString() || it.value.isNone()) {
|
if (!it.key.isString() || it.value.isNone()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
std::string keyName = it.key.copyString();
|
velocypack::StringRef keyName = it.key.stringRef();
|
||||||
if (keyName == "count" || keyName == "batchSize" || keyName == "ttl" ||
|
if (keyName == "count" || keyName == "batchSize" || keyName == "ttl" || keyName == "stream" ||
|
||||||
(isStream && keyName == "fullCount")) {
|
(isStream && keyName == "fullCount")) {
|
||||||
continue; // filter out top-level keys
|
continue; // filter out top-level keys
|
||||||
} else if (keyName == "cache") {
|
} else if (keyName == "cache") {
|
||||||
|
@ -467,6 +471,8 @@ void RestCursorHandler::buildOptions(VPackSlice const& slice) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_options->add("stream", VPackValue(isStream));
|
||||||
|
|
||||||
if (!isStream) { // ignore cache & count for streaming queries
|
if (!isStream) { // ignore cache & count for streaming queries
|
||||||
bool val = VelocyPackHelper::getBooleanValue(slice, "count", false);
|
bool val = VelocyPackHelper::getBooleanValue(slice, "count", false);
|
||||||
_options->add("count", VPackValue(val));
|
_options->add("count", VPackValue(val));
|
||||||
|
|
|
@ -150,7 +150,8 @@ ArangoStatement.prototype.execute = function () {
|
||||||
var body = {
|
var body = {
|
||||||
query: this._query,
|
query: this._query,
|
||||||
count: this._doCount,
|
count: this._doCount,
|
||||||
bindVars: this._bindVars
|
bindVars: this._bindVars,
|
||||||
|
stream: this._stream
|
||||||
};
|
};
|
||||||
|
|
||||||
if (this._batchSize) {
|
if (this._batchSize) {
|
||||||
|
@ -170,8 +171,8 @@ ArangoStatement.prototype.execute = function () {
|
||||||
|
|
||||||
arangosh.checkRequestResult(requestResult);
|
arangosh.checkRequestResult(requestResult);
|
||||||
|
|
||||||
let isStream = false;
|
let isStream = this._stream;
|
||||||
if (this._options && this._options.stream) {
|
if (!isStream && this._options && this._options.stream) {
|
||||||
isStream = this._options.stream;
|
isStream = this._options.stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,7 @@ function ArangoStatement (database, data) {
|
||||||
this._bindVars = {};
|
this._bindVars = {};
|
||||||
this._options = undefined;
|
this._options = undefined;
|
||||||
this._cache = undefined;
|
this._cache = undefined;
|
||||||
|
this._stream = false;
|
||||||
|
|
||||||
if (!data) {
|
if (!data) {
|
||||||
throw 'ArangoStatement needs initial data';
|
throw 'ArangoStatement needs initial data';
|
||||||
|
@ -73,6 +74,9 @@ function ArangoStatement (database, data) {
|
||||||
if (data.cache !== undefined) {
|
if (data.cache !== undefined) {
|
||||||
this.setCache(data.cache);
|
this.setCache(data.cache);
|
||||||
}
|
}
|
||||||
|
if (data.stream !== undefined) {
|
||||||
|
this._stream = data.stream;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// //////////////////////////////////////////////////////////////////////////////
|
// //////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -198,6 +198,21 @@ function StatementStreamSuite () {
|
||||||
assertFalse(cursor.hasNext());
|
assertFalse(cursor.hasNext());
|
||||||
},
|
},
|
||||||
|
|
||||||
|
testStreamCursorOnTopLevel : function () {
|
||||||
|
var stmt = db._createStatement({ query: "FOR i IN 1..100 RETURN i",
|
||||||
|
stream: true,
|
||||||
|
batchSize: 50});
|
||||||
|
var cursor = stmt.execute();
|
||||||
|
|
||||||
|
assertEqual(undefined, cursor.count());
|
||||||
|
for (var i = 1; i <= 100; ++i) {
|
||||||
|
assertEqual(i, cursor.next());
|
||||||
|
assertEqual(i !== 100, cursor.hasNext());
|
||||||
|
}
|
||||||
|
|
||||||
|
assertFalse(cursor.hasNext());
|
||||||
|
},
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief test to string
|
/// @brief test to string
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -220,6 +235,27 @@ function StatementStreamSuite () {
|
||||||
assertEqual(i !== 11, cursor.hasNext());
|
assertEqual(i !== 11, cursor.hasNext());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assertFalse(cursor.hasNext());
|
||||||
|
},
|
||||||
|
|
||||||
|
testStreamToStringOnTopLevel : function () {
|
||||||
|
var stmt = db._createStatement({ query: "FOR i IN 1..11 RETURN i",
|
||||||
|
stream: true });
|
||||||
|
var cursor = stmt.execute();
|
||||||
|
|
||||||
|
assertEqual(undefined, cursor.count()); // count is not supported
|
||||||
|
assertTrue(cursor.hasNext());
|
||||||
|
|
||||||
|
// print it. this should not modify the cursor apart from when it's accessed for printing
|
||||||
|
cursor.toString();
|
||||||
|
assertTrue(more === cursor);
|
||||||
|
assertTrue(cursor._stream);
|
||||||
|
|
||||||
|
for (var i = 1; i <= 11; ++i) {
|
||||||
|
assertEqual(i, cursor.next());
|
||||||
|
assertEqual(i !== 11, cursor.hasNext());
|
||||||
|
}
|
||||||
|
|
||||||
assertFalse(cursor.hasNext());
|
assertFalse(cursor.hasNext());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue