Fix some compilation errors in query engine module

This commit is contained in:
Aidar Samerkhanov 2023-04-12 22:16:54 +00:00
parent faa3e542b6
commit 18bf1c237b
6 changed files with 130 additions and 103 deletions

View File

@ -35,6 +35,7 @@
// This cannot be avoided by simple include orderings so we // This cannot be avoided by simple include orderings so we
// simply undefine those macros as we're sure that libkrb5 // simply undefine those macros as we're sure that libkrb5
// won't and can't be used anywhere in the query engine. // won't and can't be used anywhere in the query engine.
#include "storage/v2/edge_accessor.hpp"
#include "storage/v2/storage.hpp" #include "storage/v2/storage.hpp"
#undef FALSE #undef FALSE
@ -83,9 +84,9 @@ class EdgeAccessor final {
return impl_->ClearProperties(); return impl_->ClearProperties();
} }
VertexAccessor To() const; std::unique_ptr<VertexAccessor> To() const;
VertexAccessor From() const; std::unique_ptr<VertexAccessor> From() const;
bool IsCycle() const; bool IsCycle() const;
@ -102,7 +103,9 @@ class VertexAccessor final {
public: public:
storage::VertexAccessor *impl_; storage::VertexAccessor *impl_;
static EdgeAccessor MakeEdgeAccessor(const storage::EdgeAccessor impl) { return EdgeAccessor(impl); } static std::unique_ptr<EdgeAccessor> MakeEdgeAccessor(const std::unique_ptr<storage::EdgeAccessor> &impl) {
return std::make_unique<EdgeAccessor>(std::move(impl));
}
public: public:
explicit VertexAccessor(storage::VertexAccessor *impl) : impl_(impl) {} explicit VertexAccessor(storage::VertexAccessor *impl) : impl_(impl) {}
@ -168,7 +171,7 @@ class VertexAccessor final {
auto OutEdges(storage::View view, const std::vector<storage::EdgeTypeId> &edge_types, auto OutEdges(storage::View view, const std::vector<storage::EdgeTypeId> &edge_types,
const VertexAccessor &dest) const const VertexAccessor &dest) const
-> storage::Result<decltype(iter::imap(MakeEdgeAccessor, *impl_.OutEdges(view)))> { -> storage::Result<decltype(iter::imap(MakeEdgeAccessor, *impl_->OutEdges(view)))> {
auto maybe_edges = impl_->OutEdges(view, edge_types, dest.impl_); auto maybe_edges = impl_->OutEdges(view, edge_types, dest.impl_);
if (maybe_edges.HasError()) return maybe_edges.GetError(); if (maybe_edges.HasError()) return maybe_edges.GetError();
return iter::imap(MakeEdgeAccessor, std::move(*maybe_edges)); return iter::imap(MakeEdgeAccessor, std::move(*maybe_edges));
@ -190,9 +193,13 @@ class VertexAccessor final {
bool operator!=(const VertexAccessor &v) const noexcept { return !(*this == v); } bool operator!=(const VertexAccessor &v) const noexcept { return !(*this == v); }
}; };
inline VertexAccessor EdgeAccessor::To() const { return VertexAccessor(impl_->ToVertex()); } inline std::unique_ptr<VertexAccessor> EdgeAccessor::To() const {
return std::make_unique<VertexAccessor>(impl_->ToVertex());
}
inline VertexAccessor EdgeAccessor::From() const { return VertexAccessor(impl_->FromVertex()); } inline std::unique_ptr<VertexAccessor> EdgeAccessor::From() const {
return std::make_unique<VertexAccessor>(impl_->FromVertex());
}
inline bool EdgeAccessor::IsCycle() const { return To() == From(); } inline bool EdgeAccessor::IsCycle() const { return To() == From(); }
@ -318,10 +325,10 @@ class DbAccessor final {
public: public:
explicit DbAccessor(storage::Storage::Accessor *accessor) : accessor_(accessor) {} explicit DbAccessor(storage::Storage::Accessor *accessor) : accessor_(accessor) {}
std::optional<VertexAccessor> FindVertex(storage::Gid gid, storage::View view) { std::unique_ptr<VertexAccessor> FindVertex(storage::Gid gid, storage::View view) {
auto maybe_vertex = accessor_->FindVertex(gid, view); auto maybe_vertex = accessor_->FindVertex(gid, view);
if (maybe_vertex) return VertexAccessor(*maybe_vertex); if (maybe_vertex) return std::make_unique<VertexAccessor>(std::move(maybe_vertex));
return std::nullopt; return {};
} }
void FinalizeTransaction() { accessor_->FinalizeTransaction(); } void FinalizeTransaction() { accessor_->FinalizeTransaction(); }
@ -347,27 +354,27 @@ class DbAccessor final {
return VerticesIterable(accessor_->Vertices(label, property, lower, upper, view)); return VerticesIterable(accessor_->Vertices(label, property, lower, upper, view));
} }
VertexAccessor InsertVertex() { return VertexAccessor(accessor_->CreateVertex()); } std::unique_ptr<VertexAccessor> InsertVertex() { return std::make_unique<VertexAccessor>(accessor_->CreateVertex()); }
storage::Result<EdgeAccessor> InsertEdge(VertexAccessor *from, VertexAccessor *to, storage::Result<std::unique_ptr<EdgeAccessor>> InsertEdge(VertexAccessor *from, VertexAccessor *to,
const storage::EdgeTypeId &edge_type) { const storage::EdgeTypeId &edge_type) {
auto maybe_edge = accessor_->CreateEdge(&from->impl_, &to->impl_, edge_type); auto maybe_edge = accessor_->CreateEdge(from->impl_, to->impl_, edge_type);
if (maybe_edge.HasError()) return storage::Result<EdgeAccessor>(maybe_edge.GetError()); if (maybe_edge.HasError()) return storage::Result<EdgeAccessor>(maybe_edge.GetError());
return EdgeAccessor(*maybe_edge); return std::make_unique<EdgeAccessor>(std::move(maybe_edge));
} }
storage::Result<std::unique_ptr<EdgeAccessor>> RemoveEdge(EdgeAccessor *edge) { storage::Result<std::unique_ptr<EdgeAccessor>> RemoveEdge(EdgeAccessor *edge) {
auto res = accessor_->DeleteEdge(&edge->impl_); auto res = accessor_->DeleteEdge(edge->impl_);
if (res.HasError()) { if (res.HasError()) {
return res.GetError(); return res.GetError();
} }
const auto &value = res.GetValue(); const auto &value = res.GetValue();
if (!value) { if (!value) {
return std::optional<EdgeAccessor>{}; return storage::Result<std::unique_ptr<EdgeAccessor>>{std::unique_ptr<EdgeAccessor>()};
} }
return std::make_optional<EdgeAccessor>(*value); return std::make_unique<EdgeAccessor>(std::move(value));
} }
storage::Result<std::optional<std::pair<VertexAccessor, std::vector<EdgeAccessor>>>> DetachRemoveVertex( storage::Result<std::optional<std::pair<VertexAccessor, std::vector<EdgeAccessor>>>> DetachRemoveVertex(

View File

@ -309,7 +309,7 @@ std::unique_ptr<VertexAccessor> InMemoryStorage::InMemoryAccessor::CreateVertex(
std::unique_ptr<VertexAccessor> InMemoryStorage::InMemoryAccessor::FindVertex(storage::Gid gid, View view) { std::unique_ptr<VertexAccessor> InMemoryStorage::InMemoryAccessor::FindVertex(storage::Gid gid, View view) {
auto acc = storage_->vertices_.access(); auto acc = storage_->vertices_.access();
auto it = acc.find(gid); auto it = acc.find(gid);
if (it == acc.end()) return std::unique_ptr<VertexAccessor>(); if (it == acc.end()) return {};
return VertexAccessor::Create(&*it, &transaction_, &storage_->indices_, &storage_->constraints_, config_, view); return VertexAccessor::Create(&*it, &transaction_, &storage_->indices_, &storage_->constraints_, config_, view);
} }

View File

@ -79,7 +79,7 @@ class InMemoryStorage final {
~InMemoryStorage(); ~InMemoryStorage();
class InMemoryAccessor final : public Accessor { class InMemoryAccessor final : public Storage::Accessor {
private: private:
friend class InMemoryStorage; friend class InMemoryStorage;

View File

@ -149,7 +149,9 @@ struct ConstraintsInfo {
std::vector<std::pair<LabelId, std::set<PropertyId>>> unique; std::vector<std::pair<LabelId, std::set<PropertyId>>> unique;
}; };
class Accessor { class Storage {
public:
class Accessor {
public: public:
Accessor() {} Accessor() {}
Accessor(const Accessor &) = delete; Accessor(const Accessor &) = delete;
@ -220,7 +222,8 @@ class Accessor {
/// @return Accessor to the deleted vertex and deleted edges if a deletion took place, std::nullopt otherwise /// @return Accessor to the deleted vertex and deleted edges if a deletion took place, std::nullopt otherwise
/// @throw std::bad_alloc /// @throw std::bad_alloc
virtual Result<std::optional<std::pair<std::unique_ptr<VertexAccessor>, std::vector<std::unique_ptr<EdgeAccessor>>>>> virtual Result<
std::optional<std::pair<std::unique_ptr<VertexAccessor>, std::vector<std::unique_ptr<EdgeAccessor>>>>>
DetachDeleteVertex(VertexAccessor *vertex) = 0; DetachDeleteVertex(VertexAccessor *vertex) = 0;
/// @throw std::bad_alloc /// @throw std::bad_alloc
@ -269,6 +272,7 @@ class Accessor {
virtual void FinalizeTransaction() = 0; virtual void FinalizeTransaction() = 0;
virtual std::optional<uint64_t> GetTransactionId() const = 0; virtual std::optional<uint64_t> GetTransactionId() const = 0;
};
}; };
} // namespace memgraph::storage } // namespace memgraph::storage

View File

@ -21,9 +21,20 @@ std::unique_ptr<VertexAccessor> VertexAccessor::Create(Vertex *vertex, Transacti
return InMemoryVertexAccessor::Create(vertex, transaction, indices, constraints, config, view); return InMemoryVertexAccessor::Create(vertex, transaction, indices, constraints, config, view);
} }
Result<std::vector<std::unique_ptr<EdgeAccessor>>> VertexAccessor::InEdges(
View view, const std::vector<EdgeTypeId> &edge_types) const {
return InEdges(view, edge_types, nullptr);
}
Result<std::vector<std::unique_ptr<EdgeAccessor>>> VertexAccessor::InEdges(View view) const { Result<std::vector<std::unique_ptr<EdgeAccessor>>> VertexAccessor::InEdges(View view) const {
return InEdges(view, {}, nullptr); return InEdges(view, {}, nullptr);
} }
Result<std::vector<std::unique_ptr<EdgeAccessor>>> VertexAccessor::OutEdges(
View view, const std::vector<EdgeTypeId> &edge_types) const {
return OutEdges(view, edge_types, nullptr);
}
Result<std::vector<std::unique_ptr<EdgeAccessor>>> VertexAccessor::OutEdges(View view) const { Result<std::vector<std::unique_ptr<EdgeAccessor>>> VertexAccessor::OutEdges(View view) const {
return OutEdges(view, {}, nullptr); return OutEdges(view, {}, nullptr);
} }

View File

@ -85,6 +85,9 @@ class VertexAccessor {
const std::vector<EdgeTypeId> &edge_types, const std::vector<EdgeTypeId> &edge_types,
const VertexAccessor *destination) const = 0; const VertexAccessor *destination) const = 0;
Result<std::vector<std::unique_ptr<EdgeAccessor>>> InEdges(View view,
const std::vector<EdgeTypeId> &edge_types) const;
Result<std::vector<std::unique_ptr<EdgeAccessor>>> InEdges(View view) const; Result<std::vector<std::unique_ptr<EdgeAccessor>>> InEdges(View view) const;
/// @throw std::bad_alloc /// @throw std::bad_alloc
@ -94,6 +97,8 @@ class VertexAccessor {
const std::vector<EdgeTypeId> &edge_types, const std::vector<EdgeTypeId> &edge_types,
const VertexAccessor *destination) const = 0; const VertexAccessor *destination) const = 0;
Result<std::vector<std::unique_ptr<EdgeAccessor>>> OutEdges(View view,
const std::vector<EdgeTypeId> &edge_types) const;
Result<std::vector<std::unique_ptr<EdgeAccessor>>> OutEdges(View view) const; Result<std::vector<std::unique_ptr<EdgeAccessor>>> OutEdges(View view) const;
virtual Result<size_t> InDegree(View view) const = 0; virtual Result<size_t> InDegree(View view) const = 0;