1
0
Fork 0

removed AQL_PENG

This commit is contained in:
Jan Steemann 2014-07-31 12:30:16 +02:00
parent bee98cf420
commit 1ff3d44e88
7 changed files with 80 additions and 100 deletions

View File

@ -26,6 +26,7 @@
////////////////////////////////////////////////////////////////////////////////
#include "Aql/ExecutionBlock.h"
#include "Utils/Exception.h"
using namespace triagens::basics;
using namespace triagens::arango;
@ -82,8 +83,7 @@ ExecutionBlock* ExecutionBlock::instanciatePlan (ExecutionPlan const* ep) {
break;
}
default: {
TRI_ASSERT(false);
break;
THROW_ARANGO_EXCEPTION(TRI_ERROR_NOT_IMPLEMENTED);
}
}
vector<ExecutionPlan*> deps = ep->getDependencies();

View File

@ -29,6 +29,7 @@
#include "Aql/Parser.h"
#include "Aql/AstNode.h"
#include "Aql/QueryResult.h"
using namespace triagens::aql;
@ -107,7 +108,7 @@ bool Parser::configureWriteQuery (QueryType type,
/// @brief parse the query
////////////////////////////////////////////////////////////////////////////////
ParseResult Parser::parse () {
QueryResult Parser::parse () {
// start main scope
auto scopes = _ast->scopes();
scopes->start(AQL_SCOPE_MAIN);
@ -134,7 +135,7 @@ ParseResult Parser::parse () {
TRI_ASSERT(scopes->numActive() == 0);
ParseResult result;
QueryResult result;
result.collectionNames = _ast->collectionNames();
result.bindParameters = _ast->bindParameters();
result.json = _ast->toJson(TRI_UNKNOWN_MEM_ZONE);

View File

@ -43,6 +43,7 @@ namespace triagens {
struct AstNode;
class Query;
struct QueryResult;
class Parser;
}
}
@ -204,7 +205,7 @@ namespace triagens {
/// @brief parse the query
////////////////////////////////////////////////////////////////////////////////
ParseResult parse ();
QueryResult parse ();
////////////////////////////////////////////////////////////////////////////////
/// @brief register a parse error, position is specified as line / column

View File

@ -28,7 +28,9 @@
////////////////////////////////////////////////////////////////////////////////
#include "Aql/Query.h"
#include "Aql/ExecutionBlock.h"
#include "Aql/Parser.h"
#include "Aql/PlanGenerator.h"
#include "Aql/V8Executor.h"
#include "BasicsC/json.h"
#include "BasicsC/tri-strings.h"
@ -163,23 +165,63 @@ void Query::registerError (int code,
/// @brief execute an AQL query - TODO: implement and determine return type
////////////////////////////////////////////////////////////////////////////////
ParseResult Query::execute () {
QueryResult Query::execute () {
try {
Parser parser(this);
parser.parse();
parser.ast()->injectBindParameters(_bindParameters);
parser.ast()->optimize();
ParseResult result(TRI_ERROR_NO_ERROR);
result.json = parser.ast()->toJson(TRI_UNKNOWN_MEM_ZONE);
PlanGenerator generator;
auto plan = generator.fromAst(parser.ast());
try {
auto exec = ExecutionBlock::instanciatePlan(plan);
try {
exec->staticAnalysis();
exec->initialize();
exec->execute();
shared_ptr<AqlItem> value;
while (nullptr != (value = exec->getOne())) {
std::cout << value->getValue(0, 0)->toString() << std::endl;
value.reset();
}
exec->shutdown();
delete exec;
}
catch (...) {
delete exec;
delete plan;
// TODO: convert exception code
return QueryResult(TRI_ERROR_INTERNAL);
}
}
catch (triagens::arango::Exception const& ex) {
delete plan;
return QueryResult(ex.code(), ex.message());
}
catch (...) {
delete plan;
// TODO: convert exception code
return QueryResult(TRI_ERROR_INTERNAL);
}
delete plan;
QueryResult result(TRI_ERROR_NO_ERROR);
// result.json = parser.ast()->toJson(TRI_UNKNOWN_MEM_ZONE);
return result;
}
catch (triagens::arango::Exception const& ex) {
return ParseResult(ex.code(), ex.message());
return QueryResult(ex.code(), ex.message());
}
catch (...) {
return ParseResult(TRI_ERROR_OUT_OF_MEMORY, TRI_errno_string(TRI_ERROR_OUT_OF_MEMORY));
return QueryResult(TRI_ERROR_OUT_OF_MEMORY, TRI_errno_string(TRI_ERROR_OUT_OF_MEMORY));
}
}
@ -187,16 +229,16 @@ ParseResult Query::execute () {
/// @brief parse an AQL query
////////////////////////////////////////////////////////////////////////////////
ParseResult Query::parse () {
QueryResult Query::parse () {
try {
Parser parser(this);
return parser.parse();
}
catch (triagens::arango::Exception const& ex) {
return ParseResult(ex.code(), ex.message());
return QueryResult(ex.code(), ex.message());
}
catch (...) {
return ParseResult(TRI_ERROR_OUT_OF_MEMORY, TRI_errno_string(TRI_ERROR_OUT_OF_MEMORY));
return QueryResult(TRI_ERROR_OUT_OF_MEMORY, TRI_errno_string(TRI_ERROR_OUT_OF_MEMORY));
}
}

View File

@ -32,7 +32,7 @@
#include "Basics/Common.h"
#include "Aql/BindParameters.h"
#include "Aql/ParseResult.h"
#include "Aql/QueryResult.h"
struct TRI_json_s;
struct TRI_vocbase_s;
@ -142,16 +142,16 @@ namespace triagens {
char const* = nullptr);
////////////////////////////////////////////////////////////////////////////////
/// @brief execute an AQL query - TODO: implement and determine return type
/// @brief execute an AQL query
////////////////////////////////////////////////////////////////////////////////
ParseResult execute ();
QueryResult execute ();
////////////////////////////////////////////////////////////////////////////////
/// @brief parse an AQL query
////////////////////////////////////////////////////////////////////////////////
ParseResult parse ();
QueryResult parse ();
////////////////////////////////////////////////////////////////////////////////
/// @brief explain an AQL query - TODO: implement and determine return type

View File

@ -1,5 +1,5 @@
////////////////////////////////////////////////////////////////////////////////
/// @brief Aql, parse results
/// @brief Aql, query results
///
/// @file
///
@ -27,8 +27,8 @@
/// @author Copyright 2012-2013, triAGENS GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////
#ifndef ARANGODB_AQL_PARSE_RESULT_H
#define ARANGODB_AQL_PARSE_RESULT_H 1
#ifndef ARANGODB_AQL_QUERY_RESULT_H
#define ARANGODB_AQL_QUERY_RESULT_H 1
#include "Basics/Common.h"
#include "BasicsC/json.h"
@ -37,13 +37,13 @@ namespace triagens {
namespace aql {
// -----------------------------------------------------------------------------
// --SECTION-- struct ParseResult
// --SECTION-- struct QueryResult
// -----------------------------------------------------------------------------
struct ParseResult {
ParseResult& operator= (ParseResult const& other) = delete;
struct QueryResult {
QueryResult& operator= (QueryResult const& other) = delete;
ParseResult (ParseResult&& other) {
QueryResult (QueryResult&& other) {
code = other.code;
details = other.details;
json = other.json;
@ -51,7 +51,7 @@ namespace triagens {
other.json = nullptr;
}
ParseResult (int code,
QueryResult (int code,
std::string const& details)
: code(code),
details(details),
@ -59,21 +59,21 @@ namespace triagens {
json(nullptr) {
}
explicit ParseResult (int code)
explicit QueryResult (int code)
: code(code),
details(""),
zone(TRI_UNKNOWN_MEM_ZONE),
json(nullptr) {
}
ParseResult ()
QueryResult ()
: code(TRI_ERROR_NO_ERROR),
details(),
zone(TRI_UNKNOWN_MEM_ZONE),
json(nullptr) {
}
~ParseResult () {
~QueryResult () {
if (json != nullptr) {
TRI_FreeJson(zone, json);
}

View File

@ -5397,71 +5397,6 @@ static v8::Handle<v8::Value> JS_ParseAql (v8::Arguments const& argv) {
return scope.Close(result);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief peng an AQL query
////////////////////////////////////////////////////////////////////////////////
class MyWorker : public triagens::aql::ExecutionBlock::WalkerWorker {
public:
int count;
MyWorker () : count(0) {};
~MyWorker () {};
void before (triagens::aql::ExecutionBlock* eb) {
std::cout << "Before node of type " << eb->getPlan()->getTypeString()
<< std::endl;
count++;
}
void after (triagens::aql::ExecutionBlock* eb) {
std::cout << "After node of type " << eb->getPlan()->getTypeString()
<< std::endl;
}
};
static v8::Handle<v8::Value> JS_PengAql (v8::Arguments const& argv) {
v8::HandleScope scope;
TRI_vocbase_t* vocbase = GetContextVocBase();
if (vocbase == nullptr) {
TRI_V8_EXCEPTION(scope, TRI_ERROR_ARANGO_DATABASE_NOT_FOUND);
}
if (argv.Length() != 0) {
TRI_V8_EXCEPTION_USAGE(scope, "AQL_PENG()");
}
triagens::aql::ExecutionPlan* singlePlan = new triagens::aql::SingletonPlan();
triagens::aql::ExecutionPlan* enumPlan = new triagens::aql::EnumerateCollectionPlan(vocbase, "fuxx", 1, "f");
enumPlan->addDependency(singlePlan);
triagens::aql::ExecutionPlan* rootPlan = new triagens::aql::RootPlan(1,"X");
rootPlan->addDependency(enumPlan);
triagens::aql::ExecutionBlock* exec = triagens::aql::ExecutionBlock::instanciatePlan (rootPlan);
exec->staticAnalysis();
MyWorker w;
exec->walk(w);
std::cout << "Count is " << w.count << std::endl;
exec->initialize();
exec->execute();
shared_ptr<triagens::aql::AqlItem> value;
while (nullptr != (value = exec->getOne())) {
std::cout << "Peng" << std::endl;
std::cout << value->getValue(0,0)->toString() << std::endl;
value.reset();
}
exec->shutdown();
delete exec;
delete rootPlan;
return scope.Close(v8::Undefined());
}
////////////////////////////////////////////////////////////////////////////////
/// @brief executes an AQL query
////////////////////////////////////////////////////////////////////////////////
@ -5499,14 +5434,16 @@ static v8::Handle<v8::Value> JS_ExecuteAql (v8::Arguments const& argv) {
// bind parameters will be freed by the query later
triagens::aql::Query query(vocbase, queryString.c_str(), queryString.size(), parameters);
auto parseResult = query.execute();
if (parseResult.code != TRI_ERROR_NO_ERROR) {
TRI_V8_EXCEPTION_FULL(scope, parseResult.code, parseResult.details);
auto queryResult = query.execute();
if (queryResult.code != TRI_ERROR_NO_ERROR) {
TRI_V8_EXCEPTION_FULL(scope, queryResult.code, queryResult.details);
}
v8::Handle<v8::Object> result = v8::Object::New();
result->Set(TRI_V8_STRING("ast"), TRI_ObjectJson(parseResult.json));
if (queryResult.json != nullptr) {
result->Set(TRI_V8_STRING("json"), TRI_ObjectJson(queryResult.json));
}
return scope.Close(result);
}
@ -10778,7 +10715,6 @@ void TRI_InitV8VocBridge (v8::Handle<v8::Context> context,
// new AQL functions. not intended to be used directly by end users
TRI_AddGlobalFunctionVocbase(context, "AQL_EXECUTE", JS_ExecuteAql, true);
TRI_AddGlobalFunctionVocbase(context, "AQL_PARSE", JS_ParseAql, true);
TRI_AddGlobalFunctionVocbase(context, "AQL_PENG", JS_PengAql, true);
// cursor functions. not intended to be used by end users
TRI_AddGlobalFunctionVocbase(context, "CURSOR", JS_Cursor, true);