add filtering out/in edges, and subgraphvertex creation
This commit is contained in:
parent
006aadac6e
commit
765145dbdf
src/query
@ -15,6 +15,10 @@
|
||||
|
||||
#include "query/graph.hpp"
|
||||
|
||||
#include <cppitertools/filter.hpp>
|
||||
#include <cppitertools/imap.hpp>
|
||||
#include "utils/pmr/unordered_set.hpp"
|
||||
|
||||
namespace memgraph::query {
|
||||
SubgraphDbAccessor::SubgraphDbAccessor(query::DbAccessor *db_accessor, Graph *graph)
|
||||
: db_accessor_(db_accessor), graph_(graph) {}
|
||||
@ -91,4 +95,53 @@ std::optional<VertexAccessor> SubgraphDbAccessor::FindVertex(storage::Gid gid, s
|
||||
}
|
||||
|
||||
query::Graph *SubgraphDbAccessor::getGraph() { return graph_; }
|
||||
|
||||
auto SubgraphVertexAccessor::OutEdges(storage::View view) -> decltype(impl_.OutEdges(view)) const {
|
||||
// todo antoniofilipovic add filtering here
|
||||
|
||||
auto maybe_edges = impl_.impl_.OutEdges(view, {});
|
||||
if (maybe_edges.HasError()) return maybe_edges.GetError();
|
||||
auto edges = std::move(*maybe_edges);
|
||||
auto graph_edges = graph_->edges();
|
||||
|
||||
std::unordered_set<storage::EdgeAccessor> graph_edges_storage;
|
||||
|
||||
for (auto e : graph_edges) {
|
||||
graph_edges_storage.insert(e.impl_);
|
||||
}
|
||||
|
||||
std::vector<storage::EdgeAccessor> filteredOutEdges;
|
||||
for (auto &edge : edges) {
|
||||
if (std::find(begin(graph_edges_storage), end(graph_edges_storage), edge) != std::end(graph_edges_storage)) {
|
||||
filteredOutEdges.push_back(edge);
|
||||
}
|
||||
}
|
||||
|
||||
return iter::imap(VertexAccessor::MakeEdgeAccessor, std::move(filteredOutEdges));
|
||||
}
|
||||
|
||||
auto SubgraphVertexAccessor::InEdges(storage::View view) -> decltype(impl_.OutEdges(view)) const {
|
||||
// todo antoniofilipovic add filtering here
|
||||
|
||||
auto maybe_edges = impl_.impl_.InEdges(view, {});
|
||||
if (maybe_edges.HasError()) return maybe_edges.GetError();
|
||||
auto edges = std::move(*maybe_edges);
|
||||
auto graph_edges = graph_->edges();
|
||||
|
||||
std::unordered_set<storage::EdgeAccessor> graph_edges_storage;
|
||||
|
||||
for (auto e : graph_edges) {
|
||||
graph_edges_storage.insert(e.impl_);
|
||||
}
|
||||
|
||||
std::vector<storage::EdgeAccessor> filteredOutEdges;
|
||||
for (auto &edge : edges) {
|
||||
if (std::find(begin(graph_edges_storage), end(graph_edges_storage), edge) != std::end(graph_edges_storage)) {
|
||||
filteredOutEdges.push_back(edge);
|
||||
}
|
||||
}
|
||||
|
||||
return iter::imap(VertexAccessor::MakeEdgeAccessor, std::move(filteredOutEdges));
|
||||
}
|
||||
|
||||
} // namespace memgraph::query
|
||||
|
@ -200,20 +200,9 @@ class SubgraphVertexAccessor final {
|
||||
return impl_ == v.impl_;
|
||||
}
|
||||
|
||||
auto InEdges(storage::View view) -> decltype(impl_.OutEdges(view)) const {
|
||||
// todo antoniofilipovic add filtering here
|
||||
auto InEdges(storage::View view) -> decltype(impl_.OutEdges(view)) const;
|
||||
|
||||
auto maybe_edges = impl_.impl_.InEdges(view, {});
|
||||
if (maybe_edges.HasError()) return maybe_edges.GetError();
|
||||
return iter::imap(VertexAccessor::MakeEdgeAccessor, std::move(*maybe_edges));
|
||||
}
|
||||
|
||||
auto OutEdges(storage::View view) -> decltype(impl_.OutEdges(view)) const {
|
||||
// todo antoniofilipovic add filtering here
|
||||
auto maybe_edges = impl_.impl_.OutEdges(view, {});
|
||||
if (maybe_edges.HasError()) return maybe_edges.GetError();
|
||||
return iter::imap(VertexAccessor::MakeEdgeAccessor, std::move(*maybe_edges));
|
||||
}
|
||||
auto OutEdges(storage::View view) -> decltype(impl_.OutEdges(view)) const;
|
||||
|
||||
auto Labels(storage::View view) const { return impl_.Labels(view); }
|
||||
|
||||
|
@ -3733,15 +3733,15 @@ void CallCustomProcedure(const std::string_view fully_qualified_procedure_name,
|
||||
for (auto *expression : args) {
|
||||
args_list.emplace_back(expression->Accept(*evaluator));
|
||||
}
|
||||
query::SubgraphDbAccessor *subgraphAccessor = nullptr;
|
||||
if (!args_list.empty() && args_list.front().type() == TypedValue::Type::Graph) {
|
||||
TypedValue subgraph_typed = TypedValue(args_list.front(), args_list.front().ValueGraph().GetMemoryResource());
|
||||
|
||||
if (!args_list.empty() && args_list.front().type() == TypedValue::Type::Graph) {
|
||||
// TypedValue subgraph_typed = TypedValue(args_list.front(), args_list.front().ValueGraph().GetMemoryResource());
|
||||
query::Graph *subgraph =
|
||||
new query::Graph(std::move(args_list.front().ValueGraph()), args_list.front().ValueGraph().GetMemoryResource());
|
||||
args_list.erase(args_list.begin());
|
||||
query::Graph *subgraph = &subgraph_typed.ValueGraph();
|
||||
subgraphAccessor =
|
||||
query::SubgraphDbAccessor::MakeSubgraphDbAccessor(std::get<query::DbAccessor *>(graph.impl), subgraph);
|
||||
graph.impl = subgraphAccessor;
|
||||
// query::Graph *subgraph = new query::Graph(std::move(graph), args_list.front().ValueGraph().GetMemoryResource())
|
||||
|
||||
graph.impl = query::SubgraphDbAccessor::MakeSubgraphDbAccessor(std::get<query::DbAccessor *>(graph.impl), subgraph);
|
||||
}
|
||||
|
||||
procedure::ConstructArguments(args_list, proc, fully_qualified_procedure_name, proc_args, graph);
|
||||
|
@ -461,7 +461,17 @@ mgp_value::mgp_value(const memgraph::query::TypedValue &tv, mgp_graph *graph, me
|
||||
}
|
||||
case MGP_VALUE_TYPE_VERTEX: {
|
||||
memgraph::utils::Allocator<mgp_vertex> allocator(m);
|
||||
vertex_v = allocator.new_object<mgp_vertex>(tv.ValueVertex(), graph);
|
||||
vertex_v = std::visit(
|
||||
memgraph::utils::Overloaded{[&](memgraph::query::DbAccessor *impl) {
|
||||
return allocator.new_object<mgp_vertex>(tv.ValueVertex(), graph);
|
||||
},
|
||||
[&](memgraph::query::SubgraphDbAccessor *impl) {
|
||||
return allocator.new_object<mgp_vertex>(
|
||||
memgraph::query::SubgraphVertexAccessor(tv.ValueVertex(), impl->getGraph()),
|
||||
graph);
|
||||
}},
|
||||
graph->impl);
|
||||
|
||||
break;
|
||||
}
|
||||
case MGP_VALUE_TYPE_EDGE: {
|
||||
|
Loading…
Reference in New Issue
Block a user