diff --git a/include/_mgp.hpp b/include/_mgp.hpp index c3f1eb794..96789d79d 100644 --- a/include/_mgp.hpp +++ b/include/_mgp.hpp @@ -255,14 +255,14 @@ inline mgp_edge *graph_create_edge(mgp_graph *graph, mgp_vertex *from, mgp_verte return MgInvoke(mgp_graph_create_edge, graph, from, to, type, memory); } -inline mgp_edge *graph_change_edge_from(struct mgp_graph *graph, struct mgp_edge *e, struct mgp_vertex *new_from, - mgp_memory *memory) { - return MgInvoke(mgp_graph_change_edge_from, graph, e, new_from, memory); +inline mgp_edge *graph_edge_set_from(struct mgp_graph *graph, struct mgp_edge *e, struct mgp_vertex *new_from, + mgp_memory *memory) { + return MgInvoke(mgp_graph_edge_set_from, graph, e, new_from, memory); } -inline mgp_edge *graph_change_edge_to(struct mgp_graph *graph, struct mgp_edge *e, struct mgp_vertex *new_to, - mgp_memory *memory) { - return MgInvoke(mgp_graph_change_edge_to, graph, e, new_to, memory); +inline mgp_edge *graph_edge_set_to(struct mgp_graph *graph, struct mgp_edge *e, struct mgp_vertex *new_to, + mgp_memory *memory) { + return MgInvoke(mgp_graph_edge_set_to, graph, e, new_to, memory); } inline void graph_delete_edge(mgp_graph *graph, mgp_edge *edge) { MgInvokeVoid(mgp_graph_delete_edge, graph, edge); } diff --git a/include/mg_procedure.h b/include/mg_procedure.h index 6d7285b45..007914eef 100644 --- a/include/mg_procedure.h +++ b/include/mg_procedure.h @@ -887,16 +887,16 @@ enum mgp_error mgp_graph_create_edge(struct mgp_graph *graph, struct mgp_vertex /// Return mgp_error::MGP_ERROR_UNABLE_TO_ALLOCATE if unable to allocate a mgp_edge. /// Return mgp_error::MGP_ERROR_DELETED_OBJECT if `from` or `to` has been deleted. /// Return mgp_error::MGP_ERROR_SERIALIZATION_ERROR if `from` or `to` has been modified by another transaction. -enum mgp_error mgp_graph_change_edge_from(struct mgp_graph *graph, struct mgp_edge *e, struct mgp_vertex *new_from, - struct mgp_memory *memory, struct mgp_edge **result); +enum mgp_error mgp_graph_edge_set_from(struct mgp_graph *graph, struct mgp_edge *e, struct mgp_vertex *new_from, + struct mgp_memory *memory, struct mgp_edge **result); /// Change edge to vertex /// Return mgp_error::MGP_ERROR_IMMUTABLE_OBJECT if `graph` is immutable. /// Return mgp_error::MGP_ERROR_UNABLE_TO_ALLOCATE if unable to allocate a mgp_edge. /// Return mgp_error::MGP_ERROR_DELETED_OBJECT if `from` or `to` has been deleted. /// Return mgp_error::MGP_ERROR_SERIALIZATION_ERROR if `from` or `to` has been modified by another transaction. -enum mgp_error mgp_graph_change_edge_to(struct mgp_graph *graph, struct mgp_edge *e, struct mgp_vertex *new_to, - struct mgp_memory *memory, struct mgp_edge **result); +enum mgp_error mgp_graph_edge_set_to(struct mgp_graph *graph, struct mgp_edge *e, struct mgp_vertex *new_to, + struct mgp_memory *memory, struct mgp_edge **result); /// Delete an edge from the graph. /// Return mgp_error::MGP_ERROR_IMMUTABLE_OBJECT if `graph` is immutable. diff --git a/include/mgp.hpp b/include/mgp.hpp index 5b2cc4f8d..169c93036 100644 --- a/include/mgp.hpp +++ b/include/mgp.hpp @@ -251,9 +251,9 @@ class Graph { /// @brief Creates a relationship of type `type` between nodes `from` and `to` and adds it to the graph. Relationship CreateRelationship(const Node &from, const Node &to, const std::string_view type); /// @brief Changes a relationship from node. - void ChangeRelationshipFrom(Relationship &relationship, const Node &new_from); + void SetFrom(Relationship &relationship, const Node &new_from); /// @brief Changes a relationship to node. - void ChangeRelationshipTo(Relationship &relationship, const Node &new_to); + void SetTo(Relationship &relationship, const Node &new_to); /// @brief Deletes a relationship from the graph. void DeleteRelationship(const Relationship &relationship); @@ -1989,14 +1989,14 @@ inline Relationship Graph::CreateRelationship(const Node &from, const Node &to, return relationship; } -inline void Graph::ChangeRelationshipFrom(Relationship &relationship, const Node &new_from) { - mgp_edge *edge = mgp::MemHandlerCallback(mgp::graph_change_edge_from, graph_, relationship.ptr_, new_from.ptr_); +inline void Graph::SetFrom(Relationship &relationship, const Node &new_from) { + mgp_edge *edge = mgp::MemHandlerCallback(mgp::graph_edge_set_from, graph_, relationship.ptr_, new_from.ptr_); relationship = Relationship(edge); mgp::edge_destroy(edge); } -inline void Graph::ChangeRelationshipTo(Relationship &relationship, const Node &new_to) { - mgp_edge *edge = mgp::MemHandlerCallback(mgp::graph_change_edge_to, graph_, relationship.ptr_, new_to.ptr_); +inline void Graph::SetTo(Relationship &relationship, const Node &new_to) { + mgp_edge *edge = mgp::MemHandlerCallback(mgp::graph_edge_set_to, graph_, relationship.ptr_, new_to.ptr_); relationship = Relationship(edge); mgp::edge_destroy(edge); } diff --git a/src/query/db_accessor.cpp b/src/query/db_accessor.cpp index 93c8d83f2..7412067ff 100644 --- a/src/query/db_accessor.cpp +++ b/src/query/db_accessor.cpp @@ -76,21 +76,21 @@ SubgraphDbAccessor::DetachRemoveVertex( // NOLINT(readability-convert-member-fu "Vertex holds only partial information about edges. Cannot detach delete safely while using projected graph."}; } -storage::Result SubgraphDbAccessor::ChangeEdgeFrom(EdgeAccessor *edge, SubgraphVertexAccessor *new_from) { +storage::Result SubgraphDbAccessor::EdgeSetFrom(EdgeAccessor *edge, SubgraphVertexAccessor *new_from) { VertexAccessor *new_from_impl = &new_from->impl_; if (!this->graph_->ContainsVertex(*new_from_impl)) { - throw std::logic_error{"Projected graph must contain the new from vertex!"}; + throw std::logic_error{"Projected graph must contain the new `from` vertex!"}; } - auto result = db_accessor_.ChangeEdgeFrom(edge, new_from_impl); + auto result = db_accessor_.EdgeSetFrom(edge, new_from_impl); return result; } -storage::Result SubgraphDbAccessor::ChangeEdgeTo(EdgeAccessor *edge, SubgraphVertexAccessor *new_to) { +storage::Result SubgraphDbAccessor::EdgeSetTo(EdgeAccessor *edge, SubgraphVertexAccessor *new_to) { VertexAccessor *new_to_impl = &new_to->impl_; if (!this->graph_->ContainsVertex(*new_to_impl)) { - throw std::logic_error{"Projected graph must contain the new to vertex!"}; + throw std::logic_error{"Projected graph must contain the new `to` vertex!"}; } - auto result = db_accessor_.ChangeEdgeFrom(edge, new_to_impl); + auto result = db_accessor_.EdgeSetTo(edge, new_to_impl); return result; } diff --git a/src/query/db_accessor.hpp b/src/query/db_accessor.hpp index 51a01089c..31538c51a 100644 --- a/src/query/db_accessor.hpp +++ b/src/query/db_accessor.hpp @@ -19,7 +19,6 @@ #include "query/exceptions.hpp" #include "storage/v2/edge_accessor.hpp" #include "storage/v2/id_types.hpp" -#include "storage/v2/inmemory/storage.hpp" #include "storage/v2/property_value.hpp" #include "storage/v2/result.hpp" #include "storage/v2/storage_mode.hpp" @@ -377,16 +376,14 @@ class DbAccessor final { return EdgeAccessor(*maybe_edge); } - storage::Result ChangeEdgeFrom(EdgeAccessor *edge, VertexAccessor *new_from) { - auto changed_edge = static_cast(accessor_)->ChangeEdgeFrom( - &edge->impl_, &new_from->impl_); + storage::Result EdgeSetFrom(EdgeAccessor *edge, VertexAccessor *new_from) { + auto changed_edge = accessor_->EdgeSetFrom(&edge->impl_, &new_from->impl_); if (changed_edge.HasError()) return storage::Result(changed_edge.GetError()); return EdgeAccessor(*changed_edge); } - storage::Result ChangeEdgeTo(EdgeAccessor *edge, VertexAccessor *new_to) { - auto changed_edge = static_cast(accessor_)->ChangeEdgeTo( - &edge->impl_, &new_to->impl_); + storage::Result EdgeSetTo(EdgeAccessor *edge, VertexAccessor *new_to) { + auto changed_edge = accessor_->EdgeSetTo(&edge->impl_, &new_to->impl_); if (changed_edge.HasError()) return storage::Result(changed_edge.GetError()); return EdgeAccessor(*changed_edge); } @@ -560,9 +557,9 @@ class SubgraphDbAccessor final { storage::Result InsertEdge(SubgraphVertexAccessor *from, SubgraphVertexAccessor *to, const storage::EdgeTypeId &edge_type); - storage::Result ChangeEdgeFrom(EdgeAccessor *edge, SubgraphVertexAccessor *new_from); + storage::Result EdgeSetFrom(EdgeAccessor *edge, SubgraphVertexAccessor *new_from); - storage::Result ChangeEdgeTo(EdgeAccessor *edge, SubgraphVertexAccessor *new_to); + storage::Result EdgeSetTo(EdgeAccessor *edge, SubgraphVertexAccessor *new_to); storage::Result>>> DetachRemoveVertex( SubgraphVertexAccessor *vertex_accessor); diff --git a/src/query/procedure/mg_procedure_impl.cpp b/src/query/procedure/mg_procedure_impl.cpp index 9cffb4d80..c8a882d02 100644 --- a/src/query/procedure/mg_procedure_impl.cpp +++ b/src/query/procedure/mg_procedure_impl.cpp @@ -2679,126 +2679,81 @@ mgp_error mgp_graph_create_edge(mgp_graph *graph, mgp_vertex *from, mgp_vertex * result); } -mgp_error mgp_graph_change_edge_from(struct mgp_graph *graph, struct mgp_edge *e, struct mgp_vertex *new_from, - mgp_memory *memory, mgp_edge **result) { - return WrapExceptions( - [&]() -> mgp_edge * { - auto *ctx = graph->ctx; +namespace { + +mgp_edge *EdgeSet(auto *e, auto *new_vertex, auto *memory, auto *graph, bool set_from) { + auto *ctx = graph->ctx; #ifdef MG_ENTERPRISE - if (memgraph::license::global_license_checker.IsEnterpriseValidFast() && ctx && ctx->auth_checker && - !ctx->auth_checker->Has(e->impl, memgraph::query::AuthQuery::FineGrainedPrivilege::CREATE_DELETE)) { - throw AuthorizationException{"Insufficient permissions for changing an edge!"}; - } + if (memgraph::license::global_license_checker.IsEnterpriseValidFast() && ctx && ctx->auth_checker && + !ctx->auth_checker->Has(e->impl, memgraph::query::AuthQuery::FineGrainedPrivilege::CREATE_DELETE)) { + throw AuthorizationException{"Insufficient permissions for changing an edge!"}; + } #endif - if (!MgpGraphIsMutable(*graph)) { - throw ImmutableObjectException{"Cannot remove an edge from an immutable graph!"}; - } + if (!MgpGraphIsMutable(*graph)) { + throw ImmutableObjectException{"Cannot change the edge because the graph is immutable!"}; + } - auto edge = std::visit(memgraph::utils::Overloaded{ - [&](memgraph::query::DbAccessor *accessor) { - return accessor->ChangeEdgeFrom( - &e->impl, &std::get(new_from->impl)); - }, - [&](memgraph::query::SubgraphDbAccessor *accessor) { - return accessor->ChangeEdgeFrom( - &e->impl, &std::get(new_from->impl)); - }}, - graph->impl); + auto edge = std::visit( + memgraph::utils::Overloaded{ + [&e, &new_vertex, &set_from]( + memgraph::query::DbAccessor *accessor) -> memgraph::storage::Result { + if (set_from) { + return accessor->EdgeSetFrom(&e->impl, &std::get(new_vertex->impl)); + } + return accessor->EdgeSetTo(&e->impl, &std::get(new_vertex->impl)); + }, + [&e, &new_vertex, &set_from](memgraph::query::SubgraphDbAccessor *accessor) + -> memgraph::storage::Result { + if (set_from) { + return accessor->EdgeSetFrom(&e->impl, + &std::get(new_vertex->impl)); + } + return accessor->EdgeSetTo(&e->impl, &std::get(new_vertex->impl)); + }}, + graph->impl); - if (edge.HasError()) { - switch (edge.GetError()) { - case memgraph::storage::Error::NONEXISTENT_OBJECT: - LOG_FATAL("Query modules shouldn't have access to nonexistent objects when changing an edge!"); - case memgraph::storage::Error::DELETED_OBJECT: - LOG_FATAL("The edge was already deleted."); - case memgraph::storage::Error::PROPERTIES_DISABLED: - case memgraph::storage::Error::VERTEX_HAS_EDGES: - LOG_FATAL("Unexpected error when removing an edge."); - case memgraph::storage::Error::SERIALIZATION_ERROR: - throw SerializationException{"Cannot serialize changing an edge."}; - } - } + if (edge.HasError()) { + switch (edge.GetError()) { + case memgraph::storage::Error::NONEXISTENT_OBJECT: + LOG_FATAL("Query modules shouldn't have access to nonexistent objects when changing an edge!"); + case memgraph::storage::Error::DELETED_OBJECT: + LOG_FATAL("The edge was already deleted."); + case memgraph::storage::Error::PROPERTIES_DISABLED: + case memgraph::storage::Error::VERTEX_HAS_EDGES: + LOG_FATAL("Unexpected error when removing an edge."); + case memgraph::storage::Error::SERIALIZATION_ERROR: + throw SerializationException{"Cannot serialize changing an edge."}; + } + } - if (ctx->trigger_context_collector) { - ctx->trigger_context_collector->RegisterDeletedObject(e->impl); - ctx->trigger_context_collector->RegisterCreatedObject(*edge); - } + if (ctx->trigger_context_collector) { + ctx->trigger_context_collector->RegisterDeletedObject(e->impl); + ctx->trigger_context_collector->RegisterCreatedObject(*edge); + } - return std::visit( - memgraph::utils::Overloaded{ - [memory, edge, new_from](memgraph::query::DbAccessor *) { - return NewRawMgpObject(memory->impl, edge.GetValue(), new_from->graph); - }, - [memory, edge, new_from](memgraph::query::SubgraphDbAccessor *db_impl) { - const auto &v_from = - memgraph::query::SubgraphVertexAccessor(edge.GetValue().From(), db_impl->getGraph()); - const auto &v_to = memgraph::query::SubgraphVertexAccessor(edge.GetValue().To(), db_impl->getGraph()); - return NewRawMgpObject(memory->impl, edge.GetValue(), v_from, v_to, new_from->graph); - }}, - new_from->graph->impl); - }, - result); + return std::visit( + memgraph::utils::Overloaded{ + [&memory, &edge, &new_vertex](memgraph::query::DbAccessor *) -> mgp_edge * { + return NewRawMgpObject(memory->impl, edge.GetValue(), new_vertex->graph); + }, + [&memory, &edge, &new_vertex](memgraph::query::SubgraphDbAccessor *db_impl) -> mgp_edge * { + const auto v_from = memgraph::query::SubgraphVertexAccessor(edge.GetValue().From(), db_impl->getGraph()); + const auto v_to = memgraph::query::SubgraphVertexAccessor(edge.GetValue().To(), db_impl->getGraph()); + return NewRawMgpObject(memory->impl, edge.GetValue(), v_from, v_to, new_vertex->graph); + }}, + new_vertex->graph->impl); } -mgp_error mgp_graph_change_edge_to(struct mgp_graph *graph, struct mgp_edge *e, struct mgp_vertex *new_to, - mgp_memory *memory, mgp_edge **result) { - return WrapExceptions( - [&]() -> mgp_edge * { - auto *ctx = graph->ctx; -#ifdef MG_ENTERPRISE - if (memgraph::license::global_license_checker.IsEnterpriseValidFast() && ctx && ctx->auth_checker && - !ctx->auth_checker->Has(e->impl, memgraph::query::AuthQuery::FineGrainedPrivilege::CREATE_DELETE)) { - throw AuthorizationException{"Insufficient permissions for changing an edge!"}; - } -#endif - if (!MgpGraphIsMutable(*graph)) { - throw ImmutableObjectException{"Cannot remove an edge from an immutable graph!"}; - } +} // namespace - auto edge = std::visit(memgraph::utils::Overloaded{ - [&](memgraph::query::DbAccessor *accessor) { - return accessor->ChangeEdgeTo( - &e->impl, &std::get(new_to->impl)); - }, - [&](memgraph::query::SubgraphDbAccessor *accessor) { - return accessor->ChangeEdgeTo( - &e->impl, &std::get(new_to->impl)); - }}, - graph->impl); +mgp_error mgp_graph_edge_set_from(struct mgp_graph *graph, struct mgp_edge *e, struct mgp_vertex *new_from, + mgp_memory *memory, mgp_edge **result) { + return WrapExceptions([&]() -> mgp_edge * { return EdgeSet(e, new_from, memory, graph, true); }, result); +} - if (edge.HasError()) { - switch (edge.GetError()) { - case memgraph::storage::Error::NONEXISTENT_OBJECT: - LOG_FATAL("Query modules shouldn't have access to nonexistent objects when changing an edge!"); - case memgraph::storage::Error::DELETED_OBJECT: - LOG_FATAL("The edge was already deleted."); - case memgraph::storage::Error::PROPERTIES_DISABLED: - case memgraph::storage::Error::VERTEX_HAS_EDGES: - LOG_FATAL("Unexpected error when removing an edge."); - case memgraph::storage::Error::SERIALIZATION_ERROR: - throw SerializationException{"Cannot serialize changing an edge."}; - } - } - - if (ctx->trigger_context_collector) { - ctx->trigger_context_collector->RegisterDeletedObject(e->impl); - ctx->trigger_context_collector->RegisterCreatedObject(*edge); - } - - return std::visit( - memgraph::utils::Overloaded{ - [memory, edge, new_to](memgraph::query::DbAccessor *) { - return NewRawMgpObject(memory->impl, edge.GetValue(), new_to->graph); - }, - [memory, edge, new_to](memgraph::query::SubgraphDbAccessor *db_impl) { - const auto &v_from = - memgraph::query::SubgraphVertexAccessor(edge.GetValue().From(), db_impl->getGraph()); - const auto &v_to = memgraph::query::SubgraphVertexAccessor(edge.GetValue().To(), db_impl->getGraph()); - return NewRawMgpObject(memory->impl, edge.GetValue(), v_from, v_to, new_to->graph); - }}, - new_to->graph->impl); - }, - result); +mgp_error mgp_graph_edge_set_to(struct mgp_graph *graph, struct mgp_edge *e, struct mgp_vertex *new_to, + mgp_memory *memory, mgp_edge **result) { + return WrapExceptions([&]() -> mgp_edge * { return EdgeSet(e, new_to, memory, graph, false); }, result); } mgp_error mgp_graph_delete_edge(struct mgp_graph *graph, mgp_edge *edge) { diff --git a/src/storage/v2/disk/storage.cpp b/src/storage/v2/disk/storage.cpp index a94c01552..e41172ba2 100644 --- a/src/storage/v2/disk/storage.cpp +++ b/src/storage/v2/disk/storage.cpp @@ -36,6 +36,7 @@ #include "storage/v2/disk/rocksdb_storage.hpp" #include "storage/v2/disk/storage.hpp" #include "storage/v2/disk/unique_constraints.hpp" +#include "storage/v2/edge_accessor.hpp" #include "storage/v2/edge_import_mode.hpp" #include "storage/v2/edge_ref.hpp" #include "storage/v2/id_types.hpp" @@ -1366,6 +1367,16 @@ Result> DiskStorage::DiskAccessor::DeleteEdge(EdgeAc &storage_->indices_, &storage_->constraints_, config_, true); } +Result DiskStorage::DiskAccessor::EdgeSetFrom(EdgeAccessor *edge, VertexAccessor *new_from) { + MG_ASSERT(false, "EdgeSetFrom is currently only implemented for InMemory storage"); + return Error::NONEXISTENT_OBJECT; +} + +Result DiskStorage::DiskAccessor::EdgeSetTo(EdgeAccessor *edge, VertexAccessor *new_to) { + MG_ASSERT(false, "EdgeSetTo is currently only implemented for InMemory storage"); + return Error::NONEXISTENT_OBJECT; +} + /// TODO: at which storage naming /// TODO: this method should also delete the old key bool DiskStorage::DiskAccessor::WriteVertexToDisk(const Vertex &vertex) { diff --git a/src/storage/v2/disk/storage.hpp b/src/storage/v2/disk/storage.hpp index 597a49b55..c8124e7a1 100644 --- a/src/storage/v2/disk/storage.hpp +++ b/src/storage/v2/disk/storage.hpp @@ -184,6 +184,10 @@ class DiskStorage final : public Storage { Result CreateEdge(VertexAccessor *from, VertexAccessor *to, EdgeTypeId edge_type) override; + Result EdgeSetFrom(EdgeAccessor *edge, VertexAccessor *new_from) override; + + Result EdgeSetTo(EdgeAccessor *edge, VertexAccessor *new_to) override; + Result> DeleteEdge(EdgeAccessor *edge) override; bool LabelIndexExists(LabelId label) const override { diff --git a/src/storage/v2/inmemory/storage.cpp b/src/storage/v2/inmemory/storage.cpp index 019c3a28e..d26b75b9b 100644 --- a/src/storage/v2/inmemory/storage.cpp +++ b/src/storage/v2/inmemory/storage.cpp @@ -496,7 +496,7 @@ Result InMemoryStorage::InMemoryAccessor::CreateEdgeEx(VertexAcces &storage_->constraints_, config_); } -Result InMemoryStorage::InMemoryAccessor::ChangeEdgeFrom(EdgeAccessor *edge, VertexAccessor *new_from) { +Result InMemoryStorage::InMemoryAccessor::EdgeSetFrom(EdgeAccessor *edge, VertexAccessor *new_from) { MG_ASSERT(edge->transaction_ == new_from->transaction_, "EdgeAccessor must be from the same transaction as the new from vertex " "accessor when deleting an edge!"); @@ -598,7 +598,7 @@ Result InMemoryStorage::InMemoryAccessor::ChangeEdgeFrom(EdgeAcces &storage_->constraints_, config_); } -Result InMemoryStorage::InMemoryAccessor::ChangeEdgeTo(EdgeAccessor *edge, VertexAccessor *new_to) { +Result InMemoryStorage::InMemoryAccessor::EdgeSetTo(EdgeAccessor *edge, VertexAccessor *new_to) { MG_ASSERT(edge->transaction_ == new_to->transaction_, "EdgeAccessor must be from the same transaction as the new to vertex " "accessor when deleting an edge!"); @@ -612,8 +612,8 @@ Result InMemoryStorage::InMemoryAccessor::ChangeEdgeTo(EdgeAccesso if (old_to_vertex->gid == new_to_vertex->gid) return *edge; - auto edge_ref = edge->edge_; - auto edge_type = edge->edge_type_; + auto &edge_ref = edge->edge_; + auto &edge_type = edge->edge_type_; std::unique_lock guard; if (config_.properties_on_edges) { @@ -704,8 +704,8 @@ Result> InMemoryStorage::InMemoryAccessor::DeleteEdg MG_ASSERT(edge->transaction_ == &transaction_, "EdgeAccessor must be from the same transaction as the storage " "accessor when deleting an edge!"); - auto edge_ref = edge->edge_; - auto edge_type = edge->edge_type_; + auto &edge_ref = edge->edge_; + auto &edge_type = edge->edge_type_; std::unique_lock guard; if (config_.properties_on_edges) { diff --git a/src/storage/v2/inmemory/storage.hpp b/src/storage/v2/inmemory/storage.hpp index 8ff87ad90..32faff226 100644 --- a/src/storage/v2/inmemory/storage.hpp +++ b/src/storage/v2/inmemory/storage.hpp @@ -221,9 +221,9 @@ class InMemoryStorage final : public Storage { /// @throw std::bad_alloc Result CreateEdge(VertexAccessor *from, VertexAccessor *to, EdgeTypeId edge_type) override; - Result ChangeEdgeFrom(EdgeAccessor *edge, VertexAccessor *new_from); + Result EdgeSetFrom(EdgeAccessor *edge, VertexAccessor *new_from) override; - Result ChangeEdgeTo(EdgeAccessor *edge, VertexAccessor *new_to); + Result EdgeSetTo(EdgeAccessor *edge, VertexAccessor *new_to) override; /// Accessor to the deleted edge if a deletion took place, std::nullopt otherwise /// @throw std::bad_alloc diff --git a/src/storage/v2/storage.hpp b/src/storage/v2/storage.hpp index 54c6fc31b..399325966 100644 --- a/src/storage/v2/storage.hpp +++ b/src/storage/v2/storage.hpp @@ -153,6 +153,10 @@ class Storage { virtual Result CreateEdge(VertexAccessor *from, VertexAccessor *to, EdgeTypeId edge_type) = 0; + virtual Result EdgeSetFrom(EdgeAccessor *edge, VertexAccessor *new_from) = 0; + + virtual Result EdgeSetTo(EdgeAccessor *edge, VertexAccessor *new_to) = 0; + virtual Result> DeleteEdge(EdgeAccessor *edge) = 0; virtual bool LabelIndexExists(LabelId label) const = 0; diff --git a/tests/unit/cpp_api.cpp b/tests/unit/cpp_api.cpp index 807746d01..1e0ab5ee2 100644 --- a/tests/unit/cpp_api.cpp +++ b/tests/unit/cpp_api.cpp @@ -701,7 +701,7 @@ TYPED_TEST(CppApiTestFixture, TestRelationshipChangeFrom) { auto relationship = graph.CreateRelationship(node_1, node_2, "Edge"); ASSERT_EQ(relationship.From().Id(), node_1.Id()); - graph.ChangeRelationshipFrom(relationship, node_3); + graph.SetFrom(relationship, node_3); ASSERT_EQ(std::string(relationship.Type()), "Edge"); ASSERT_EQ(relationship.From().Id(), node_3.Id()); @@ -719,7 +719,7 @@ TYPED_TEST(CppApiTestFixture, TestRelationshipChangeTo) { auto relationship = graph.CreateRelationship(node_1, node_2, "Edge"); ASSERT_EQ(relationship.To().Id(), node_2.Id()); - graph.ChangeRelationshipTo(relationship, node_3); + graph.SetTo(relationship, node_3); ASSERT_EQ(std::string(relationship.Type()), "Edge"); ASSERT_EQ(relationship.From().Id(), node_1.Id());