From f89a2bbf428563b48db7454bdfe49d5e8fdcb137 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1nos=20Benjamin=20Antal?= Date: Thu, 20 Oct 2022 11:35:00 +0200 Subject: [PATCH] Make ExpandOne work in the query engine (#589) --- src/coordinator/shard_map.hpp | 16 +- src/glue/v2/communication.cpp | 1 + src/memgraph.cpp | 4 +- src/query/v2/accessors.cpp | 24 +- src/query/v2/accessors.hpp | 42 +- src/query/v2/context.hpp | 2 +- src/query/v2/conversions.hpp | 2 +- src/query/v2/interpreter.cpp | 1 + src/query/v2/plan/operator.cpp | 160 ++++++- src/query/v2/plan/vertex_count_cache.hpp | 2 +- src/query/v2/requests.hpp | 79 ++- src/query/v2/shard_request_manager.hpp | 61 +-- src/storage/v3/bindings/db_accessor.hpp | 2 +- src/storage/v3/shard.hpp | 4 +- src/storage/v3/shard_rsm.cpp | 449 ++++++++---------- src/storage/v3/value_conversions.hpp | 28 +- src/storage/v3/vertex_accessor.cpp | 1 + .../distributed_queries.py | 29 +- tests/simulation/common.hpp | 84 ++-- tests/simulation/shard_request_manager.cpp | 375 ++++++++------- tests/simulation/shard_rsm.cpp | 171 +++---- tests/unit/machine_manager.cpp | 44 +- 22 files changed, 884 insertions(+), 697 deletions(-) diff --git a/src/coordinator/shard_map.hpp b/src/coordinator/shard_map.hpp index 93ddd78c6..78a80e9e7 100644 --- a/src/coordinator/shard_map.hpp +++ b/src/coordinator/shard_map.hpp @@ -208,7 +208,13 @@ struct ShardMap { // Find a random place for the server to plug in } - LabelId GetLabelId(const std::string &label) const { return labels.at(label); } + std::optional GetLabelId(const std::string &label) const { + if (const auto it = labels.find(label); it != labels.end()) { + return it->second; + } + + return std::nullopt; + } std::string GetLabelName(const LabelId label) const { if (const auto it = @@ -220,8 +226,8 @@ struct ShardMap { } std::optional GetPropertyId(const std::string &property_name) const { - if (properties.contains(property_name)) { - return properties.at(property_name); + if (const auto it = properties.find(property_name); it != properties.end()) { + return it->second; } return std::nullopt; @@ -237,8 +243,8 @@ struct ShardMap { } std::optional GetEdgeTypeId(const std::string &edge_type) const { - if (edge_types.contains(edge_type)) { - return edge_types.at(edge_type); + if (const auto it = edge_types.find(edge_type); it != edge_types.end()) { + return it->second; } return std::nullopt; diff --git a/src/glue/v2/communication.cpp b/src/glue/v2/communication.cpp index f14013ae0..ffafc4a59 100644 --- a/src/glue/v2/communication.cpp +++ b/src/glue/v2/communication.cpp @@ -205,6 +205,7 @@ Value ToBoltValue(msgs::Value value) { case msgs::Value::Type::Edge: { throw utils::BasicException("Vertex and Edge not supported!"); } + // TODO Value to Date types not supported } } diff --git a/src/memgraph.cpp b/src/memgraph.cpp index 36a194fb4..9c4d71e94 100644 --- a/src/memgraph.cpp +++ b/src/memgraph.cpp @@ -643,10 +643,10 @@ int main(int argc, char **argv) { const std::string label{"label"}; memgraph::coordinator::ShardMap sm; auto prop_map = sm.AllocatePropertyIds(std::vector{property}); - auto edge_type_map = sm.AllocateEdgeTypeIds(std::vector{"edge_type"}); + auto edge_type_map = sm.AllocateEdgeTypeIds(std::vector{"TO"}); std::vector schema{{prop_map.at(property), memgraph::common::SchemaType::INT}}; sm.InitializeNewLabel(label, schema, 1, sm.shard_map_version); - sm.SplitShard(sm.GetHlc(), sm.GetLabelId(label), + sm.SplitShard(sm.GetHlc(), *sm.GetLabelId(label), std::vector{memgraph::storage::v3::PropertyValue{2}}); memgraph::coordinator::Coordinator coordinator{sm}; diff --git a/src/query/v2/accessors.cpp b/src/query/v2/accessors.cpp index de64e80fb..5391f1384 100644 --- a/src/query/v2/accessors.cpp +++ b/src/query/v2/accessors.cpp @@ -14,13 +14,12 @@ #include "storage/v3/id_types.hpp" namespace memgraph::query::v2::accessors { -EdgeAccessor::EdgeAccessor(Edge edge, std::vector> props) - : edge(std::move(edge)), properties(std::move(props)) {} +EdgeAccessor::EdgeAccessor(Edge edge) : edge(std::move(edge)) {} -EdgeTypeId EdgeAccessor::EdgeType() const { return EdgeTypeId::FromUint(edge.type.id); } +EdgeTypeId EdgeAccessor::EdgeType() const { return edge.type.id; } -std::vector> EdgeAccessor::Properties() const { - return properties; +const std::vector> &EdgeAccessor::Properties() const { + return edge.properties; // std::map res; // for (const auto &[name, value] : *properties) { // res[name] = ValueToTypedValue(value); @@ -34,7 +33,9 @@ Value EdgeAccessor::GetProperty(const std::string & /*prop_name*/) const { return {}; } -Edge EdgeAccessor::GetEdge() const { return edge; } +const Edge &EdgeAccessor::GetEdge() const { return edge; } + +bool EdgeAccessor::IsCycle() const { return edge.src == edge.dst; }; VertexAccessor EdgeAccessor::To() const { return VertexAccessor(Vertex{edge.dst}, {}); } @@ -45,6 +46,8 @@ VertexAccessor::VertexAccessor(Vertex v, std::vector VertexAccessor::Labels() const { return vertex.labels; } bool VertexAccessor::HasLabel(Label &label) const { @@ -52,14 +55,7 @@ bool VertexAccessor::HasLabel(Label &label) const { [label](const auto &l) { return l.id == label.id; }) != vertex.labels.end(); } -std::vector> VertexAccessor::Properties() const { - // std::map res; - // for (const auto &[name, value] : *properties) { - // res[name] = ValueToTypedValue(value); - // } - // return res; - return properties; -} +const std::vector> &VertexAccessor::Properties() const { return properties; } Value VertexAccessor::GetProperty(PropertyId prop_id) const { return std::find_if(properties.begin(), properties.end(), [&](auto &pr) { return prop_id == pr.first; })->second; diff --git a/src/query/v2/accessors.hpp b/src/query/v2/accessors.hpp index 4ea647539..eed169b8a 100644 --- a/src/query/v2/accessors.hpp +++ b/src/query/v2/accessors.hpp @@ -36,59 +36,61 @@ class VertexAccessor; class EdgeAccessor final { public: - EdgeAccessor(Edge edge, std::vector> props); + explicit EdgeAccessor(Edge edge); - EdgeTypeId EdgeType() const; + [[nodiscard]] EdgeTypeId EdgeType() const; - std::vector> Properties() const; + [[nodiscard]] const std::vector> &Properties() const; - Value GetProperty(const std::string &prop_name) const; + [[nodiscard]] Value GetProperty(const std::string &prop_name) const; - Edge GetEdge() const; + [[nodiscard]] const Edge &GetEdge() const; + + [[nodiscard]] bool IsCycle() const; // Dummy function // NOLINTNEXTLINE(readability-convert-member-functions-to-static) - inline size_t CypherId() const { return 10; } + [[nodiscard]] size_t CypherId() const { return 10; } // bool HasSrcAccessor const { return src == nullptr; } // bool HasDstAccessor const { return dst == nullptr; } - VertexAccessor To() const; - VertexAccessor From() const; + [[nodiscard]] VertexAccessor To() const; + [[nodiscard]] VertexAccessor From() const; - friend bool operator==(const EdgeAccessor &lhs, const EdgeAccessor &rhs) { - return lhs.edge == rhs.edge && lhs.properties == rhs.properties; - } + friend bool operator==(const EdgeAccessor &lhs, const EdgeAccessor &rhs) { return lhs.edge == rhs.edge; } friend bool operator!=(const EdgeAccessor &lhs, const EdgeAccessor &rhs) { return !(lhs == rhs); } private: Edge edge; - std::vector> properties; }; class VertexAccessor final { public: using PropertyId = msgs::PropertyId; using Label = msgs::Label; + using VertexId = msgs::VertexId; VertexAccessor(Vertex v, std::vector> props); - Label PrimaryLabel() const; + [[nodiscard]] Label PrimaryLabel() const; - std::vector