8000 refactored cursor API, added export API · ezhangle/arangodb@e672d79 · GitHub
[go: up one dir, main page]

Skip to content

Commit e672d79

Browse files
committed
refactored cursor API, added export API
1 parent 80a99ab commit e672d79

23 files changed

+1026
-141
lines changed

Documentation/Books/Users/HttpAqlQueryCursor/README.mdpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
This is an introduction to ArangoDB's HTTP Interface for Queries. Results of AQL
66
and simple queries are returned as cursors in order to batch the communication
77
between server and client. Each call returns a number of documents in a batch
8-
and an indication, if the current batch has been the final batch. Depending on
8+
and an indication if the current batch has been the final batch. Depending on
99
the query, the total number of documents in the result set might or might not be
1010
known in advance. In order to free server resources the client should delete the
1111
cursor as soon as it is no longer needed.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
!CHAPTER HTTP Interface for Exporting Documents
2+
3+
@startDocuBlock JSF_post_api_export

Documentation/Books/Users/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@
164164
* [Edges](HttpEdge/README.md)
165165
* [Address and ETag](HttpEdge/AddressAndEtag.md)
166166
* [Working with Edges](HttpEdge/WorkingWithEdges.md)
167+
* [Exporting data](HttpExport/README.md)
167168
* [AQL Query Cursors](HttpAqlQueryCursor/README.md)
168169
* [Query Results](HttpAqlQueryCursor/QueryResults.md)
169170
* [Accessing Cursors](HttpAqlQueryCursor/AccessingCursors.md)

Documentation/Scripts/generateSwaggerApi.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,12 @@
4444
files = {
4545
"js/actions/api-aqlfunction.js" : "aqlfunction",
4646
"ar 6D40 angod/RestHandler/RestBatchHandler.cpp" : "batch",
47-
"js/actions/api-collection.js" : "collection",
48-
"js/actions/api-cursor.js" : "cursor",
49-
"js/actions/api-database.js" : "database",
47+
"js/actions/_api/collection/app.js" : "collection",
48+
"js/actions/_admin/database/app.js" : "database",
49+
"arangod/RestHandler/RestCursorHandler.cpp" : "cursor",
5050
"arangod/RestHandler/RestDocumentHandler.cpp" : "document",
5151
"arangod/RestHandler/RestEdgeHandler.cpp" : "edge",
52+
"arangod/RestHandler/RestExportHandler.cpp" : "export",
5253
"js/actions/api-edges.js" : "edges",
5354
"js/actions/api-endpoint.js" : "endpoint",
5455
"js/actions/api-explain.js" : "explain",
@@ -57,16 +58,17 @@
5758
"js/actions/api-index.js" : "index",
5859
"lib/HttpServer/AsyncJobManager.h" : "job",
5960
"lib/Admin/RestAdminLogHandler.cpp" : "log",
60-
"js/actions/api-query.js" : "query",
61+
"arangod/RestHandler/RestQueryHandler.cpp" : "query",
6162
"arangod/RestHandler/RestReplicationHandler.cpp" : "replication",
6263
"js/actions/api-simple.js" : "simple",
6364
"js/actions/api-structure.js" : "structure",
6465
"js/actions/api-system.js" : "system",
6566
"js/actions/api-tasks.js" : "tasks",
6667
"js/actions/api-transaction.js" : "transaction",
6768
"js/actions/api-traversal.js" : "traversal",
68-
"js/actions/api-user.js" : "user",
69-
"lib/Admin/RestVersionHandler.cpp" : "version"
69+
"js/actions/_api/user/app.js" : "user",
70+
"lib/Admin/RestVersionHandler.cpp" : "version",
71+
"js/actions/_admin/wal/app.js" : "wal"
7072
}
7173

7274
if len(sys.argv) < 3:

arangod/Aql/Query.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,6 @@ void Query::registerErrorCustom (int code,
480480
errorMessage.append(": ");
481481
errorMessage.append(details);
482482

483-
std::cout << "REGISTER ERROR CUSTOM: " << errorMessage << "\n";
484483
THROW_ARANGO_EXCEPTION_MESSAGE(code, errorMessage);
485484
}
486485

arangod/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ add_executable(
105105
RestHandler/RestCursorHandler.cpp
106106
RestHandler/RestDocumentHandler.cpp
107107
RestHandler/RestEdgeHandler.cpp
108+
RestHandler/RestExportHandler.cpp
108109
RestHandler/RestImportHandler.cpp
109110
RestHandler/RestPleaseUpgradeHandler.cpp
110111
RestHandler/RestQueryHandler.cpp
@@ -116,6 +117,7 @@ add_executable(
116117
RestServer/VocbaseContext.cpp
117118
RestServer/arangod.cpp
118119
SkipLists/skiplistIndex.cpp
120+
Utils/CollectionExport.cpp
119121
Utils/Cursor.cpp
120122
Utils/CursorRepository.cpp
121123
Utils/DocumentHelper.cpp

arangod/Makefile.files

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ arangod_libarangod_a_SOURCES = \
7878
arangod/RestHandler/RestCursorHandler.cpp \
7979
arangod/RestHandler/RestDocumentHandler.cpp \
8080
arangod/RestHandler/RestEdgeHandler.cpp \
81+
arangod/RestHandler/RestExportHandler.cpp \
8182
arangod/RestHandler/RestImportHandler.cpp \
8283
arangod/RestHandler/RestPleaseUpgradeHandler.cpp \
8384
arangod/RestHandler/RestQueryHandler.cpp \
@@ -89,6 +90,7 @@ arangod_libarangod_a_SOURCES = \
8990
arangod/RestServer/VocbaseContext.cpp \
9091
arangod/RestServer/arangod.cpp \
9192
arangod/SkipLists/skiplistIndex.cpp \
93+
arangod/Utils/CollectionExport.cpp \
9294
arangod/Utils/Cursor.cpp \
9395
arangod/Utils/CursorRepository.cpp \
9496
arangod/Utils/DocumentHelper.cpp \

arangod/RestHandler/RestCursorHandler.cpp

Lines changed: 14 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -236,67 +236,6 @@ triagens::basics::Json RestCursorHandler::buildExtra (triagens::aql::QueryResult
236236
return extra;
237237
}
238238

239-
////////////////////////////////////////////////////////////////////////////////
240-
/// @brief append the contents of the cursor into the response body
241-
////////////////////////////////////////////////////////////////////////////////
242-
243-
void RestCursorHandler::dumpCursor (Cursor* cursor) {
244-
_response->body().appendText("{\"result\":[");
245-
246-
size_t const n = cursor->batchSize();
247-
248-
for (size_t i = 0; i < n; ++i) {
249-
if (! cursor->hasNext()) {
250-
break;
251-
}
252-
253-
if (i > 0) {
254-
_response->body().appendChar(',');
255-
}
256-
257-
auto row = cursor->next();
258-
if (row == nullptr) {
259-
THROW_ARANGO_EXCEPTION(TRI_ERROR_OUT_OF_MEMORY);
260-
}
261-
262-
int res = TRI_StringifyJson(_response->body().stringBuffer(), row);
263-
264-
if (res != TRI_ERROR_NO_ERROR) {
265-
THROW_ARANGO_EXCEPTION(res);
266-
}
267-
}
268-
269-
bool hasCount = cursor->hasCount();
270-
size_t count = cursor->count();
271-
bool hasNext = cursor->hasNext();
272-
TRI_json_t* extra = cursor->extra();
273-
274-
_response->body().appendText("],\"hasMore\":");
275-
_response->body().appendText(hasNext ? "true" : "false");
276-
277-
if (hasNext) {
278-
// only return cursor id if there are more documents
279-
_response->body().appendText(",\"id\":\"");
280-
_response->body().appendInteger(cursor->id());
281-
_response->body().appendText("\"");
282-
}
283-
284-
if (hasCount) {
285-
_response->body().appendText(",\"count\":");
286-
_response->body().appendInteger(static_cast<uint64_t>(count));
287-
}
288-
289-
if (TRI_IsObjectJson(extra)) {
290-
_response->body().appendText(",\"extra\":");
291-
TRI_StringifyJson(_response->body().stringBuffer(), extra);
292-
}
293-
294-
_response->body().appendText(",\"error\":false,\"code\":");
295-
_response->body().appendInteger(static_cast<uint32_t>(_response->responseCode()));
296-
297-
_response->body().appendChar('}');
298-
}
299-
300239
////////////////////////////////////////////////////////////////////////////////
301240
/// @startDocuBlock JSF_post_api_cursor
302241
/// @brief create a cursor and return the first results
@@ -735,13 +674,18 @@ void RestCursorHandler::createCursor () {
735674
double ttl = triagens::basics::JsonHelper::getNumericValue<double>(options.json(), "ttl", 30);
736675
bool count = triagens::basics::JsonHelper::getBooleanValue(options.json(), "count", false);
737676

738-
// steal the query JSON, cursor will take owner the ownership
677+
// steal the query JSON, cursor will take over the ownership
739678
auto j = queryResult.json;
679+
triagens::arango::JsonCursor* cursor = cursors->createFromJson(j, batchSize, extra.steal(), ttl, count);
740680
queryResult.json = nullptr;
741-
triagens::arango::Cursor* cursor = cursors->createFromJson(j, batchSize, extra.steal(), ttl, count);
742681

743682
try {
744-
dumpCursor(cursor);
683+
_response->body().appendChar('{');
684+
cursor->dump(_response->body());
685+
_response->body().appendText(",\"error\":false,\"code\":");
686+
_response->body().appendInteger(static_cast<uint32_t>(_response->responseCode()));
687+
_response->body().appendChar('}');
688+
745689
cursors->release(cursor);
746690
}
747691
catch (...) {
@@ -889,7 +833,12 @@ void RestCursorHandler::modifyCursor () {
889833
_response = createResponse(HttpResponse::OK);
890834
_response->setContentType("application/json; charset=utf-8");
891835

892-
dumpCursor(cursor);
836+
_response->body().appendChar('{');
837+
cursor->dump(_response->body());
838+
_response->body().appendText(",\"error\":false,\"code\":");
839+
_response->body().appendInteger(static_cast<uint32_t>(_response->responseCode()));
840+
_response->body().appendChar('}');
841+
893842
cursors->release(cursor);
894843
}
895844
catch (triagens::basics::Exception const& ex) {

arangod/RestHandler/RestCursorHandler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ namespace triagens {
5050
class Cursor;
5151

5252
////////////////////////////////////////////////////////////////////////////////
53-
/// @brief document request handler
53+
/// @brief cursor request handler
5454
////////////////////////////////////////////////////////////////////////////////
5555

5656
class RestCursorHandler : public RestVocbaseBaseHandler {

0 commit comments

Comments
 (0)
0