Make the database dumper use only Vertices
Reviewers: teon.banek Reviewed By: teon.banek Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D2539
This commit is contained in:
parent
cdb9c08047
commit
e350e2b7a4
@ -199,7 +199,7 @@ CypherDumpGenerator::CypherDumpGenerator(query::DbAccessor *dba)
|
|||||||
unique_constraints_state_.emplace(dba->ListUniqueConstraints());
|
unique_constraints_state_.emplace(dba->ListUniqueConstraints());
|
||||||
#endif
|
#endif
|
||||||
vertices_state_.emplace(dba->Vertices(storage::View::OLD));
|
vertices_state_.emplace(dba->Vertices(storage::View::OLD));
|
||||||
edges_state_.emplace(dba->Edges(storage::View::OLD));
|
edges_state_.emplace(dba->Vertices(storage::View::OLD));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CypherDumpGenerator::NextQuery(std::ostream *os) {
|
bool CypherDumpGenerator::NextQuery(std::ostream *os) {
|
||||||
@ -225,7 +225,7 @@ bool CypherDumpGenerator::NextQuery(std::ostream *os) {
|
|||||||
DumpVertex(os, dba_, *vertices_state_->GetCurrentAndAdvance());
|
DumpVertex(os, dba_, *vertices_state_->GetCurrentAndAdvance());
|
||||||
return true;
|
return true;
|
||||||
} else if (!edges_state_->ReachedEnd()) {
|
} else if (!edges_state_->ReachedEnd()) {
|
||||||
DumpEdge(os, dba_, *edges_state_->GetCurrentAndAdvance());
|
DumpEdge(os, dba_, edges_state_->GetCurrentAndAdvance());
|
||||||
return true;
|
return true;
|
||||||
} else if (!vertices_state_->Empty() && !cleaned_internal_index_) {
|
} else if (!vertices_state_->Empty() && !cleaned_internal_index_) {
|
||||||
*os << "DROP INDEX ON :" << kInternalVertexLabel << "("
|
*os << "DROP INDEX ON :" << kInternalVertexLabel << "("
|
||||||
@ -242,4 +242,29 @@ bool CypherDumpGenerator::NextQuery(std::ostream *os) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CypherDumpGenerator::EdgesState::FindNext() {
|
||||||
|
current_edge_ = std::nullopt;
|
||||||
|
if (edges_list_state_ && !edges_list_state_->ReachedEnd()) {
|
||||||
|
current_edge_ = *edges_list_state_->GetCurrentAndAdvance();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
while (!vertices_state_->ReachedEnd()) {
|
||||||
|
auto vertex = *vertices_state_->GetCurrentAndAdvance();
|
||||||
|
auto maybe_edges = vertex.OutEdges(storage::View::OLD);
|
||||||
|
CHECK(maybe_edges.HasValue()) << "Invalid database state!";
|
||||||
|
auto &edges = maybe_edges.GetValue();
|
||||||
|
// We convert the itertools object to a list of edge accessors here because
|
||||||
|
// itertools have suspicious object lifetime handling.
|
||||||
|
std::vector<query::EdgeAccessor> edges_list;
|
||||||
|
for (auto edge : edges) {
|
||||||
|
edges_list.push_back(edge);
|
||||||
|
}
|
||||||
|
if (!edges_list.empty()) {
|
||||||
|
edges_list_state_.emplace(std::move(edges_list));
|
||||||
|
current_edge_ = *edges_list_state_->GetCurrentAndAdvance();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace database
|
} // namespace database
|
||||||
|
@ -54,7 +54,7 @@ class CypherDumpGenerator {
|
|||||||
|
|
||||||
bool ReachedEnd() const { return current_ == end_; }
|
bool ReachedEnd() const { return current_ == end_; }
|
||||||
|
|
||||||
// Returns true iff the container is empty.
|
// Returns true if the container is empty.
|
||||||
bool Empty() const { return empty_; }
|
bool Empty() const { return empty_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -67,6 +67,44 @@ class CypherDumpGenerator {
|
|||||||
bool empty_;
|
bool empty_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class EdgesState {
|
||||||
|
private:
|
||||||
|
using TVertices = decltype(std::declval<query::DbAccessor>().Vertices(
|
||||||
|
std::declval<storage::View>()));
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit EdgesState(TVertices vertices)
|
||||||
|
: vertices_state_(std::move(vertices)) {
|
||||||
|
FindNext();
|
||||||
|
}
|
||||||
|
|
||||||
|
EdgesState(const EdgesState &other) = delete;
|
||||||
|
// NOLINTNEXTLINE(hicpp-noexcept-move,performance-noexcept-move-constructor)
|
||||||
|
EdgesState(EdgesState &&other) = default;
|
||||||
|
EdgesState &operator=(const EdgesState &other) = delete;
|
||||||
|
EdgesState &operator=(EdgesState &&other) = delete;
|
||||||
|
~EdgesState() = default;
|
||||||
|
|
||||||
|
auto GetCurrentAndAdvance() {
|
||||||
|
auto edge = *current_edge_;
|
||||||
|
FindNext();
|
||||||
|
return edge;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ReachedEnd() const { return !current_edge_; }
|
||||||
|
|
||||||
|
// Returns true if the container is empty.
|
||||||
|
bool Empty() const { return !current_edge_; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
void FindNext();
|
||||||
|
|
||||||
|
std::optional<ContainerState<TVertices>> vertices_state_;
|
||||||
|
std::optional<ContainerState<std::vector<query::EdgeAccessor>>>
|
||||||
|
edges_list_state_;
|
||||||
|
std::optional<query::EdgeAccessor> current_edge_;
|
||||||
|
};
|
||||||
|
|
||||||
query::DbAccessor *dba_;
|
query::DbAccessor *dba_;
|
||||||
|
|
||||||
bool created_internal_index_;
|
bool created_internal_index_;
|
||||||
@ -82,8 +120,7 @@ class CypherDumpGenerator {
|
|||||||
#endif
|
#endif
|
||||||
std::optional<ContainerState<decltype(dba_->Vertices(storage::View::OLD))>>
|
std::optional<ContainerState<decltype(dba_->Vertices(storage::View::OLD))>>
|
||||||
vertices_state_;
|
vertices_state_;
|
||||||
std::optional<ContainerState<decltype(dba_->Edges(storage::View::OLD))>>
|
std::optional<EdgesState> edges_state_;
|
||||||
edges_state_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace database
|
} // namespace database
|
||||||
|
@ -522,27 +522,6 @@ class DbAccessor final {
|
|||||||
Iterator end() { return Iterator(iterable_.end()); }
|
Iterator end() { return Iterator(iterable_.end()); }
|
||||||
};
|
};
|
||||||
|
|
||||||
class EdgesIterable final {
|
|
||||||
public:
|
|
||||||
class Iterator final {
|
|
||||||
public:
|
|
||||||
EdgeAccessor operator*() const {
|
|
||||||
throw utils::NotYetImplemented("operator*");
|
|
||||||
}
|
|
||||||
|
|
||||||
Iterator &operator++() { throw utils::NotYetImplemented("operator++"); }
|
|
||||||
|
|
||||||
bool operator==(const Iterator &other) const {
|
|
||||||
throw utils::NotYetImplemented("operator==");
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator!=(const Iterator &other) const { return !(other == *this); }
|
|
||||||
};
|
|
||||||
|
|
||||||
Iterator begin() { throw utils::NotYetImplemented("begin"); }
|
|
||||||
Iterator end() { throw utils::NotYetImplemented("end"); }
|
|
||||||
};
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit DbAccessor(storage::Storage::Accessor *accessor)
|
explicit DbAccessor(storage::Storage::Accessor *accessor)
|
||||||
: accessor_(accessor) {}
|
: accessor_(accessor) {}
|
||||||
@ -569,10 +548,6 @@ class DbAccessor final {
|
|||||||
accessor_->Vertices(label, property, lower, upper, view));
|
accessor_->Vertices(label, property, lower, upper, view));
|
||||||
}
|
}
|
||||||
|
|
||||||
EdgesIterable Edges(storage::View view) {
|
|
||||||
throw utils::NotYetImplemented("Edges");
|
|
||||||
}
|
|
||||||
|
|
||||||
VertexAccessor InsertVertex() {
|
VertexAccessor InsertVertex() {
|
||||||
return VertexAccessor(accessor_->CreateVertex());
|
return VertexAccessor(accessor_->CreateVertex());
|
||||||
}
|
}
|
||||||
@ -785,12 +760,6 @@ class DbAccessor final {
|
|||||||
return VerticesIterable<decltype(vertices)>(std::move(vertices));
|
return VerticesIterable<decltype(vertices)>(std::move(vertices));
|
||||||
}
|
}
|
||||||
|
|
||||||
auto Edges(storage::View view) {
|
|
||||||
// TODO: Exceptions?
|
|
||||||
return iter::imap([](const auto &e) { return EdgeAccessor(e); },
|
|
||||||
dba_->Edges(view == storage::View::NEW));
|
|
||||||
}
|
|
||||||
|
|
||||||
storage::Property NameToProperty(const std::string_view &name) {
|
storage::Property NameToProperty(const std::string_view &name) {
|
||||||
return dba_->Property(std::string(name));
|
return dba_->Property(std::string(name));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user