//////////////////////////////////////////////////////////////////////////////// /// @brief Infrastructure for ExecutionPlans /// /// @file arangod/Aql/ExecutionNode.h /// /// DISCLAIMER /// /// Copyright 2010-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 triAGENS GmbH, Cologne, Germany /// /// @author Max Neunhoeffer /// @author Copyright 2014, triagens GmbH, Cologne, Germany //////////////////////////////////////////////////////////////////////////////// #ifndef ARANGODB_AQL_EXECUTION_Plan_H #define ARANGODB_AQL_EXECUTION_Plan_H 1 #include #include #include #include #include "Aql/Expression.h" #include "Aql/Variable.h" #include "Aql/Types.h" namespace triagens { namespace aql { class ExecutionBlock; class WalkerWorker; //////////////////////////////////////////////////////////////////////////////// /// @brief class ExecutionNode, abstract base class of all execution Nodes //////////////////////////////////////////////////////////////////////////////// class ExecutionNode { //////////////////////////////////////////////////////////////////////////////// /// @brief node type //////////////////////////////////////////////////////////////////////////////// public: enum NodeType { ILLEGAL, SINGLETON, // done ENUMERATE_COLLECTION, // done INDEX_RANGE, ENUMERATE_LIST, // done FILTER, // done LIMIT, // done INTERSECTION, PROJECTION, // done CALCULATION, // done SUBQUERY, // done SORT, // done AGGREGATE, // done LOOKUP_JOIN, MERGE_JOIN, LOOKUP_INDEX_UNIQUE, LOOKUP_INDEX_RANGE, LOOKUP_FULL_COLLECTION, CONCATENATION, MERGE, REMOTE, INSERT, REMOVE, REPLACE, UPDATE, RETURN // done }; // ----------------------------------------------------------------------------- // --SECTION-- constructors / destructors // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @brief default constructor //////////////////////////////////////////////////////////////////////////////// ExecutionNode () { } //////////////////////////////////////////////////////////////////////////////// /// @brief constructor with one dependency //////////////////////////////////////////////////////////////////////////////// ExecutionNode (ExecutionNode* ep) { _dependencies.push_back(ep); } //////////////////////////////////////////////////////////////////////////////// /// @brief destructor, free dependencies //////////////////////////////////////////////////////////////////////////////// virtual ~ExecutionNode () { } // ----------------------------------------------------------------------------- // --SECTION-- public methods // ----------------------------------------------------------------------------- public: //////////////////////////////////////////////////////////////////////////////// /// @brief return the type of the node //////////////////////////////////////////////////////////////////////////////// virtual NodeType getType () const { return ILLEGAL; } //////////////////////////////////////////////////////////////////////////////// /// @brief return the type of the node as a string //////////////////////////////////////////////////////////////////////////////// virtual std::string getTypeString () const { return std::string("ExecutionNode (abstract)"); } //////////////////////////////////////////////////////////////////////////////// /// @brief add a dependency //////////////////////////////////////////////////////////////////////////////// void addDependency (ExecutionNode* ep) { _dependencies.push_back(ep); } //////////////////////////////////////////////////////////////////////////////// /// @brief get all dependencies //////////////////////////////////////////////////////////////////////////////// std::vector getDependencies () const { return _dependencies; } //////////////////////////////////////////////////////////////////////////////// /// @brief remove a dependency, returns true if the pointer was found and /// removed, please note that this does not delete ep! //////////////////////////////////////////////////////////////////////////////// bool removeDependency (ExecutionNode* ep) { auto it = _dependencies.begin(); while (it != _dependencies.end()) { if (*it == ep) { _dependencies.erase(it); return true; } ++it; } return false; } //////////////////////////////////////////////////////////////////////////////// /// @brief access the pos-th dependency //////////////////////////////////////////////////////////////////////////////// ExecutionNode* operator[] (size_t pos) const { if (pos > _dependencies.size()) { return nullptr; } else { return _dependencies.at(pos); } } //////////////////////////////////////////////////////////////////////////////// /// @brief clone execution Node recursively, this makes the class abstract //////////////////////////////////////////////////////////////////////////////// virtual ExecutionNode* clone () const = 0; // make class abstract //////////////////////////////////////////////////////////////////////////////// /// @brief helper for cloning, use virtual clone methods for dependencies //////////////////////////////////////////////////////////////////////////////// void cloneDependencies (ExecutionNode* theClone) const { auto it = _dependencies.begin(); while (it != _dependencies.end()) { theClone->_dependencies.push_back((*it)->clone()); ++it; } } //////////////////////////////////////////////////////////////////////////////// /// @brief convert to a string, basically for debugging purposes //////////////////////////////////////////////////////////////////////////////// virtual void appendAsString (std::string& st, int indent = 0); void walk (WalkerWorker* worker); //////////////////////////////////////////////////////////////////////////////// /// @brief export to JSON, returns an AUTOFREE Json object //////////////////////////////////////////////////////////////////////////////// triagens::basics::Json toJson (TRI_memory_zone_t* zone = TRI_UNKNOWN_MEM_ZONE); //////////////////////////////////////////////////////////////////////////////// /// @brief helpers for export to JSON, appends an entry to nodes, indexMap is the /// map from nodes to indices in list //////////////////////////////////////////////////////////////////////////////// // ----------------------------------------------------------------------------- // --SECTION-- protected methods // ----------------------------------------------------------------------------- protected: //////////////////////////////////////////////////////////////////////////////// /// @brief toJsonHelper, for a generic node //////////////////////////////////////////////////////////////////////////////// triagens::basics::Json toJsonHelperGeneric ( std::map& indexTab, triagens::basics::Json& nodes, TRI_memory_zone_t* zone); //////////////////////////////////////////////////////////////////////////////// /// @brief toJson //////////////////////////////////////////////////////////////////////////////// virtual void toJsonHelper (std::map& indexTab, triagens::basics::Json& nodes, TRI_memory_zone_t* zone = TRI_UNKNOWN_MEM_ZONE) = 0; // ----------------------------------------------------------------------------- // --SECTION-- protected variables // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @brief our dependent nodes //////////////////////////////////////////////////////////////////////////////// protected: std::vector _dependencies; }; // ----------------------------------------------------------------------------- // --SECTION-- class SingletonNode // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @brief class SingletonNode, derived from ExecutionNode //////////////////////////////////////////////////////////////////////////////// class SingletonNode : public ExecutionNode { friend class ExecutionBlock; friend class SingletonBlock; //////////////////////////////////////////////////////////////////////////////// /// @brief constructor with a vocbase and a collection name //////////////////////////////////////////////////////////////////////////////// public: SingletonNode () : ExecutionNode() { } //////////////////////////////////////////////////////////////////////////////// /// @brief return the type of the node //////////////////////////////////////////////////////////////////////////////// virtual NodeType getType () const { return SINGLETON; } //////////////////////////////////////////////////////////////////////////////// /// @brief return the type of the node as a string //////////////////////////////////////////////////////////////////////////////// virtual std::string getTypeString () const { return std::string("SingletonNode"); } //////////////////////////////////////////////////////////////////////////////// /// @brief export to JSON //////////////////////////////////////////////////////////////////////////////// virtual void toJsonHelper (std::map& indexTab, triagens::basics::Json& nodes, TRI_memory_zone_t* zone = TRI_UNKNOWN_MEM_ZONE); //////////////////////////////////////////////////////////////////////////////// /// @brief clone ExecutionNode recursively //////////////////////////////////////////////////////////////////////////////// virtual ExecutionNode* clone () const { auto c = new SingletonNode(); cloneDependencies(c); return static_cast(c); } }; // ----------------------------------------------------------------------------- // --SECTION-- class EnumerateCollectionNode // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @brief class EnumerateCollectionNode, derived from ExecutionNode //////////////////////////////////////////////////////////////////////////////// class EnumerateCollectionNode : public ExecutionNode { friend class ExecutionBlock; friend class EnumerateCollectionBlock; //////////////////////////////////////////////////////////////////////////////// /// @brief constructor with a vocbase and a collection name //////////////////////////////////////////////////////////////////////////////// public: EnumerateCollectionNode (TRI_vocbase_t* vocbase, std::string collname, Variable const* outVariable) : ExecutionNode(), _vocbase(vocbase), _collname(collname), _outVariable(outVariable) { TRI_ASSERT(_vocbase != nullptr); TRI_ASSERT(_outVariable != nullptr); } //////////////////////////////////////////////////////////////////////////////// /// @brief return the type of the node //////////////////////////////////////////////////////////////////////////////// virtual NodeType getType () const { return ENUMERATE_COLLECTION; } //////////////////////////////////////////////////////////////////////////////// /// @brief return the type of the node as a string //////////////////////////////////////////////////////////////////////////////// virtual std::string getTypeString () const { return std::string("EnumerateCollectionNode"); } //////////////////////////////////////////////////////////////////////////////// /// @brief export to JSON //////////////////////////////////////////////////////////////////////////////// virtual void toJsonHelper (std::map& indexTab, triagens::basics::Json& nodes, TRI_memory_zone_t* zone = TRI_UNKNOWN_MEM_ZONE); //////////////////////////////////////////////////////////////////////////////// /// @brief clone ExecutionNode recursively //////////////////////////////////////////////////////////////////////////////// virtual ExecutionNode* clone () const { auto c = new EnumerateCollectionNode(_vocbase, _collname, _outVariable); cloneDependencies(c); return static_cast(c); } //////////////////////////////////////////////////////////////////////////////// /// @brief private data //////////////////////////////////////////////////////////////////////////////// private: //////////////////////////////////////////////////////////////////////////////// /// @brief _vocbase, the database //////////////////////////////////////////////////////////////////////////////// TRI_vocbase_t* _vocbase; //////////////////////////////////////////////////////////////////////////////// /// @brief _collname, the collection name //////////////////////////////////////////////////////////////////////////////// std::string _collname; //////////////////////////////////////////////////////////////////////////////// /// @brief output variable //////////////////////////////////////////////////////////////////////////////// Variable const* _outVariable; }; // ----------------------------------------------------------------------------- // --SECTION-- class EnumerateListNode // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @brief class EnumerateListNode, derived from ExecutionNode //////////////////////////////////////////////////////////////////////////////// class EnumerateListNode : public ExecutionNode { friend class ExecutionBlock; friend class EnumerateListBlock; //////////////////////////////////////////////////////////////////////////////// /// @brief constructor //////////////////////////////////////////////////////////////////////////////// public: EnumerateListNode (Variable const* inVariable, Variable const* outVariable) : ExecutionNode(), _inVariable(inVariable), _outVariable(outVariable) { TRI_ASSERT(_inVariable != nullptr); TRI_ASSERT(_outVariable != nullptr); } //////////////////////////////////////////////////////////////////////////////// /// @brief return the type of the node //////////////////////////////////////////////////////////////////////////////// virtual NodeType getType () const { return ENUMERATE_LIST; } //////////////////////////////////////////////////////////////////////////////// /// @brief return the type of the node as a string //////////////////////////////////////////////////////////////////////////////// virtual std::string getTypeString () const { return std::string("EnumerateListNode"); } //////////////////////////////////////////////////////////////////////////////// /// @brief export to JSON //////////////////////////////////////////////////////////////////////////////// virtual void toJsonHelper (std::map& indexTab, triagens::basics::Json& nodes, TRI_memory_zone_t* zone = TRI_UNKNOWN_MEM_ZONE); //////////////////////////////////////////////////////////////////////////////// /// @brief clone ExecutionNode recursively //////////////////////////////////////////////////////////////////////////////// virtual ExecutionNode* clone () const { auto c = new EnumerateListNode(_inVariable, _outVariable); cloneDependencies(c); return static_cast(c); } //////////////////////////////////////////////////////////////////////////////// /// @brief private data //////////////////////////////////////////////////////////////////////////////// private: //////////////////////////////////////////////////////////////////////////////// /// @brief input variable to read from //////////////////////////////////////////////////////////////////////////////// Variable const* _inVariable; //////////////////////////////////////////////////////////////////////////////// /// @brief output variable to write to //////////////////////////////////////////////////////////////////////////////// Variable const* _outVariable; }; // ----------------------------------------------------------------------------- // --SECTION-- class LimitNode // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @brief class LimitNode, derived from ExecutionNode //////////////////////////////////////////////////////////////////////////////// class LimitNode : public ExecutionNode { friend class ExecutionBlock; friend class LimitBlock; //////////////////////////////////////////////////////////////////////////////// /// @brief constructors for various arguments, always with offset and limit //////////////////////////////////////////////////////////////////////////////// public: LimitNode (size_t o, size_t l) : ExecutionNode(), _offset(o), _limit(l) { } LimitNode (size_t l) : ExecutionNode(), _offset(0), _limit(l) { } //////////////////////////////////////////////////////////////////////////////// /// @brief return the type of the node //////////////////////////////////////////////////////////////////////////////// virtual NodeType getType () const { return LIMIT; } //////////////////////////////////////////////////////////////////////////////// /// @brief return the type of the node as a string //////////////////////////////////////////////////////////////////////////////// virtual std::string getTypeString () const { return std::string("LimitNode"); } //////////////////////////////////////////////////////////////////////////////// /// @brief export to JSON //////////////////////////////////////////////////////////////////////////////// virtual void toJsonHelper (std::map& indexTab, triagens::basics::Json& nodes, TRI_memory_zone_t* zone = TRI_UNKNOWN_MEM_ZONE); //////////////////////////////////////////////////////////////////////////////// /// @brief clone ExecutionNode recursively //////////////////////////////////////////////////////////////////////////////// virtual ExecutionNode* clone () const { auto c = new LimitNode(_offset, _limit); cloneDependencies(c); return static_cast(c); } //////////////////////////////////////////////////////////////////////////////// /// @brief we need to know the offset and limit //////////////////////////////////////////////////////////////////////////////// private: size_t _offset; size_t _limit; }; // ----------------------------------------------------------------------------- // --SECTION-- class ProjectionNode // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @brief class ProjectionNode, derived from ExecutionNode //////////////////////////////////////////////////////////////////////////////// class ProjectionNode : public ExecutionNode { friend class ExecutionBlock; friend class ProjectionBlock; //////////////////////////////////////////////////////////////////////////////// /// @brief constructor //////////////////////////////////////////////////////////////////////////////// public: ProjectionNode (Variable const* inVariable, Variable const* outVariable, std::vector keepAttributes) : ExecutionNode(), _inVariable(inVariable), _outVariable(outVariable), _keepAttributes(keepAttributes) { TRI_ASSERT(inVariable != nullptr); TRI_ASSERT(outVariable != nullptr); } //////////////////////////////////////////////////////////////////////////////// /// @brief return the type of the node //////////////////////////////////////////////////////////////////////////////// virtual NodeType getType () const { return PROJECTION; } //////////////////////////////////////////////////////////////////////////////// /// @brief return the type of the node as a string //////////////////////////////////////////////////////////////////////////////// virtual std::string getTypeString () const { return std::string("ProjectionNode"); } //////////////////////////////////////////////////////////////////////////////// /// @brief export to JSON //////////////////////////////////////////////////////////////////////////////// virtual void toJsonHelper (std::map& indexTab, triagens::basics::Json& nodes, TRI_memory_zone_t* zone = TRI_UNKNOWN_MEM_ZONE); //////////////////////////////////////////////////////////////////////////////// /// @brief clone ExecutionNode recursively //////////////////////////////////////////////////////////////////////////////// virtual ExecutionNode* clone () const { auto c = new ProjectionNode(_inVariable, _outVariable, _keepAttributes); cloneDependencies(c); return static_cast(c); } //////////////////////////////////////////////////////////////////////////////// /// @brief private data //////////////////////////////////////////////////////////////////////////////// private: //////////////////////////////////////////////////////////////////////////////// /// @brief input variable to read from //////////////////////////////////////////////////////////////////////////////// Variable const* _inVariable; //////////////////////////////////////////////////////////////////////////////// /// @brief output variable to write to //////////////////////////////////////////////////////////////////////////////// Variable const* _outVariable; //////////////////////////////////////////////////////////////////////////////// /// @brief vector of attributes to leave in the object //////////////////////////////////////////////////////////////////////////////// std::vector _keepAttributes; }; // ----------------------------------------------------------------------------- // --SECTION-- class CalculationNode // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @brief class CalculationNode, derived from ExecutionNode //////////////////////////////////////////////////////////////////////////////// class CalculationNode : public ExecutionNode { friend class ExecutionBlock; friend class CalculationBlock; public: //////////////////////////////////////////////////////////////////////////////// /// @brief constructor //////////////////////////////////////////////////////////////////////////////// CalculationNode (Expression* expr, Variable const* outVariable) : ExecutionNode(), _expression(expr), _outVariable(outVariable) { TRI_ASSERT(_expression != nullptr); TRI_ASSERT(_outVariable != nullptr); } //////////////////////////////////////////////////////////////////////////////// /// @brief destructor //////////////////////////////////////////////////////////////////////////////// ~CalculationNode () { if (_expression != nullptr) { delete _expression; } } //////////////////////////////////////////////////////////////////////////////// /// @brief return the type of the node //////////////////////////////////////////////////////////////////////////////// virtual NodeType getType () const { return CALCULATION; } //////////////////////////////////////////////////////////////////////////////// /// @brief return the type of the node as a string //////////////////////////////////////////////////////////////////////////////// virtual std::string getTypeString () const { return std::string("CalculationNode"); } //////////////////////////////////////////////////////////////////////////////// /// @brief export to JSON //////////////////////////////////////////////////////////////////////////////// virtual void toJsonHelper (std::map& indexTab, triagens::basics::Json& nodes, TRI_memory_zone_t* zone = TRI_UNKNOWN_MEM_ZONE); //////////////////////////////////////////////////////////////////////////////// /// @brief clone ExecutionNode recursively //////////////////////////////////////////////////////////////////////////////// virtual ExecutionNode* clone () const { auto c = new CalculationNode(_expression->clone(), _outVariable); cloneDependencies(c); return static_cast(c); } //////////////////////////////////////////////////////////////////////////////// /// @brief return out variable //////////////////////////////////////////////////////////////////////////////// Variable const* outVariable () const { return _outVariable; } //////////////////////////////////////////////////////////////////////////////// /// @brief return the expression //////////////////////////////////////////////////////////////////////////////// Expression* expression () const { return _expression; } //////////////////////////////////////////////////////////////////////////////// /// @brief private data //////////////////////////////////////////////////////////////////////////////// private: //////////////////////////////////////////////////////////////////////////////// /// @brief we need to have an expression and where to write the result //////////////////////////////////////////////////////////////////////////////// Expression* _expression; //////////////////////////////////////////////////////////////////////////////// /// @brief output variable to write to //////////////////////////////////////////////////////////////////////////////// Variable const* _outVariable; }; // ----------------------------------------------------------------------------- // --SECTION-- class SubqueryNode // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @brief class SubqueryNode, derived from ExecutionNode //////////////////////////////////////////////////////////////////////////////// class SubqueryNode : public ExecutionNode { friend class ExecutionBlock; friend class SubqueryBlock; //////////////////////////////////////////////////////////////////////////////// /// @brief constructor //////////////////////////////////////////////////////////////////////////////// public: SubqueryNode (ExecutionNode* subquery, Variable const* outVariable) : ExecutionNode(), _subquery(subquery), _outVariable(outVariable) { TRI_ASSERT(_subquery != nullptr); TRI_ASSERT(_outVariable != nullptr); } //////////////////////////////////////////////////////////////////////////////// /// @brief return the type of the node //////////////////////////////////////////////////////////////////////////////// virtual NodeType getType () const { return SUBQUERY; } //////////////////////////////////////////////////////////////////////////////// /// @brief return the type of the node as a string //////////////////////////////////////////////////////////////////////////////// virtual std::string getTypeString () const { return std::string("SubqueryNode"); } //////////////////////////////////////////////////////////////////////////////// /// @brief export to JSON //////////////////////////////////////////////////////////////////////////////// virtual void toJsonHelper (std::map& indexTab, triagens::basics::Json& nodes, TRI_memory_zone_t* zone = TRI_UNKNOWN_MEM_ZONE); //////////////////////////////////////////////////////////////////////////////// /// @brief clone ExecutionNode recursively //////////////////////////////////////////////////////////////////////////////// virtual ExecutionNode* clone () const { auto c = new SubqueryNode(_subquery->clone(), _outVariable); cloneDependencies(c); return static_cast(c); } //////////////////////////////////////////////////////////////////////////////// /// @brief getter for subquery //////////////////////////////////////////////////////////////////////////////// ExecutionNode* getSubquery () { return _subquery; } //////////////////////////////////////////////////////////////////////////////// /// @brief private data //////////////////////////////////////////////////////////////////////////////// private: //////////////////////////////////////////////////////////////////////////////// /// @brief we need to have an expression and where to write the result //////////////////////////////////////////////////////////////////////////////// ExecutionNode* _subquery; //////////////////////////////////////////////////////////////////////////////// /// @brief variable to write to //////////////////////////////////////////////////////////////////////////////// Variable const* _outVariable; }; // ----------------------------------------------------------------------------- // --SECTION-- class FilterNode // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @brief class FilterNode, derived from ExecutionNode //////////////////////////////////////////////////////////////////////////////// class FilterNode : public ExecutionNode { friend class ExecutionBlock; friend class FilterBlock; //////////////////////////////////////////////////////////////////////////////// /// @brief constructors for various arguments, always with offset and limit //////////////////////////////////////////////////////////////////////////////// public: FilterNode (Variable const* inVariable) : ExecutionNode(), _inVariable(inVariable) { TRI_ASSERT(_inVariable != nullptr); } //////////////////////////////////////////////////////////////////////////////// /// @brief return the type of the node //////////////////////////////////////////////////////////////////////////////// virtual NodeType getType () const { return FILTER; } //////////////////////////////////////////////////////////////////////////////// /// @brief return the type of the node as a string //////////////////////////////////////////////////////////////////////////////// virtual std::string getTypeString () const { return std::string("FilterNode"); } //////////////////////////////////////////////////////////////////////////////// /// @brief export to JSON //////////////////////////////////////////////////////////////////////////////// virtual void toJsonHelper (std::map& indexTab, triagens::basics::Json& nodes, TRI_memory_zone_t* zone = TRI_UNKNOWN_MEM_ZONE); //////////////////////////////////////////////////////////////////////////////// /// @brief clone ExecutionNode recursively //////////////////////////////////////////////////////////////////////////////// virtual ExecutionNode* clone () const { auto c = new FilterNode(_inVariable); cloneDependencies(c); return static_cast(c); } //////////////////////////////////////////////////////////////////////////////// /// @brief we need to know the offset and limit //////////////////////////////////////////////////////////////////////////////// private: //////////////////////////////////////////////////////////////////////////////// /// @brief input variable to read from //////////////////////////////////////////////////////////////////////////////// Variable const* _inVariable; }; // ----------------------------------------------------------------------------- // --SECTION-- class SortNode // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @brief class SortNode, derived from ExecutionNode //////////////////////////////////////////////////////////////////////////////// class SortNode : public ExecutionNode { friend class ExecutionBlock; friend class SortBlock; //////////////////////////////////////////////////////////////////////////////// /// @brief constructor //////////////////////////////////////////////////////////////////////////////// public: SortNode (std::vector> elements) : ExecutionNode(), _elements(elements) { } //////////////////////////////////////////////////////////////////////////////// /// @brief return the type of the node //////////////////////////////////////////////////////////////////////////////// virtual NodeType getType () const { return SORT; } //////////////////////////////////////////////////////////////////////////////// /// @brief return the type of the node as a string //////////////////////////////////////////////////////////////////////////////// virtual std::string getTypeString () const { return std::string("SortNode"); } //////////////////////////////////////////////////////////////////////////////// /// @brief export to JSON //////////////////////////////////////////////////////////////////////////////// virtual void toJsonHelper (std::map& indexTab, triagens::basics::Json& nodes, TRI_memory_zone_t* zone = TRI_UNKNOWN_MEM_ZONE); //////////////////////////////////////////////////////////////////////////////// /// @brief clone ExecutionNode recursively //////////////////////////////////////////////////////////////////////////////// virtual ExecutionNode* clone () const { auto c = new SortNode(_elements); cloneDependencies(c); return static_cast(c); } //////////////////////////////////////////////////////////////////////////////// /// @brief private data //////////////////////////////////////////////////////////////////////////////// private: //////////////////////////////////////////////////////////////////////////////// /// @brief pairs, consisting of variable and sort direction /// (true = ascending | false = descending) //////////////////////////////////////////////////////////////////////////////// std::vector> _elements; }; // ----------------------------------------------------------------------------- // --SECTION-- class AggregateNode // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @brief class AggregateNode, derived from ExecutionNode //////////////////////////////////////////////////////////////////////////////// class AggregateNode : public ExecutionNode { friend class ExecutionBlock; friend class AggregateBlock; //////////////////////////////////////////////////////////////////////////////// /// @brief constructor //////////////////////////////////////////////////////////////////////////////// public: AggregateNode (std::vector> aggregateVariables, Variable const* outVariable, std::unordered_map const& variableMap) : ExecutionNode(), _aggregateVariables(aggregateVariables), _outVariable(outVariable), _variableMap(variableMap) { // outVariable can be a nullptr } //////////////////////////////////////////////////////////////////////////////// /// @brief return the type of the node //////////////////////////////////////////////////////////////////////////////// virtual NodeType getType () const { return AGGREGATE; } //////////////////////////////////////////////////////////////////////////////// /// @brief return the type of the node as a string //////////////////////////////////////////////////////////////////////////////// virtual std::string getTypeString () const { return std::string("AggregateNode"); } //////////////////////////////////////////////////////////////////////////////// /// @brief export to JSON //////////////////////////////////////////////////////////////////////////////// virtual void toJsonHelper (std::map& indexTab, triagens::basics::Json& nodes, TRI_memory_zone_t* zone = TRI_UNKNOWN_MEM_ZONE); //////////////////////////////////////////////////////////////////////////////// /// @brief clone ExecutionNode recursively //////////////////////////////////////////////////////////////////////////////// virtual ExecutionNode* clone () const { auto c = new AggregateNode(_aggregateVariables, _outVariable, _variableMap); cloneDependencies(c); return static_cast(c); } //////////////////////////////////////////////////////////////////////////////// /// @brief private data //////////////////////////////////////////////////////////////////////////////// private: //////////////////////////////////////////////////////////////////////////////// /// @brief input/output variables for the aggregation (out, in) //////////////////////////////////////////////////////////////////////////////// std::vector> _aggregateVariables; //////////////////////////////////////////////////////////////////////////////// /// @brief output variable to write to (might be null) //////////////////////////////////////////////////////////////////////////////// Variable const* _outVariable; //////////////////////////////////////////////////////////////////////////////// /// @brief map of all variable ids and names (needed to construct group data) //////////////////////////////////////////////////////////////////////////////// std::unordered_map const _variableMap; }; // ----------------------------------------------------------------------------- // --SECTION-- class ReturnNode // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @brief class ReturnNode, derived from ExecutionNode //////////////////////////////////////////////////////////////////////////////// class ReturnNode : public ExecutionNode { friend class ExecutionBlock; friend class ReturnBlock; //////////////////////////////////////////////////////////////////////////////// /// @brief constructors for various arguments, always with offset and limit //////////////////////////////////////////////////////////////////////////////// public: ReturnNode (Variable const* inVariable) : ExecutionNode(), _inVariable(inVariable) { TRI_ASSERT(_inVariable != nullptr); } //////////////////////////////////////////////////////////////////////////////// /// @brief return the type of the node //////////////////////////////////////////////////////////////////////////////// virtual NodeType getType () const { return RETURN; } //////////////////////////////////////////////////////////////////////////////// /// @brief return the type of the node as a string //////////////////////////////////////////////////////////////////////////////// virtual std::string getTypeString () const { return std::string("ReturnNode"); } //////////////////////////////////////////////////////////////////////////////// /// @brief export to JSON //////////////////////////////////////////////////////////////////////////////// virtual void toJsonHelper (std::map& indexTab, triagens::basics::Json& nodes, TRI_memory_zone_t* zone = TRI_UNKNOWN_MEM_ZONE); //////////////////////////////////////////////////////////////////////////////// /// @brief clone ExecutionNode recursively //////////////////////////////////////////////////////////////////////////////// virtual ExecutionNode* clone () const { auto c = new ReturnNode(_inVariable); cloneDependencies(c); return static_cast(c); } //////////////////////////////////////////////////////////////////////////////// /// @brief we need to know the offset and limit //////////////////////////////////////////////////////////////////////////////// private: Variable const* _inVariable; }; } // namespace triagens::aql } // namespace triagens #endif // Local Variables: // mode: outline-minor // outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\|/// @\\}\\)" // End: