From e4a3ba7a2b80ad7969daf31a6b9cd69fc47038ce Mon Sep 17 00:00:00 2001 From: antoniofilipovic Date: Wed, 27 Jul 2022 21:42:57 +0200 Subject: [PATCH] add non working version of edge iterator --- src/query/graph.hpp | 10 ++++++++++ src/query/plan/operator.cpp | 8 +++++--- src/query/procedure/mg_procedure_impl.cpp | 18 ++++++++++++++++++ src/query/procedure/mg_procedure_impl.hpp | 5 +++-- 4 files changed, 36 insertions(+), 5 deletions(-) diff --git a/src/query/graph.hpp b/src/query/graph.hpp index 0a6fe6e3d..3547034eb 100644 --- a/src/query/graph.hpp +++ b/src/query/graph.hpp @@ -66,6 +66,16 @@ class Graph { std::for_each(path_edges_.begin(), path_edges_.end(), [this](const EdgeAccessor e) { edges_.push_back(e); }); } + std::vector OutEdges(query::VertexAccessor vertex_accessor) { + std::vector out_edges; + for (auto it = edges_.begin(); it != edges_.end(); ++it) { + if (it->From() == vertex_accessor) { + out_edges.emplace_back(*it); + } + } + return out_edges; + } + /** Move assign other, utils::MemoryResource of `this` is used. */ Graph &operator=(Graph &&) = default; diff --git a/src/query/plan/operator.cpp b/src/query/plan/operator.cpp index e9f9ab313..0a2ba7f1d 100644 --- a/src/query/plan/operator.cpp +++ b/src/query/plan/operator.cpp @@ -3739,10 +3739,12 @@ void CallCustomProcedure(const std::string_view fully_qualified_procedure_name, for (auto *expression : args) { args_list.emplace_back(expression->Accept(*evaluator)); } - const query::Graph *subgraph; + if (!args_list.empty() && args_list.front().type() == TypedValue::Type::Graph) { - subgraph = &args_list.front().ValueGraph(); - args_list.erase(args_list.begin()); + TypedValue subgraph = TypedValue(args_list.front(), args_list.front().ValueGraph().GetMemoryResource()); + + args_list.erase(args_list.begin()); // ova linija obrise vertexe + graph.subgraph = &subgraph.ValueGraph(); } // if we have graph at first element, it is okay to have 1+ element here diff --git a/src/query/procedure/mg_procedure_impl.cpp b/src/query/procedure/mg_procedure_impl.cpp index 664d74c44..f238950c1 100644 --- a/src/query/procedure/mg_procedure_impl.cpp +++ b/src/query/procedure/mg_procedure_impl.cpp @@ -1866,6 +1866,24 @@ mgp_error mgp_vertex_iter_out_edges(mgp_vertex *v, mgp_memory *memory, mgp_edges [v, memory] { auto it = NewMgpObject(memory, *v); MG_ASSERT(it != nullptr); + if (v->graph->subgraph) { + spdlog::info("works here"); + auto edges = v->graph->subgraph->OutEdges(v->impl); + std::vector edges_; + edges_.reserve(edges.size()); + + for (auto it = edges.begin(); it != edges.end(); ++it) { + edges_.emplace_back(mgp_edge(*it, v->graph, memory->impl)); + } + + // it->out.emplace(std::move(edges_)); + // it->out_it.emplace(it->out->begin()); + // if (*it->out_it != it->out->end()) { + // it->current_e.emplace(**it->out_it, v->graph, it->GetMemoryResource()); + // } + + // return it.release(); + } auto maybe_edges = v->impl.OutEdges(v->graph->view); if (maybe_edges.HasError()) { diff --git a/src/query/procedure/mg_procedure_impl.hpp b/src/query/procedure/mg_procedure_impl.hpp index 6336204f0..07c126ed0 100644 --- a/src/query/procedure/mg_procedure_impl.hpp +++ b/src/query/procedure/mg_procedure_impl.hpp @@ -576,16 +576,17 @@ struct mgp_graph { // TODO: Merge `mgp_graph` and `mgp_memory` into a single `mgp_context`. The // `ctx` field is out of place here. memgraph::query::ExecutionContext *ctx; + memgraph::query::Graph *subgraph; // memgraph:::query::Graph *subraph; static mgp_graph WritableGraph(memgraph::query::DbAccessor &acc, memgraph::storage::View view, memgraph::query::ExecutionContext &ctx) { - return mgp_graph{&acc, view, &ctx}; + return mgp_graph{&acc, view, &ctx, nullptr}; } static mgp_graph NonWritableGraph(memgraph::query::DbAccessor &acc, memgraph::storage::View view) { - return mgp_graph{&acc, view, nullptr}; + return mgp_graph{&acc, view, nullptr, nullptr}; } };