1
0
Fork 0

Implement POST for HTTP API for queries.

This commit is contained in:
Max Neunhoeffer 2014-09-23 16:51:03 +02:00
parent cd36c00712
commit 1f74a64b58
6 changed files with 52 additions and 5 deletions

View File

@ -30,6 +30,7 @@
#include "RestAqlHandler.h"
#include "Basics/ConditionLocker.h"
#include "Basics/StringUtils.h"
#include "Rest/HttpRequest.h"
#include "Rest/HttpResponse.h"
@ -38,6 +39,7 @@
#include "GeneralServer/GeneralServerJob.h"
#include "GeneralServer/GeneralServer.h"
#include "VocBase/server.h"
#include "V8Server/v8-vocbaseprivate.h"
using namespace std;
@ -117,7 +119,7 @@ void RestAqlHandler::createQuery () {
Json options;
try {
plan = queryJson.get("plan");
plan = queryJson.get("plan").copy();
}
catch (...) {
generateError(HttpResponse::BAD, TRI_ERROR_INTERNAL,
@ -125,17 +127,46 @@ void RestAqlHandler::createQuery () {
return;
}
try {
options = queryJson.get("options");
options = queryJson.get("options").copy();
}
catch (...) {
}
auto query = new Query(vocbase, queryJson, options.steal());
std::cout << "plan" << plan.toString() << std::endl;
std::cout << "options" << options.toString() << std::endl;
auto query = new Query(vocbase, plan, options.steal());
QueryResult res = query->prepare();
if (res.code != TRI_ERROR_NO_ERROR) {
generateError(HttpResponse::BAD, TRI_ERROR_QUERY_BAD_JSON_PLAN,
res.details);
delete query;
return;
}
// Now the query is ready to go, store it in the registry and return:
double ttl = 3600.0;
bool found;
char const* ttlstring = _request->header("ttl", found);
if (found) {
ttl = triagens::basics::StringUtils::doubleDecimal(ttlstring);
}
QueryId qId = TRI_NewTickServer();
try {
_queryRegistry->insert(vocbase, qId, query, ttl);
}
catch (...) {
generateError(HttpResponse::BAD, TRI_ERROR_INTERNAL,
"could not keep query in registry");
delete query;
return;
}
_response = createResponse(triagens::rest::HttpResponse::OK);
_response->setContentType("application/json; charset=utf-8");
_response->body().appendText("{\"a\":12}");
_response->body().appendText("{\"queryId\":");
_response->body().appendInteger(qId);
_response->body().appendText("}");
}
void RestAqlHandler::deleteQuery () {

View File

@ -175,6 +175,7 @@
"ERROR_QUERY_MODIFY_IN_SUBQUERY" : { "code" : 1574, "message" : "modify operation in subquery" },
"ERROR_QUERY_COMPILE_TIME_OPTIONS" : { "code" : 1575, "message" : "query options must be readable at query compile time" },
"ERROR_QUERY_EXCEPTION_OPTIONS" : { "code" : 1576, "message" : "query options expected" },
"ERROR_QUERY_BAD_JSON_PLAN" : { "code" : 1577, "message" : "JSON describing execution plan was bad" },
"ERROR_QUERY_FUNCTION_INVALID_NAME" : { "code" : 1580, "message" : "invalid user function name" },
"ERROR_QUERY_FUNCTION_INVALID_CODE" : { "code" : 1581, "message" : "invalid user function code" },
"ERROR_QUERY_FUNCTION_NOT_FOUND" : { "code" : 1582, "message" : "user function '%s()' not found" },

View File

@ -175,6 +175,7 @@
"ERROR_QUERY_MODIFY_IN_SUBQUERY" : { "code" : 1574, "message" : "modify operation in subquery" },
"ERROR_QUERY_COMPILE_TIME_OPTIONS" : { "code" : 1575, "message" : "query options must be readable at query compile time" },
"ERROR_QUERY_EXCEPTION_OPTIONS" : { "code" : 1576, "message" : "query options expected" },
"ERROR_QUERY_BAD_JSON_PLAN" : { "code" : 1577, "message" : "JSON describing execution plan was bad" },
"ERROR_QUERY_FUNCTION_INVALID_NAME" : { "code" : 1580, "message" : "invalid user function name" },
"ERROR_QUERY_FUNCTION_INVALID_CODE" : { "code" : 1581, "message" : "invalid user function code" },
"ERROR_QUERY_FUNCTION_NOT_FOUND" : { "code" : 1582, "message" : "user function '%s()' not found" },

View File

@ -216,6 +216,7 @@ ERROR_QUERY_MULTI_MODIFY,1573,"multi-modify query", "Will be raised when an AQL
ERROR_QUERY_MODIFY_IN_SUBQUERY,1574,"modify operation in subquery", "Will be raised when an AQL query contains a data-modifying operation inside a subquery."
ERROR_QUERY_COMPILE_TIME_OPTIONS,1575,"query options must be readable at query compile time", "Will be raised when an AQL data-modification query contains options that cannot be figured out at query compile time."
ERROR_QUERY_EXCEPTION_OPTIONS,1576,"query options expected", "Will be raised when an AQL data-modification query contains an invalid options specification."
ERROR_QUERY_BAD_JSON_PLAN,1577,"JSON describing execution plan was bad", "Will be raised when an HTTP API for a query got an invalid JSON object."
################################################################################
## AQL user functions

View File

@ -171,6 +171,7 @@ void TRI_InitialiseErrorMessages (void) {
REG_ERROR(ERROR_QUERY_MODIFY_IN_SUBQUERY, "modify operation in subquery");
REG_ERROR(ERROR_QUERY_COMPILE_TIME_OPTIONS, "query options must be readable at query compile time");
REG_ERROR(ERROR_QUERY_EXCEPTION_OPTIONS, "query options expected");
REG_ERROR(ERROR_QUERY_BAD_JSON_PLAN, "JSON describing execution plan was bad");
REG_ERROR(ERROR_QUERY_FUNCTION_INVALID_NAME, "invalid user function name");
REG_ERROR(ERROR_QUERY_FUNCTION_INVALID_CODE, "invalid user function code");
REG_ERROR(ERROR_QUERY_FUNCTION_NOT_FOUND, "user function '%s()' not found");

View File

@ -421,6 +421,8 @@
/// - 1576: @LIT{query options expected}
/// "Will be raised when an AQL data-modification query contains an invalid
/// options specification."
/// - 1577: @LIT{JSON describing execution plan was bad}
/// "Will be raised when an HTTP API for a query got an invalid JSON object."
/// - 1580: @LIT{invalid user function name}
/// Will be raised when a user function with an invalid name is registered.
/// - 1581: @LIT{invalid user function code}
@ -2315,6 +2317,16 @@ void TRI_InitialiseErrorMessages (void);
#define TRI_ERROR_QUERY_EXCEPTION_OPTIONS (1576)
////////////////////////////////////////////////////////////////////////////////
/// @brief 1577: ERROR_QUERY_BAD_JSON_PLAN
///
/// JSON describing execution plan was bad
///
/// "Will be raised when an HTTP API for a query got an invalid JSON object."
////////////////////////////////////////////////////////////////////////////////
#define TRI_ERROR_QUERY_BAD_JSON_PLAN (1577)
////////////////////////////////////////////////////////////////////////////////
/// @brief 1580: ERROR_QUERY_FUNCTION_INVALID_NAME
///