implement edge insertion

This commit is contained in:
antoniofilipovic 2022-08-16 14:22:49 +02:00
parent 93a2de96c1
commit 5505257daa
3 changed files with 31 additions and 26 deletions

View File

@ -57,10 +57,16 @@ storage::Result<std::optional<EdgeAccessor>> SubgraphDbAccessor::RemoveEdge(Edge
return result;
}
storage::Result<EdgeAccessor> SubgraphDbAccessor::InsertEdge(VertexAccessor *from, VertexAccessor *to,
storage::Result<EdgeAccessor> SubgraphDbAccessor::InsertEdge(SubgraphVertexAccessor *from, SubgraphVertexAccessor *to,
const storage::EdgeTypeId &edge_type) {
auto result = db_accessor_->InsertEdge(from, to, edge_type);
// todo antoniofilipovic add edge to subgraph
VertexAccessor *from_impl = &from->impl_;
VertexAccessor *to_impl = &to->impl_;
auto result = db_accessor_->InsertEdge(from_impl, to_impl, edge_type);
if (result.HasError()) {
return result;
}
this->graph_->InsertEdge(*result);
return result;
}

View File

@ -479,7 +479,7 @@ class SubgraphDbAccessor final {
storage::Result<std::optional<EdgeAccessor>> RemoveEdge(EdgeAccessor *edge);
storage::Result<EdgeAccessor> InsertEdge(VertexAccessor *from, VertexAccessor *to,
storage::Result<EdgeAccessor> InsertEdge(SubgraphVertexAccessor *from, SubgraphVertexAccessor *to,
const storage::EdgeTypeId &edge_type);
storage::Result<std::optional<std::pair<VertexAccessor, std::vector<EdgeAccessor>>>> DetachRemoveVertex(

View File

@ -2385,28 +2385,27 @@ mgp_error mgp_graph_create_edge(mgp_graph *graph, mgp_vertex *from, mgp_vertex *
if (!MgpGraphIsMutable(*graph)) {
throw ImmutableObjectException{"Cannot create an edge in an immutable graph!"};
}
auto edge = std::visit(memgraph::utils::Overloaded{
[from, to, type](memgraph::query::DbAccessor *impl) {
if (std::holds_alternative<memgraph::query::SubgraphVertexAccessor>(from->impl) ||
std::holds_alternative<memgraph::query::SubgraphVertexAccessor>(to->impl)) {
throw std::logic_error{"Both vertices must be of VertexAccessorType"};
}
return impl->InsertEdge(&std::get<memgraph::query::VertexAccessor>(from->impl),
&std::get<memgraph::query::VertexAccessor>(to->impl),
impl->NameToEdgeType(type.name));
},
[from, to, type](memgraph::query::SubgraphDbAccessor *impl) {
// todo antoniofilipovic change this, it is wrong here since it needs to be
// SubgraphVertexAccessor
if (std::holds_alternative<memgraph::query::SubgraphVertexAccessor>(from->impl) ||
std::holds_alternative<memgraph::query::SubgraphVertexAccessor>(to->impl)) {
throw std::logic_error{"Wrong type"};
}
return impl->InsertEdge(&std::get<memgraph::query::VertexAccessor>(from->impl),
&std::get<memgraph::query::VertexAccessor>(to->impl),
impl->NameToEdgeType(type.name));
}},
graph->impl);
auto edge =
std::visit(memgraph::utils::Overloaded{
[from, to, type](memgraph::query::DbAccessor *impl) {
if (std::holds_alternative<memgraph::query::SubgraphVertexAccessor>(from->impl) ||
std::holds_alternative<memgraph::query::SubgraphVertexAccessor>(to->impl)) {
throw std::logic_error{"Both vertices must be of VertexAccessor type"};
}
return impl->InsertEdge(&std::get<memgraph::query::VertexAccessor>(from->impl),
&std::get<memgraph::query::VertexAccessor>(to->impl),
impl->NameToEdgeType(type.name));
},
[from, to, type](memgraph::query::SubgraphDbAccessor *impl) {
if (std::holds_alternative<memgraph::query::VertexAccessor>(from->impl) ||
std::holds_alternative<memgraph::query::VertexAccessor>(to->impl)) {
throw std::logic_error{"Both vertices must be of SubgraphVertexAccessor type"};
}
return impl->InsertEdge(&std::get<memgraph::query::SubgraphVertexAccessor>(from->impl),
&std::get<memgraph::query::SubgraphVertexAccessor>(to->impl),
impl->NameToEdgeType(type.name));
}},
graph->impl);
if (edge.HasError()) {
switch (edge.GetError()) {