diff --git a/src/query/db_accessor.hpp b/src/query/db_accessor.hpp index 915ea9936..381f407ef 100644 --- a/src/query/db_accessor.hpp +++ b/src/query/db_accessor.hpp @@ -439,6 +439,12 @@ class DbAccessor final { return std::nullopt; } + std::optional FindEdge(storage::Gid gid, storage::View view) { + auto maybe_edge = accessor_->FindEdge(gid, view); + if (maybe_edge) return EdgeAccessor(*maybe_edge); + return std::nullopt; + } + void FinalizeTransaction() { accessor_->FinalizeTransaction(); } void TrackCurrentThreadAllocations() { @@ -789,6 +795,8 @@ class SubgraphDbAccessor final { std::optional FindVertex(storage::Gid gid, storage::View view); + std::optional FindEdge(storage::Gid gid, storage::View view); + Graph *getGraph(); storage::StorageMode GetStorageMode() const noexcept; diff --git a/src/storage/v2/disk/storage.cpp b/src/storage/v2/disk/storage.cpp index 21ae7755e..cdb8e843d 100644 --- a/src/storage/v2/disk/storage.cpp +++ b/src/storage/v2/disk/storage.cpp @@ -913,6 +913,10 @@ std::optional DiskStorage::DiskAccessor::FindVertex(storage::Gid return disk_storage->FindVertex(gid, &transaction_, view); } +std::optional DiskStorage::DiskAccessor::FindEdge(storage::Gid gid, View view) { + throw utils::NotYetImplemented("Id based lookup for on-disk storage mode is not yet implemented."); +} + Result, std::vector>>> DiskStorage::DiskAccessor::DetachDelete(std::vector nodes, std::vector edges, bool detach) { diff --git a/src/storage/v2/disk/storage.hpp b/src/storage/v2/disk/storage.hpp index 349a7454a..4735769d3 100644 --- a/src/storage/v2/disk/storage.hpp +++ b/src/storage/v2/disk/storage.hpp @@ -72,6 +72,8 @@ class DiskStorage final : public Storage { const std::optional> &lower_bound, const std::optional> &upper_bound, View view) override; + std::optional FindEdge(Gid gid, View view) override; + EdgesIterable Edges(EdgeTypeId edge_type, View view) override; uint64_t ApproximateVertexCount() const override; diff --git a/src/storage/v2/edge_accessor.cpp b/src/storage/v2/edge_accessor.cpp index 62a9f4bcd..d03e489d4 100644 --- a/src/storage/v2/edge_accessor.cpp +++ b/src/storage/v2/edge_accessor.cpp @@ -26,6 +26,11 @@ #include "utils/memory_tracker.hpp" namespace memgraph::storage { +std::optional EdgeAccessor::Create(EdgeRef edge, EdgeTypeId edge_type, Vertex *from_vertex, + Vertex *to_vertex, Storage *storage, Transaction *transaction, + bool for_deleted) { + return std::nullopt; +} bool EdgeAccessor::IsDeleted() const { if (!storage_->config_.salient.items.properties_on_edges) { diff --git a/src/storage/v2/edge_accessor.hpp b/src/storage/v2/edge_accessor.hpp index 6b76ddbe8..92451b084 100644 --- a/src/storage/v2/edge_accessor.hpp +++ b/src/storage/v2/edge_accessor.hpp @@ -44,6 +44,9 @@ class EdgeAccessor final { transaction_(transaction), for_deleted_(for_deleted) {} + static std::optional Create(EdgeRef edge, EdgeTypeId edge_type, Vertex *from_vertex, Vertex *to_vertex, + Storage *storage, Transaction *transaction, bool for_deleted = false); + bool IsDeleted() const; /// @return true if the object is visible from the current transaction diff --git a/src/storage/v2/inmemory/storage.cpp b/src/storage/v2/inmemory/storage.cpp index 1ea909450..f72636584 100644 --- a/src/storage/v2/inmemory/storage.cpp +++ b/src/storage/v2/inmemory/storage.cpp @@ -1426,6 +1426,15 @@ EdgesIterable InMemoryStorage::InMemoryAccessor::Edges(EdgeTypeId edge_type, Vie return EdgesIterable(mem_edge_type_index->Edges(edge_type, view, storage_, &transaction_)); } +std::optional InMemoryStorage::InMemoryAccessor::FindEdge(Gid gid, View view) { + auto *mem_storage = static_cast(storage_); + auto acc = mem_storage->edges_.access(); + auto it = acc.find(gid); + if (it == acc.end()) return std::nullopt; + // Create EdgeAccessor! + return {}; +} + Transaction InMemoryStorage::CreateTransaction( IsolationLevel isolation_level, StorageMode storage_mode, memgraph::replication_coordination_glue::ReplicationRole replication_role) { diff --git a/src/storage/v2/inmemory/storage.hpp b/src/storage/v2/inmemory/storage.hpp index 6d10e0fbd..d1b2a9e58 100644 --- a/src/storage/v2/inmemory/storage.hpp +++ b/src/storage/v2/inmemory/storage.hpp @@ -109,6 +109,8 @@ class InMemoryStorage final : public Storage { const std::optional> &lower_bound, const std::optional> &upper_bound, View view) override; + std::optional FindEdge(Gid gid, View view) override; + EdgesIterable Edges(EdgeTypeId edge_type, View view) override; /// Return approximate number of all vertices in the database. diff --git a/src/storage/v2/storage.hpp b/src/storage/v2/storage.hpp index 58936bd56..80dd93d4e 100644 --- a/src/storage/v2/storage.hpp +++ b/src/storage/v2/storage.hpp @@ -174,6 +174,8 @@ class Storage { const std::optional> &lower_bound, const std::optional> &upper_bound, View view) = 0; + virtual std::optional FindEdge(Gid gid, View view) = 0; + virtual EdgesIterable Edges(EdgeTypeId edge_type, View view) = 0; virtual Result> DeleteVertex(VertexAccessor *vertex);