add buildable graph impl

This commit is contained in:
antoniofilipovic 2022-07-21 11:37:04 +02:00
parent 12979c3048
commit e70e445899
4 changed files with 21 additions and 5 deletions

View File

@ -15,6 +15,7 @@
#include <utility>
#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(); }

View File

@ -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:

View File

@ -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");
}

View File

@ -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