1
0
Fork 0

Removed V8Traverser files and made ShortestPathOptions an extension of Graph::BaseOptions. Now they are ready to use LokkupInfos as well. Now starting to move logic around

This commit is contained in:
Michael Hackstein 2017-04-10 16:26:23 +02:00
parent d9dbf2111a
commit cf7136264b
8 changed files with 80 additions and 60 deletions

View File

@ -43,7 +43,7 @@
#include "Basics/SmallVector.h" #include "Basics/SmallVector.h"
#include "Basics/StaticStrings.h" #include "Basics/StaticStrings.h"
#include "Basics/VelocyPackHelper.h" #include "Basics/VelocyPackHelper.h"
#include "V8Server/V8Traverser.h" #include "Graph/ShortestPathOptions.h"
#include "VocBase/AccessMode.h" #include "VocBase/AccessMode.h"
#include <velocypack/Iterator.h> #include <velocypack/Iterator.h>
@ -145,9 +145,9 @@ static std::unique_ptr<traverser::TraverserOptions> CreateTraversalOptions(
return options; return options;
} }
static std::unique_ptr<traverser::ShortestPathOptions> CreateShortestPathOptions( static std::unique_ptr<graph::ShortestPathOptions> CreateShortestPathOptions(
arangodb::transaction::Methods* trx, AstNode const* node) { arangodb::transaction::Methods* trx, AstNode const* node) {
auto options = std::make_unique<traverser::ShortestPathOptions>(trx); auto options = std::make_unique<graph::ShortestPathOptions>(trx);
if (node != nullptr && node->type == NODE_TYPE_OBJECT) { if (node != nullptr && node->type == NODE_TYPE_OBJECT) {
size_t n = node->numMembers(); size_t n = node->numMembers();

View File

@ -26,13 +26,18 @@
#include "Aql/ExecutionBlock.h" #include "Aql/ExecutionBlock.h"
#include "Aql/ShortestPathNode.h" #include "Aql/ShortestPathNode.h"
#include "V8Server/V8Traverser.h" #include "Graph/ShortestPathOptions.h"
namespace arangodb { namespace arangodb {
class ManagedDocumentResult; class ManagedDocumentResult;
namespace graph {
class ShortestPathFinder;
}
namespace traverser { namespace traverser {
class EdgeCollectionInfo; class EdgeCollectionInfo;
class ShortestPath;
} }
namespace aql { namespace aql {
@ -94,7 +99,7 @@ class ShortestPathBlock : public ExecutionBlock {
std::unique_ptr<ManagedDocumentResult> _mmdr; std::unique_ptr<ManagedDocumentResult> _mmdr;
/// @brief options to compute the shortest path /// @brief options to compute the shortest path
traverser::ShortestPathOptions _opts; graph::ShortestPathOptions _opts;
/// @brief list of edge collection infos used to compute the path /// @brief list of edge collection infos used to compute the path
std::vector<arangodb::traverser::EdgeCollectionInfo*> _collectionInfos; std::vector<arangodb::traverser::EdgeCollectionInfo*> _collectionInfos;

View File

@ -30,10 +30,10 @@
#include "Aql/ExecutionPlan.h" #include "Aql/ExecutionPlan.h"
#include "Aql/Query.h" #include "Aql/Query.h"
#include "Cluster/ClusterComm.h" #include "Cluster/ClusterComm.h"
#include "Graph/ShortestPathOptions.h"
#include "Indexes/Index.h" #include "Indexes/Index.h"
#include "Utils/CollectionNameResolver.h" #include "Utils/CollectionNameResolver.h"
#include "VocBase/LogicalCollection.h" #include "VocBase/LogicalCollection.h"
#include "V8Server/V8Traverser.h"
#include <velocypack/Iterator.h> #include <velocypack/Iterator.h>
#include <velocypack/velocypack-aliases.h> #include <velocypack/velocypack-aliases.h>
@ -84,7 +84,7 @@ ShortestPathNode::ShortestPathNode(ExecutionPlan* plan, size_t id,
TRI_vocbase_t* vocbase, uint64_t direction, TRI_vocbase_t* vocbase, uint64_t direction,
AstNode const* start, AstNode const* target, AstNode const* start, AstNode const* target,
AstNode const* graph, AstNode const* graph,
std::unique_ptr<traverser::ShortestPathOptions>& options) std::unique_ptr<graph::ShortestPathOptions>& options)
: ExecutionNode(plan, id), : ExecutionNode(plan, id),
_vocbase(vocbase), _vocbase(vocbase),
_vertexOutVariable(nullptr), _vertexOutVariable(nullptr),
@ -240,7 +240,7 @@ ShortestPathNode::ShortestPathNode(ExecutionPlan* plan, size_t id,
std::string const& startVertexId, std::string const& startVertexId,
Variable const* inTargetVariable, Variable const* inTargetVariable,
std::string const& targetVertexId, std::string const& targetVertexId,
std::unique_ptr<traverser::ShortestPathOptions>& options) std::unique_ptr<graph::ShortestPathOptions>& options)
: ExecutionNode(plan, id), : ExecutionNode(plan, id),
_vocbase(vocbase), _vocbase(vocbase),
_vertexOutVariable(nullptr), _vertexOutVariable(nullptr),
@ -263,7 +263,7 @@ ShortestPathNode::ShortestPathNode(ExecutionPlan* plan, size_t id,
ShortestPathNode::~ShortestPathNode() {} ShortestPathNode::~ShortestPathNode() {}
void ShortestPathNode::fillOptions(arangodb::traverser::ShortestPathOptions& opts) const { void ShortestPathNode::fillOptions(arangodb::graph::ShortestPathOptions& opts) const {
if (!_options->weightAttribute.empty()) { if (!_options->weightAttribute.empty()) {
opts.useWeight = true; opts.useWeight = true;
opts.weightAttribute = _options->weightAttribute; opts.weightAttribute = _options->weightAttribute;
@ -395,7 +395,7 @@ ShortestPathNode::ShortestPathNode(ExecutionPlan* plan,
// Flags // Flags
if (base.hasKey("shortestPathFlags")) { if (base.hasKey("shortestPathFlags")) {
_options = std::make_unique<traverser::ShortestPathOptions>( _options = std::make_unique<graph::ShortestPathOptions>(
_plan->getAst()->query()->trx(), base); _plan->getAst()->query()->trx(), base);
} }
} }
@ -456,7 +456,7 @@ ExecutionNode* ShortestPathNode::clone(ExecutionPlan* plan,
bool withProperties) const { bool withProperties) const {
auto tmp = auto tmp =
std::make_unique<arangodb::traverser::ShortestPathOptions>(*_options.get()); std::make_unique<arangodb::graph::ShortestPathOptions>(*_options.get());
auto c = new ShortestPathNode(plan, _id, _vocbase, _edgeColls, _directions, auto c = new ShortestPathNode(plan, _id, _vocbase, _edgeColls, _directions,
_inStartVariable, _startVertexId, _inStartVariable, _startVertexId,
_inTargetVariable, _targetVertexId, tmp); _inTargetVariable, _targetVertexId, tmp);

View File

@ -31,7 +31,7 @@
namespace arangodb { namespace arangodb {
namespace traverser { namespace graph {
struct ShortestPathOptions; struct ShortestPathOptions;
} }
namespace aql { namespace aql {
@ -46,7 +46,7 @@ class ShortestPathNode : public ExecutionNode {
public: public:
ShortestPathNode(ExecutionPlan* plan, size_t id, TRI_vocbase_t* vocbase, ShortestPathNode(ExecutionPlan* plan, size_t id, TRI_vocbase_t* vocbase,
uint64_t direction, AstNode const* start, AstNode const* target, uint64_t direction, AstNode const* start, AstNode const* target,
AstNode const* graph, std::unique_ptr<traverser::ShortestPathOptions>& options); AstNode const* graph, std::unique_ptr<graph::ShortestPathOptions>& options);
ShortestPathNode(ExecutionPlan* plan, arangodb::velocypack::Slice const& base); ShortestPathNode(ExecutionPlan* plan, arangodb::velocypack::Slice const& base);
@ -61,7 +61,7 @@ class ShortestPathNode : public ExecutionNode {
std::string const& startVertexId, std::string const& startVertexId,
Variable const* inTargetVariable, Variable const* inTargetVariable,
std::string const& targetVertexId, std::string const& targetVertexId,
std::unique_ptr<traverser::ShortestPathOptions>& options); std::unique_ptr<graph::ShortestPathOptions>& options);
public: public:
/// @brief return the type of the node /// @brief return the type of the node
@ -151,7 +151,7 @@ class ShortestPathNode : public ExecutionNode {
} }
} }
void fillOptions(arangodb::traverser::ShortestPathOptions&) const; void fillOptions(arangodb::graph::ShortestPathOptions&) const;
private: private:
@ -189,7 +189,7 @@ class ShortestPathNode : public ExecutionNode {
Graph const* _graphObj; Graph const* _graphObj;
/// @brief Options for traversals /// @brief Options for traversals
std::unique_ptr<traverser::ShortestPathOptions> _options; std::unique_ptr<graph::ShortestPathOptions> _options;
}; };
} // namespace arangodb::aql } // namespace arangodb::aql

View File

@ -222,6 +222,7 @@ SET(ARANGOD_SOURCES
Graph/BreadthFirstEnumerator.cpp Graph/BreadthFirstEnumerator.cpp
Graph/ConstantWeightShortestPathFinder.cpp Graph/ConstantWeightShortestPathFinder.cpp
Graph/NeighborsEnumerator.cpp Graph/NeighborsEnumerator.cpp
Graph/ShortestPathOptions.cpp
Indexes/Index.cpp Indexes/Index.cpp
Indexes/IndexIterator.cpp Indexes/IndexIterator.cpp
Indexes/SimpleAttributeEqualityMatcher.cpp Indexes/SimpleAttributeEqualityMatcher.cpp
@ -315,7 +316,6 @@ SET(ARANGOD_SOURCES
V8Server/FoxxQueuesFeature.cpp V8Server/FoxxQueuesFeature.cpp
V8Server/V8Context.cpp V8Server/V8Context.cpp
V8Server/V8DealerFeature.cpp V8Server/V8DealerFeature.cpp
V8Server/V8Traverser.cpp
V8Server/v8-actions.cpp V8Server/v8-actions.cpp
V8Server/v8-collection-util.cpp V8Server/v8-collection-util.cpp
V8Server/v8-collection.cpp V8Server/v8-collection.cpp

View File

@ -24,8 +24,8 @@
#ifndef ARANGOD_GRAPH_BASE_OPTIONS_H #ifndef ARANGOD_GRAPH_BASE_OPTIONS_H
#define ARANGOD_GRAPH_BASE_OPTIONS_H 1 #define ARANGOD_GRAPH_BASE_OPTIONS_H 1
#include "Basics/Common.h"
#include "Aql/FixedVarExpressionContext.h" #include "Aql/FixedVarExpressionContext.h"
#include "Basics/Common.h"
#include "Cluster/ServerState.h" #include "Cluster/ServerState.h"
#include "Transaction/Methods.h" #include "Transaction/Methods.h"
@ -49,9 +49,7 @@ class Slice;
namespace graph { namespace graph {
struct BaseOptions { struct BaseOptions {
protected: protected:
struct LookupInfo { struct LookupInfo {
// This struct does only take responsibility for the expression // This struct does only take responsibility for the expression
// NOTE: The expression can be nullptr! // NOTE: The expression can be nullptr!
@ -76,7 +74,6 @@ struct BaseOptions {
void buildEngineInfo(arangodb::velocypack::Builder&) const; void buildEngineInfo(arangodb::velocypack::Builder&) const;
double estimateCost(size_t& nrItems) const; double estimateCost(size_t& nrItems) const;
}; };
public: public:
@ -87,7 +84,7 @@ struct BaseOptions {
explicit BaseOptions(BaseOptions const&); explicit BaseOptions(BaseOptions const&);
BaseOptions(arangodb::aql::Query*, arangodb::velocypack::Slice, BaseOptions(arangodb::aql::Query*, arangodb::velocypack::Slice,
arangodb::velocypack::Slice); arangodb::velocypack::Slice);
virtual ~BaseOptions(); virtual ~BaseOptions();
@ -121,7 +118,6 @@ struct BaseOptions {
virtual double estimateCost(size_t& nrItems) const = 0; virtual double estimateCost(size_t& nrItems) const = 0;
protected: protected:
double costForLookupInfoList(std::vector<LookupInfo> const& list, double costForLookupInfoList(std::vector<LookupInfo> const& list,
size_t& createItems) const; size_t& createItems) const;
@ -137,7 +133,8 @@ struct BaseOptions {
aql::Expression* getEdgeExpression(size_t cursorId) const; aql::Expression* getEdgeExpression(size_t cursorId) const;
bool evaluateExpression(aql::Expression*, arangodb::velocypack::Slice varValue) const; bool evaluateExpression(aql::Expression*,
arangodb::velocypack::Slice varValue) const;
void injectLookupInfoInList(std::vector<LookupInfo>&, aql::Ast* ast, void injectLookupInfoInList(std::vector<LookupInfo>&, aql::Ast* ast,
std::string const& collectionName, std::string const& collectionName,
@ -155,9 +152,8 @@ struct BaseOptions {
/// @brief the traverser cache /// @brief the traverser cache
std::unique_ptr<traverser::TraverserCache> _cache; std::unique_ptr<traverser::TraverserCache> _cache;
}; };
} // namespace graph } // namespace graph
} // namespace arangodb } // namespace arangodb
#endif #endif

View File

@ -21,19 +21,20 @@
/// @author Michael Hackstein /// @author Michael Hackstein
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#include "V8Traverser.h" #include "ShortestPathOptions.h"
#include "VocBase/LogicalCollection.h"
#include "VocBase/SingleServerTraverser.h" #include "Basics/VelocyPackHelper.h"
#include <velocypack/Iterator.h> #include <velocypack/Iterator.h>
#include <velocypack/velocypack-aliases.h> #include <velocypack/velocypack-aliases.h>
using namespace arangodb; using namespace arangodb;
using namespace arangodb::basics; using namespace arangodb::basics;
using namespace arangodb::traverser; using namespace arangodb::graph;
ShortestPathOptions::ShortestPathOptions(transaction::Methods* trx) ShortestPathOptions::ShortestPathOptions(transaction::Methods* trx)
: BasicOptions(trx), : BaseOptions(trx),
direction("outbound"), direction("outbound"),
useWeight(false), useWeight(false),
weightAttribute(""), weightAttribute(""),
@ -43,7 +44,7 @@ ShortestPathOptions::ShortestPathOptions(transaction::Methods* trx)
ShortestPathOptions::ShortestPathOptions(transaction::Methods* trx, ShortestPathOptions::ShortestPathOptions(transaction::Methods* trx,
VPackSlice const& info) VPackSlice const& info)
: BasicOptions(trx), : BaseOptions(trx),
direction("outbound"), direction("outbound"),
useWeight(false), useWeight(false),
weightAttribute(""), weightAttribute(""),
@ -60,6 +61,13 @@ ShortestPathOptions::ShortestPathOptions(transaction::Methods* trx,
} }
} }
ShortestPathOptions::~ShortestPathOptions() {}
void ShortestPathOptions::buildEngineInfo(VPackBuilder& result) const {
// TODO Implement me!
BaseOptions::buildEngineInfo(result);
}
void ShortestPathOptions::setStart(std::string const& id) { void ShortestPathOptions::setStart(std::string const& id) {
start = id; start = id;
startBuilder.clear(); startBuilder.clear();
@ -83,3 +91,12 @@ void ShortestPathOptions::toVelocyPack(VPackBuilder& builder) const {
builder.add("weightAttribute", VPackValue(weightAttribute)); builder.add("weightAttribute", VPackValue(weightAttribute));
builder.add("defaultWeight", VPackValue(defaultWeight)); builder.add("defaultWeight", VPackValue(defaultWeight));
} }
void ShortestPathOptions::toVelocyPackIndexes(VPackBuilder& builder) const {
// TODO Implement me
}
double ShortestPathOptions::estimateCost(size_t& nrItems) const {
// TODO Implement me
return 0;
}

View File

@ -21,41 +21,27 @@
/// @author Michael Hackstein /// @author Michael Hackstein
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#ifndef ARANGOD_V8_SERVER_V8_TRAVERSER_H #ifndef ARANGOD_GRAPH_SHORTEST_PATH_OPTIONS_H
#define ARANGOD_V8_SERVER_V8_TRAVERSER_H 1 #define ARANGOD_GRAPH_SHORTEST_PATH_OPTIONS_H 1
#include "Basics/VelocyPackHelper.h" #include "Graph/BaseOptions.h"
#include "VocBase/Traverser.h"
namespace arangodb { namespace arangodb {
namespace transaction {
class Methods;
}
namespace velocypack { namespace velocypack {
class Builder;
class Slice; class Slice;
} }
} namespace graph {
namespace arangodb { struct ShortestPathOptions : public BaseOptions {
namespace traverser {
// A collection of shared options used in several functions.
// Should not be used directly, use specialization instead.
struct BasicOptions {
transaction::Methods* _trx;
protected:
explicit BasicOptions(transaction::Methods* trx) : _trx(trx) {}
virtual ~BasicOptions() {}
public: public:
std::string start; std::string start;
public:
transaction::Methods* trx() { return _trx; }
};
struct ShortestPathOptions : BasicOptions {
public:
std::string direction; std::string direction;
bool useWeight; bool useWeight;
std::string weightAttribute; std::string weightAttribute;
@ -71,15 +57,31 @@ struct ShortestPathOptions : BasicOptions {
ShortestPathOptions(transaction::Methods* trx, ShortestPathOptions(transaction::Methods* trx,
arangodb::velocypack::Slice const& info); arangodb::velocypack::Slice const& info);
~ShortestPathOptions();
// Creates a complete Object containing all EngineInfo
// in the given builder.
void buildEngineInfo(arangodb::velocypack::Builder&) const override;
void setStart(std::string const&); void setStart(std::string const&);
void setEnd(std::string const&); void setEnd(std::string const&);
arangodb::velocypack::Slice getStart() const; arangodb::velocypack::Slice getStart() const;
arangodb::velocypack::Slice getEnd() const; arangodb::velocypack::Slice getEnd() const;
void toVelocyPack(arangodb::velocypack::Builder&) const; /// @brief Build a velocypack for cloning in the plan.
void toVelocyPack(arangodb::velocypack::Builder&) const override;
// Creates a complete Object containing all index information
// in the given builder.
void toVelocyPackIndexes(arangodb::velocypack::Builder&) const override;
/// @brief Estimate the total cost for this operation
double estimateCost(size_t& nrItems) const override;
}; };
}
} } // namespace graph
} // namespace arangodb
#endif #endif