mirror of https://gitee.com/bigwinds/arangodb
rename variables in JSON
This commit is contained in:
parent
76a9887e25
commit
4b6ab03102
|
@ -117,7 +117,7 @@ int ExecutionBlock::staticAnalysisRecursion (
|
||||||
_depth++;
|
_depth++;
|
||||||
curVar = 0;
|
curVar = 0;
|
||||||
auto p = static_cast<EnumerateCollectionPlan const*>(_exePlan);
|
auto p = static_cast<EnumerateCollectionPlan const*>(_exePlan);
|
||||||
varTab.insert(make_pair(p->_outVarNumber, VarDefPlace(_depth, 0)));
|
varTab.insert(make_pair(p->_outVariable->id, VarDefPlace(_depth, 0)));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ExecutionPlan::ENUMERATE_LIST: {
|
case ExecutionPlan::ENUMERATE_LIST: {
|
||||||
|
|
|
@ -184,8 +184,7 @@ void EnumerateCollectionPlan::toJsonHelper (std::map<ExecutionPlan*, int>& index
|
||||||
json("vocbase", Json(_vocbase->_name));
|
json("vocbase", Json(_vocbase->_name));
|
||||||
}
|
}
|
||||||
json("collection", Json(_collname))
|
json("collection", Json(_collname))
|
||||||
("outVarNumber", Json(static_cast<double>(_outVarNumber)))
|
("outVariable", _outVariable->toJson());
|
||||||
("outVarName", Json(_outVarName));
|
|
||||||
|
|
||||||
// And add it:
|
// And add it:
|
||||||
int len = static_cast<int>(nodes.size());
|
int len = static_cast<int>(nodes.size());
|
||||||
|
|
|
@ -336,10 +336,9 @@ namespace triagens {
|
||||||
|
|
||||||
EnumerateCollectionPlan (TRI_vocbase_t* vocbase,
|
EnumerateCollectionPlan (TRI_vocbase_t* vocbase,
|
||||||
std::string collname,
|
std::string collname,
|
||||||
VariableId outVarNumber,
|
Variable const* outVariable)
|
||||||
std::string outVarName)
|
|
||||||
: ExecutionPlan(), _vocbase(vocbase), _collname(collname),
|
: ExecutionPlan(), _vocbase(vocbase), _collname(collname),
|
||||||
_outVarNumber(outVarNumber), _outVarName(outVarName) {
|
_outVariable(outVariable) {
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -371,8 +370,7 @@ namespace triagens {
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
virtual ExecutionPlan* clone () const {
|
virtual ExecutionPlan* clone () const {
|
||||||
auto c = new EnumerateCollectionPlan(_vocbase, _collname,
|
auto c = new EnumerateCollectionPlan(_vocbase, _collname, _outVariable);
|
||||||
_outVarNumber, _outVarName);
|
|
||||||
cloneDependencies(c);
|
cloneDependencies(c);
|
||||||
return static_cast<ExecutionPlan*>(c);
|
return static_cast<ExecutionPlan*>(c);
|
||||||
}
|
}
|
||||||
|
@ -396,16 +394,10 @@ namespace triagens {
|
||||||
std::string _collname;
|
std::string _collname;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief _outVarNumber, output variable
|
/// @brief output variable
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
VariableId _outVarNumber;
|
Variable const* _outVariable;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
/// @brief _outVarName, name of variable to write to
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
std::string _outVarName;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -147,7 +147,7 @@ ExecutionPlan* PlanGenerator::fromNodeFor (Ast const* ast,
|
||||||
if (expression->type == NODE_TYPE_COLLECTION) {
|
if (expression->type == NODE_TYPE_COLLECTION) {
|
||||||
// second operand is a collection
|
// second operand is a collection
|
||||||
char const* collectionName = expression->getStringValue();
|
char const* collectionName = expression->getStringValue();
|
||||||
plan = new EnumerateCollectionPlan(ast->query()->vocbase(), std::string(collectionName), v->id, v->name);
|
plan = new EnumerateCollectionPlan(ast->query()->vocbase(), std::string(collectionName), v);
|
||||||
}
|
}
|
||||||
else if (expression->type == NODE_TYPE_REFERENCE) {
|
else if (expression->type == NODE_TYPE_REFERENCE) {
|
||||||
// second operand is already a variable
|
// second operand is already a variable
|
||||||
|
|
|
@ -0,0 +1,81 @@
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief Aql, AST variable
|
||||||
|
///
|
||||||
|
/// @file
|
||||||
|
///
|
||||||
|
/// DISCLAIMER
|
||||||
|
///
|
||||||
|
/// Copyright 2014 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
|
||||||
|
/// @author Copyright 2014, ArangoDB GmbH, Cologne, Germany
|
||||||
|
/// @author Copyright 2012-2013, triAGENS GmbH, Cologne, Germany
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include "Aql/Variable.h"
|
||||||
|
|
||||||
|
using namespace triagens::aql;
|
||||||
|
using Json = triagens::basics::Json;
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// --SECTION-- constructors / destructors
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief create the variable
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Variable::Variable (std::string const& name,
|
||||||
|
VariableId id)
|
||||||
|
: name(name),
|
||||||
|
value(nullptr),
|
||||||
|
id(id),
|
||||||
|
refCount(0) {
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief destroy the variable
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Variable::~Variable () {
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// --SECTION-- public functions
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief return a JSON representation of the variable
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Json Variable::toJson () const {
|
||||||
|
Json json(triagens::basics::Json::Array, 2);
|
||||||
|
json("id", Json(static_cast<double>(id)))
|
||||||
|
("name", Json(name));
|
||||||
|
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// --SECTION-- END-OF-FILE
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Local Variables:
|
||||||
|
// mode: outline-minor
|
||||||
|
// outline-regexp: "/// @brief\\|/// {@inheritDoc}\\|/// @page\\|// --SECTION--\\|/// @\\}"
|
||||||
|
// End:
|
|
@ -1,5 +1,5 @@
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief Aql, AST variables
|
/// @brief Aql, AST variable
|
||||||
///
|
///
|
||||||
/// @file
|
/// @file
|
||||||
///
|
///
|
||||||
|
@ -31,6 +31,7 @@
|
||||||
#define ARANGODB_AQL_VARIABLE_H 1
|
#define ARANGODB_AQL_VARIABLE_H 1
|
||||||
|
|
||||||
#include "Basics/Common.h"
|
#include "Basics/Common.h"
|
||||||
|
#include "Basics/JsonHelper.h"
|
||||||
|
|
||||||
namespace triagens {
|
namespace triagens {
|
||||||
namespace aql {
|
namespace aql {
|
||||||
|
@ -42,18 +43,23 @@ namespace triagens {
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
struct Variable {
|
struct Variable {
|
||||||
Variable (std::string const& name,
|
|
||||||
VariableId id,
|
|
||||||
bool isUserDefined)
|
|
||||||
: name(name),
|
|
||||||
value(nullptr),
|
|
||||||
id(id),
|
|
||||||
refCount(0),
|
|
||||||
isUserDefined(isUserDefined) {
|
|
||||||
}
|
|
||||||
|
|
||||||
~Variable () {
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
}
|
/// @brief create the variable
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Variable (std::string const&,
|
||||||
|
VariableId);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief destroy the variable
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
~Variable ();
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// --SECTION-- public functions
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief registers a constant value for the variable
|
/// @brief registers a constant value for the variable
|
||||||
|
@ -97,15 +103,49 @@ namespace triagens {
|
||||||
--refCount;
|
--refCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief whether or not the variable is user-defined
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
inline bool isUserDefined () const {
|
||||||
|
char const c = name[0];
|
||||||
|
// variables starting with a number are user-defined
|
||||||
|
return (c >= '0' && c <= '9');
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief return a JSON representation of the variable
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
triagens::basics::Json toJson () const;
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// --SECTION-- public variables
|
// --SECTION-- public variables
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
std::string const name;
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
void* value;
|
/// @brief variable name
|
||||||
VariableId const id;
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
uint32_t refCount;
|
|
||||||
bool const isUserDefined;
|
std::string const name;
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief constant variable value (points to another AstNode)
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
void* value;
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief variable id
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
VariableId const id;
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief number of times the variable is used in the AST
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
uint32_t refCount;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -65,7 +65,11 @@ VariableGenerator::~VariableGenerator () {
|
||||||
|
|
||||||
Variable* VariableGenerator::createVariable (char const* name,
|
Variable* VariableGenerator::createVariable (char const* name,
|
||||||
bool isUserDefined) {
|
bool isUserDefined) {
|
||||||
auto variable = new Variable(std::string(name), nextId(), isUserDefined);
|
auto variable = new Variable(std::string(name), nextId());
|
||||||
|
|
||||||
|
if (isUserDefined) {
|
||||||
|
TRI_ASSERT(variable->isUserDefined());
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
_variables.insert(std::make_pair(variable->id, variable));
|
_variables.insert(std::make_pair(variable->id, variable));
|
||||||
|
@ -85,7 +89,11 @@ Variable* VariableGenerator::createVariable (char const* name,
|
||||||
|
|
||||||
Variable* VariableGenerator::createVariable (std::string const& name,
|
Variable* VariableGenerator::createVariable (std::string const& name,
|
||||||
bool isUserDefined) {
|
bool isUserDefined) {
|
||||||
auto variable = new Variable(name, nextId(), isUserDefined);
|
auto variable = new Variable(name, nextId());
|
||||||
|
|
||||||
|
if (isUserDefined) {
|
||||||
|
TRI_ASSERT(variable->isUserDefined());
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
_variables.insert(std::make_pair(variable->id, variable));
|
_variables.insert(std::make_pair(variable->id, variable));
|
||||||
|
@ -126,6 +134,8 @@ Variable* VariableGenerator::getVariable (VariableId id) const {
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
std::string VariableGenerator::nextName () const {
|
std::string VariableGenerator::nextName () const {
|
||||||
|
// note: if the naming scheme is adjusted, it may be necessary to adjust
|
||||||
|
// Variable::isUserDefined, too!
|
||||||
return std::to_string(_id); // to_string: c++11
|
return std::to_string(_id); // to_string: c++11
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -69,6 +69,7 @@ add_executable(
|
||||||
Aql/Scopes.cpp
|
Aql/Scopes.cpp
|
||||||
Aql/tokens.cpp
|
Aql/tokens.cpp
|
||||||
Aql/V8Executor.cpp
|
Aql/V8Executor.cpp
|
||||||
|
Aql/Variable.cpp
|
||||||
Aql/VariableGenerator.cpp
|
Aql/VariableGenerator.cpp
|
||||||
BitIndexes/bitarray.cpp
|
BitIndexes/bitarray.cpp
|
||||||
BitIndexes/bitarrayIndex.cpp
|
BitIndexes/bitarrayIndex.cpp
|
||||||
|
|
|
@ -50,6 +50,7 @@ arangod_libarangod_a_SOURCES = \
|
||||||
arangod/Aql/Scopes.cpp \
|
arangod/Aql/Scopes.cpp \
|
||||||
arangod/Aql/tokens.cpp \
|
arangod/Aql/tokens.cpp \
|
||||||
arangod/Aql/V8Executor.cpp \
|
arangod/Aql/V8Executor.cpp \
|
||||||
|
arangod/Aql/Variable.cpp \
|
||||||
arangod/Aql/VariableGenerator.cpp \
|
arangod/Aql/VariableGenerator.cpp \
|
||||||
arangod/BitIndexes/bitarray.cpp \
|
arangod/BitIndexes/bitarray.cpp \
|
||||||
arangod/BitIndexes/bitarrayIndex.cpp \
|
arangod/BitIndexes/bitarrayIndex.cpp \
|
||||||
|
|
Loading…
Reference in New Issue