//////////////////////////////////////////////////////////////////////////////// /// 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 Michael Hackstein //////////////////////////////////////////////////////////////////////////////// #ifndef ARANGOD_AQL_SHORTEST_PATH_NODE_H #define ARANGOD_AQL_SHORTEST_PATH_NODE_H 1 #include "Aql/ExecutionNode.h" #include "Aql/Graphs.h" #include namespace arangodb { namespace graph { struct ShortestPathOptions; } namespace aql { /// @brief class ShortestPathNode class ShortestPathNode : public ExecutionNode { friend class ExecutionBlock; friend class RedundantCalculationsReplacer; friend class ShortestPathBlock; /// @brief constructor with a vocbase and a collection name public: ShortestPathNode(ExecutionPlan* plan, size_t id, TRI_vocbase_t* vocbase, uint64_t direction, AstNode const* start, AstNode const* target, AstNode const* graph, std::unique_ptr& options); ShortestPathNode(ExecutionPlan* plan, arangodb::velocypack::Slice const& base); ~ShortestPathNode(); /// @brief Internal constructor to clone the node. private: ShortestPathNode(ExecutionPlan* plan, size_t id, TRI_vocbase_t* vocbase, std::vector const& edgeColls, std::vector const& directions, Variable const* inStartVariable, std::string const& startVertexId, Variable const* inTargetVariable, std::string const& targetVertexId, std::unique_ptr& options); public: /// @brief return the type of the node NodeType getType() const override final { return SHORTEST_PATH; } /// @brief export to VelocyPack void toVelocyPackHelper(arangodb::velocypack::Builder&, bool) const override final; /// @brief clone ExecutionNode recursively ExecutionNode* clone(ExecutionPlan* plan, bool withDependencies, bool withProperties) const override final; /// @brief the cost of a traversal node double estimateCost(size_t&) const override final; /// @brief Test if this node uses an in variable or constant for start bool usesStartInVariable() const { return _inStartVariable != nullptr; } /// @brief return the start variable Variable const* startInVariable() const { return _inStartVariable; } std::string const getStartVertex() const { return _startVertexId; } /// @brief Test if this node uses an in variable or constant for target bool usesTargetInVariable() const { return _inTargetVariable != nullptr; } /// @brief return the target variable Variable const* targetInVariable() const { return _inTargetVariable; } std::string const getTargetVertex() const { return _targetVertexId; } /// @brief return the vertex out variable Variable const* vertexOutVariable() const { return _vertexOutVariable; } /// @brief checks if the vertex out variable is used bool usesVertexOutVariable() const { return _vertexOutVariable != nullptr; } /// @brief set the vertex out variable void setVertexOutput(Variable const* outVar) { _vertexOutVariable = outVar; } /// @brief return the edge out variable Variable const* edgeOutVariable() const { return _edgeOutVariable; } /// @brief checks if the edge out variable is used bool usesEdgeOutVariable() const { return _edgeOutVariable != nullptr; } /// @brief set the edge out variable void setEdgeOutput(Variable const* outVar) { _edgeOutVariable = outVar; } /// @brief getVariablesSetHere std::vector getVariablesSetHere() const override final { std::vector vars; if (_vertexOutVariable != nullptr) { vars.emplace_back(_vertexOutVariable); } if (_edgeOutVariable != nullptr) { vars.emplace_back(_edgeOutVariable); } return vars; } /// @brief getVariablesUsedHere, returning a vector std::vector getVariablesUsedHere() const override { std::vector vars; if (_inStartVariable != nullptr) { vars.emplace_back(_inStartVariable); } if (_inTargetVariable != nullptr) { vars.emplace_back(_inTargetVariable); } return vars; } /// @brief getVariablesUsedHere, modifying the set in-place void getVariablesUsedHere( std::unordered_set& vars) const override { if (_inStartVariable != nullptr) { vars.emplace(_inStartVariable); } if (_inTargetVariable != nullptr) { vars.emplace(_inTargetVariable); } } graph::ShortestPathOptions* options() const; /// @brief Compute the shortest path options containing the expressions /// MUST! be called after optimization and before creation /// of blocks. void prepareOptions(); private: /// @brief the database TRI_vocbase_t* _vocbase; /// @brief vertex output variable Variable const* _vertexOutVariable; /// @brief vertex output variable Variable const* _edgeOutVariable; /// @brief input variable only used if _vertexId is unused Variable const* _inStartVariable; /// @brief input vertexId only used if _inVariable is unused std::string _startVertexId; /// @brief input variable only used if _vertexId is unused Variable const* _inTargetVariable; /// @brief input vertexId only used if _inVariable is unused std::string _targetVertexId; /// @brief input graphInfo only used for serialisation & info arangodb::velocypack::Builder _graphInfo; /// @brief The directions edges are followed std::vector _directions; /// @brief the edge collection names std::vector _edgeColls; /// @brief our graph... Graph const* _graphObj; /// @brief Temporary pseudo variable for the currently traversed object. Variable const* _tmpObjVariable; /// @brief Reference to the pseudo variable AstNode* _tmpObjVarNode; /// @brief Pseudo string value node to hold the last visted vertex id. AstNode* _tmpIdNode; /// @brief The hard coded condition on _from AstNode* _fromCondition; /// @brief The hard coded condition on _to AstNode* _toCondition; /// @brief Flag if the options have been build. /// Afterwards this class is not copyable anymore. bool _optionsBuild; /// @brief Options for traversals std::unique_ptr _options; }; } // namespace arangodb::aql } // namespace arangodb #endif