Extract vertex creation from FillUpSourceVertexSecondaryLabels

This commit is contained in:
jbajic 2022-11-07 10:54:28 +01:00
parent 4d2036249e
commit 88487e2513

View File

@ -12,11 +12,13 @@
#include <algorithm>
#include <functional>
#include <iterator>
#include <optional>
#include <unordered_set>
#include <utility>
#include "parser/opencypher/parser.hpp"
#include "query/v2/requests.hpp"
#include "storage/v2/vertex.hpp"
#include "storage/v2/view.hpp"
#include "storage/v3/bindings/ast/ast.hpp"
#include "storage/v3/bindings/cypher_main_visitor.hpp"
@ -180,7 +182,7 @@ std::vector<TypedValue> EvaluateVertexExpressions(DbAccessor &dba, const VertexA
struct LocalError {};
std::optional<msgs::Vertex> FillUpSourceVertexSecondaryLabels(const std::optional<VertexAccessor> &v_acc,
std::optional<std::vector<msgs::Label>> FillUpSourceVertexSecondaryLabels(const std::optional<VertexAccessor> &v_acc,
const msgs::ExpandOneRequest &req) {
auto secondary_labels = v_acc->Labels(View::NEW);
if (secondary_labels.HasError()) {
@ -190,13 +192,13 @@ std::optional<msgs::Vertex> FillUpSourceVertexSecondaryLabels(const std::optiona
}
auto &sec_labels = secondary_labels.GetValue();
msgs::Vertex source_vertex;
source_vertex.labels.reserve(sec_labels.size());
std::vector<msgs::Label> msgs_secondary_labels;
msgs_secondary_labels.reserve(sec_labels.size());
std::transform(sec_labels.begin(), sec_labels.end(), std::back_inserter(source_vertex.labels),
std::transform(sec_labels.begin(), sec_labels.end(), std::back_inserter(msgs_secondary_labels),
[](auto label_id) { return msgs::Label{.id = label_id}; });
return source_vertex;
return msgs_secondary_labels;
}
std::optional<std::map<PropertyId, Value>> FillUpSourceVertexProperties(const std::optional<VertexAccessor> &v_acc,
@ -324,11 +326,13 @@ std::optional<msgs::ExpandOneResultRow> GetExpandOneResult(
const auto primary_key = ConvertPropertyVector(src_vertex.second);
auto v_acc = acc.FindVertex(primary_key, View::NEW);
auto source_vertex = FillUpSourceVertexSecondaryLabels(v_acc, req);
if (!source_vertex) {
msgs::Vertex source_vertex = {.id = src_vertex};
if (const auto maybe_secondary_labels = FillUpSourceVertexSecondaryLabels(v_acc, req); maybe_secondary_labels) {
source_vertex.labels = *maybe_secondary_labels;
} else {
return std::nullopt;
}
source_vertex->id = src_vertex;
std::optional<std::map<PropertyId, Value>> src_vertex_properties;
src_vertex_properties = FillUpSourceVertexProperties(v_acc, req, storage::v3::View::NEW, schema);
@ -345,7 +349,7 @@ std::optional<msgs::ExpandOneResultRow> GetExpandOneResult(
auto [in_edges, out_edges] = fill_up_connecting_edges.value();
msgs::ExpandOneResultRow result_row;
result_row.src_vertex = std::move(*source_vertex);
result_row.src_vertex = std::move(source_vertex);
result_row.src_vertex_properties = std::move(*src_vertex_properties);
static constexpr bool kInEdges = true;
static constexpr bool kOutEdges = false;