mirror of https://gitee.com/bigwinds/arangodb
added /_api/aql-builtin
This commit is contained in:
parent
8b1366205a
commit
6412200f27
|
@ -0,0 +1,37 @@
|
|||
# coding: utf-8
|
||||
|
||||
require 'rspec'
|
||||
require 'arangodb.rb'
|
||||
|
||||
describe ArangoDB do
|
||||
api = "/_api/aql-builtin"
|
||||
prefix = "api-aql-builtin"
|
||||
|
||||
context "dealing with the builtin AQL functions:" do
|
||||
|
||||
it "fetches the list of functions" do
|
||||
doc = ArangoDB.log_get("#{prefix}-fetch", api)
|
||||
|
||||
doc.code.should eq(200)
|
||||
doc.headers['content-type'].should eq("application/json; charset=utf-8")
|
||||
|
||||
functions = doc.parsed_response['functions']
|
||||
found = { }
|
||||
functions.each{|f|
|
||||
f.should be_kind_of(Hash)
|
||||
f.should have_key("name")
|
||||
f.should have_key("arguments")
|
||||
|
||||
found[f["name"]] = f["name"]
|
||||
}
|
||||
|
||||
# check for a few known functions
|
||||
found.should have_key "PI"
|
||||
found.should have_key "DEGREES"
|
||||
found.should have_key "RADIANS"
|
||||
found.should have_key "SIN"
|
||||
found.should have_key "COS"
|
||||
end
|
||||
|
||||
end
|
||||
end
|
|
@ -26,6 +26,10 @@
|
|||
#include "Aql/Function.h"
|
||||
#include "Cluster/ServerState.h"
|
||||
|
||||
#include <velocypack/Builder.h>
|
||||
#include <velocypack/Value.h>
|
||||
#include <velocypack/velocypack-aliases.h>
|
||||
|
||||
using namespace arangodb::aql;
|
||||
|
||||
/// @brief determines if code is executed in cluster or not
|
||||
|
@ -71,6 +75,17 @@ std::unordered_map<int,
|
|||
|
||||
/// @brief user-accessible functions
|
||||
std::unordered_map<std::string, Function const> FunctionDefinitions::FunctionNames;
|
||||
|
||||
void FunctionDefinitions::toVelocyPack(VPackBuilder& builder) {
|
||||
builder.openArray();
|
||||
for (auto const& it : FunctionDefinitions::FunctionNames) {
|
||||
builder.openObject();
|
||||
builder.add("name", VPackValue(it.second.externalName));
|
||||
builder.add("arguments", VPackValue(it.second.arguments));
|
||||
builder.close();
|
||||
}
|
||||
builder.close();
|
||||
}
|
||||
|
||||
/// @brief this struct will add all AQL functions to the FunctionDefintions map
|
||||
struct FunctionDefiner {
|
||||
|
|
|
@ -28,6 +28,10 @@
|
|||
#include "Aql/Function.h"
|
||||
|
||||
namespace arangodb {
|
||||
namespace velocypack {
|
||||
class Builder;
|
||||
}
|
||||
|
||||
namespace aql {
|
||||
|
||||
struct FunctionDefinitions {
|
||||
|
@ -36,6 +40,8 @@ struct FunctionDefinitions {
|
|||
|
||||
/// @brief AQL user-callable function names
|
||||
static std::unordered_map<std::string, Function const> FunctionNames;
|
||||
|
||||
static void toVelocyPack(arangodb::velocypack::Builder&);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -205,6 +205,7 @@ add_executable(${BIN_ARANGOD}
|
|||
Replication/InitialSyncer.cpp
|
||||
Replication/Syncer.cpp
|
||||
RestHandler/RestAdminLogHandler.cpp
|
||||
RestHandler/RestAqlFunctionsHandler.cpp
|
||||
RestHandler/RestAuthHandler.cpp
|
||||
RestHandler/RestBaseHandler.cpp
|
||||
RestHandler/RestBatchHandler.cpp
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// DISCLAIMER
|
||||
///
|
||||
/// Copyright 2014-2016 ArangoDB GmbH, Cologne, Germany
|
||||
/// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany
|
||||
///
|
||||
/// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
/// you may not use this file except in compliance with the License.
|
||||
/// You may obtain a copy of the License at
|
||||
///
|
||||
/// http://www.apache.org/licenses/LICENSE-2.0
|
||||
///
|
||||
/// Unless required by applicable law or agreed to in writing, software
|
||||
/// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
/// See the License for the specific language governing permissions and
|
||||
/// limitations under the License.
|
||||
///
|
||||
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
|
||||
///
|
||||
/// @author Jan Steemann
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "RestAqlFunctionsHandler.h"
|
||||
#include "Aql/FunctionDefinitions.h"
|
||||
|
||||
#include <velocypack/Builder.h>
|
||||
#include <velocypack/velocypack-aliases.h>
|
||||
|
||||
using namespace arangodb;
|
||||
using namespace arangodb::rest;
|
||||
|
||||
RestAqlFunctionsHandler::RestAqlFunctionsHandler(HttpRequest* request)
|
||||
: RestVocbaseBaseHandler(request) {}
|
||||
|
||||
HttpHandler::status_t RestAqlFunctionsHandler::execute() {
|
||||
// extract the sub-request type
|
||||
auto const type = _request->requestType();
|
||||
|
||||
if (type == GeneralRequest::RequestType::GET) {
|
||||
VPackBuilder builder;
|
||||
|
||||
builder.openObject();
|
||||
builder.add(VPackValue("functions"));
|
||||
aql::FunctionDefinitions::toVelocyPack(builder);
|
||||
builder.close();
|
||||
|
||||
generateResult(GeneralResponse::ResponseCode::OK, builder.slice());
|
||||
return status_t(HANDLER_DONE);
|
||||
}
|
||||
|
||||
generateError(GeneralResponse::ResponseCode::METHOD_NOT_ALLOWED,
|
||||
TRI_ERROR_HTTP_METHOD_NOT_ALLOWED);
|
||||
return status_t(HANDLER_DONE);
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// DISCLAIMER
|
||||
///
|
||||
/// Copyright 2014-2016 ArangoDB GmbH, Cologne, Germany
|
||||
/// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany
|
||||
///
|
||||
/// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
/// you may not use this file except in compliance with the License.
|
||||
/// You may obtain a copy of the License at
|
||||
///
|
||||
/// http://www.apache.org/licenses/LICENSE-2.0
|
||||
///
|
||||
/// Unless required by applicable law or agreed to in writing, software
|
||||
/// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
/// See the License for the specific language governing permissions and
|
||||
/// limitations under the License.
|
||||
///
|
||||
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
|
||||
///
|
||||
/// @author Jan Steemann
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef ARANGOD_REST_HANDLER_REST_AQL_FUNCTIONS_HANDLER_H
|
||||
#define ARANGOD_REST_HANDLER_REST_AQL_FUNCTIONS_HANDLER_H 1
|
||||
|
||||
#include "Basics/Common.h"
|
||||
#include "RestHandler/RestVocbaseBaseHandler.h"
|
||||
|
||||
namespace arangodb {
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief AQL functions inventory handler
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class RestAqlFunctionsHandler : public RestVocbaseBaseHandler {
|
||||
public:
|
||||
explicit RestAqlFunctionsHandler(HttpRequest*);
|
||||
|
||||
public:
|
||||
status_t execute() override;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
|
@ -41,6 +41,7 @@
|
|||
#include "ProgramOptions/Section.h"
|
||||
#include "Rest/Version.h"
|
||||
#include "RestHandler/RestAdminLogHandler.h"
|
||||
#include "RestHandler/RestAqlFunctionsHandler.h"
|
||||
#include "RestHandler/RestAuthHandler.h"
|
||||
#include "RestHandler/RestBatchHandler.h"
|
||||
#include "RestHandler/RestCursorHandler.h"
|
||||
|
@ -452,6 +453,10 @@ void RestServerFeature::defineHandlers() {
|
|||
"/_api/aql",
|
||||
RestHandlerCreator<aql::RestAqlHandler>::createData<aql::QueryRegistry*>,
|
||||
queryRegistry);
|
||||
|
||||
_handlerFactory->addPrefixHandler(
|
||||
"/_api/aql-builtin",
|
||||
RestHandlerCreator<RestAqlFunctionsHandler>::createNoData);
|
||||
|
||||
_handlerFactory->addPrefixHandler(
|
||||
"/_api/query", RestHandlerCreator<RestQueryHandler>::createNoData);
|
||||
|
|
Loading…
Reference in New Issue