From 026ccc85eecc5c8a6e617a11b3cbc5f58a0b53f7 Mon Sep 17 00:00:00 2001 From: antoniofilipovic Date: Mon, 15 Aug 2022 18:19:25 +0200 Subject: [PATCH] add impl of insert vertex --- src/query/db_accessor.cpp | 8 ++++---- src/query/db_accessor.hpp | 2 +- src/query/graph.cpp | 4 ++++ src/query/graph.hpp | 3 +++ src/query/procedure/mg_procedure_impl.cpp | 12 ++++++++---- 5 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/query/db_accessor.cpp b/src/query/db_accessor.cpp index 7af481631..ac3f3305e 100644 --- a/src/query/db_accessor.cpp +++ b/src/query/db_accessor.cpp @@ -77,10 +77,10 @@ storage::Result> SubgraphDbAccessor::RemoveVertex( return result; } -VertexAccessor SubgraphDbAccessor::InsertVertex() { - auto result = db_accessor_->InsertVertex(); - // todo antoniofilipovic add vertex to subgraph - return result; +SubgraphVertexAccessor SubgraphDbAccessor::InsertVertex() { + VertexAccessor vertex = db_accessor_->InsertVertex(); + this->graph_->InsertVertex(vertex); + return SubgraphVertexAccessor(vertex, this->getGraph()); } VerticesIterable SubgraphDbAccessor::Vertices(storage::View view) { diff --git a/src/query/db_accessor.hpp b/src/query/db_accessor.hpp index 1b843ed88..431d6863f 100644 --- a/src/query/db_accessor.hpp +++ b/src/query/db_accessor.hpp @@ -486,7 +486,7 @@ class SubgraphDbAccessor final { storage::Result> RemoveVertex(VertexAccessor *vertex_accessor); - VertexAccessor InsertVertex(); + SubgraphVertexAccessor InsertVertex(); VerticesIterable Vertices(storage::View view); diff --git a/src/query/graph.cpp b/src/query/graph.cpp index a40ee382d..58c2ec606 100644 --- a/src/query/graph.cpp +++ b/src/query/graph.cpp @@ -31,6 +31,10 @@ void Graph::Expand(const Path &path) { std::for_each(path_edges_.begin(), path_edges_.end(), [this](const EdgeAccessor e) { edges_.insert(e); }); } +void Graph::InsertVertex(const VertexAccessor &vertex) { vertices_.insert(vertex); } + +void Graph::InsertEdge(const EdgeAccessor &edge) { edges_.insert(edge); } + std::vector Graph::OutEdges(query::VertexAccessor vertex_accessor) { std::vector out_edges; for (auto it = edges_.begin(); it != edges_.end(); ++it) { diff --git a/src/query/graph.hpp b/src/query/graph.hpp index 67b493d33..b4d599103 100644 --- a/src/query/graph.hpp +++ b/src/query/graph.hpp @@ -57,6 +57,9 @@ class Graph final { /** Expands the graph with the given path. */ void Expand(const Path &path); + void InsertVertex(const VertexAccessor &vertex); + void InsertEdge(const EdgeAccessor &edge); + std::vector OutEdges(VertexAccessor vertex_accessor); /** Move assign other, utils::MemoryResource of `this` is used. */ diff --git a/src/query/procedure/mg_procedure_impl.cpp b/src/query/procedure/mg_procedure_impl.cpp index f3f0e5398..8b70652ae 100644 --- a/src/query/procedure/mg_procedure_impl.cpp +++ b/src/query/procedure/mg_procedure_impl.cpp @@ -2222,6 +2222,7 @@ mgp_error mgp_graph_get_vertex_by_id(mgp_graph *graph, mgp_vertex_id id, mgp_mem }, graph->impl); if (maybe_vertex) { + // todo antoniofilipovic change this to set proper vertexAccessro return NewRawMgpObject(memory, *maybe_vertex, graph); } return nullptr; @@ -2240,16 +2241,18 @@ mgp_error mgp_graph_create_vertex(struct mgp_graph *graph, mgp_memory *memory, m if (!MgpGraphIsMutable(*graph)) { throw ImmutableObjectException{"Cannot create a vertex in an immutable graph!"}; } - auto vertex = - std::visit(memgraph::utils::Overloaded{[](auto *impl) { return impl->InsertVertex(); }}, graph->impl); + auto vertex = std::visit(memgraph::utils::Overloaded{[=](auto *impl) { + return NewRawMgpObject(memory, impl->InsertVertex(), graph); + }}, + graph->impl); auto &ctx = graph->ctx; ctx->execution_stats[memgraph::query::ExecutionStats::Key::CREATED_NODES] += 1; if (ctx->trigger_context_collector) { - ctx->trigger_context_collector->RegisterCreatedObject(vertex); + ctx->trigger_context_collector->RegisterCreatedObject(vertex->getImpl()); } - return NewRawMgpObject(memory, vertex, graph); + return vertex; }, result); } @@ -2417,6 +2420,7 @@ mgp_error mgp_graph_create_edge(mgp_graph *graph, mgp_vertex *from, mgp_vertex * if (ctx->trigger_context_collector) { ctx->trigger_context_collector->RegisterCreatedObject(*edge); } + // check what does this method call return NewRawMgpObject(memory, edge.GetValue(), from->graph); }, result);