From e70e4458994675b3d3fd4280ed195cddfd40bb83 Mon Sep 17 00:00:00 2001 From: antoniofilipovic Date: Thu, 21 Jul 2022 11:37:04 +0200 Subject: [PATCH] add buildable graph impl --- src/query/graph.hpp | 8 ++++++++ src/query/plan/operator.cpp | 4 ++-- src/query/typed_value.cpp | 8 +++++--- src/query/typed_value.hpp | 6 ++++++ 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/query/graph.hpp b/src/query/graph.hpp index 8944f97d5..65896ae2b 100644 --- a/src/query/graph.hpp +++ b/src/query/graph.hpp @@ -15,6 +15,7 @@ #include #include "query/db_accessor.hpp" +#include "query/path.hpp" #include "utils/logging.hpp" #include "utils/memory.hpp" #include "utils/pmr/vector.hpp" @@ -43,6 +44,13 @@ class Graph { explicit Graph(const VertexAccessor &vertex, utils::MemoryResource *memory = utils::NewDeleteResource()) : vertices_(memory), edges_(memory) {} + /** Expands the graph with the given path. */ + void Expand(const Path &path) { + const auto path_vertices_ = path.vertices(); + std::for_each(path_vertices_.begin(), path_vertices_.end(), + [this](const VertexAccessor v) { vertices_.push_back(v); }); + } + /** Returns the number of expansions (edges) in this path. */ auto size() const { return edges_.size(); } diff --git a/src/query/plan/operator.cpp b/src/query/plan/operator.cpp index cd9de8318..0643ee0dc 100644 --- a/src/query/plan/operator.cpp +++ b/src/query/plan/operator.cpp @@ -2824,7 +2824,7 @@ class AggregateCursor : public Cursor { break; case Aggregation::Op::PROJECT: { EnsureOkForProject(input_value); - value_it->ValueMap().emplace("path", input_value); + value_it->ValueGraph().Expand(input_value.ValuePath()); break; } case Aggregation::Op::COLLECT_MAP: @@ -2877,7 +2877,7 @@ class AggregateCursor : public Cursor { break; case Aggregation::Op::PROJECT: { EnsureOkForProject(input_value); - value_it->ValueGraph().add("path", input_value); + value_it->ValueGraph().Expand(input_value.ValuePath()); break; } case Aggregation::Op::COLLECT_MAP: diff --git a/src/query/typed_value.cpp b/src/query/typed_value.cpp index 87695895f..a22fbd90a 100644 --- a/src/query/typed_value.cpp +++ b/src/query/typed_value.cpp @@ -604,7 +604,7 @@ TypedValue &TypedValue::operator=(TypedValue &&other) noexcept(false) { case Type::Duration: new (&duration_v) utils::Duration(other.duration_v); break; - case TypedValue::Graph: + case Type::Graph: throw TypedValueException("A"); } other.DestroyValue(); @@ -646,6 +646,8 @@ void TypedValue::DestroyValue() { case Type::LocalDateTime: case Type::Duration: break; + case Type::Graph: + throw TypedValueException("A"); } type_ = TypedValue::Type::Null; @@ -1115,8 +1117,8 @@ size_t TypedValue::Hash::operator()(const TypedValue &value) const { case TypedValue::Type::Duration: return utils::DurationHash{}(value.ValueDuration()); break; - case TypedValue::Type::Duration: - throw TypedValueException("a";) + case TypedValue::Type::Graph: + throw TypedValueException("a"); } LOG_FATAL("Unhandled TypedValue.type() in hash function"); } diff --git a/src/query/typed_value.hpp b/src/query/typed_value.hpp index 472a8a1bd..838b6fe89 100644 --- a/src/query/typed_value.hpp +++ b/src/query/typed_value.hpp @@ -173,6 +173,11 @@ class TypedValue { duration_v = value; } + explicit TypedValue(const query::Graph &value, utils::MemoryResource *memory = utils::NewDeleteResource()) + : memory_(memory), type_(Type::Graph) { + graph_v = value; + } + // conversion function to storage::PropertyValue explicit operator storage::PropertyValue() const; @@ -488,6 +493,7 @@ class TypedValue { DECLARE_VALUE_AND_TYPE_GETTERS(utils::LocalTime, LocalTime) DECLARE_VALUE_AND_TYPE_GETTERS(utils::LocalDateTime, LocalDateTime) DECLARE_VALUE_AND_TYPE_GETTERS(utils::Duration, Duration) + DECLARE_VALUE_AND_TYPE_GETTERS(Graph, Graph) #undef DECLARE_VALUE_AND_TYPE_GETTERS