Remove old storage types

Reviewers: teon.banek

Reviewed By: teon.banek

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D2633
This commit is contained in:
Matej Ferencevic 2020-01-22 16:20:13 +01:00
parent 1a50165c22
commit 98dc7e2849
49 changed files with 813 additions and 715 deletions

View File

@ -10,32 +10,32 @@
namespace audit { namespace audit {
// Helper function that converts a `PropertyValue` to `nlohmann::json`. // Helper function that converts a `storage::PropertyValue` to `nlohmann::json`.
inline nlohmann::json PropertyValueToJson(const PropertyValue &pv) { inline nlohmann::json PropertyValueToJson(const storage::PropertyValue &pv) {
nlohmann::json ret; nlohmann::json ret;
switch (pv.type()) { switch (pv.type()) {
case PropertyValue::Type::Null: case storage::PropertyValue::Type::Null:
break; break;
case PropertyValue::Type::Bool: case storage::PropertyValue::Type::Bool:
ret = pv.ValueBool(); ret = pv.ValueBool();
break; break;
case PropertyValue::Type::Int: case storage::PropertyValue::Type::Int:
ret = pv.ValueInt(); ret = pv.ValueInt();
break; break;
case PropertyValue::Type::Double: case storage::PropertyValue::Type::Double:
ret = pv.ValueDouble(); ret = pv.ValueDouble();
break; break;
case PropertyValue::Type::String: case storage::PropertyValue::Type::String:
ret = pv.ValueString(); ret = pv.ValueString();
break; break;
case PropertyValue::Type::List: { case storage::PropertyValue::Type::List: {
ret = nlohmann::json::array(); ret = nlohmann::json::array();
for (const auto &item : pv.ValueList()) { for (const auto &item : pv.ValueList()) {
ret.push_back(PropertyValueToJson(item)); ret.push_back(PropertyValueToJson(item));
} }
break; break;
} }
case PropertyValue::Type::Map: { case storage::PropertyValue::Type::Map: {
ret = nlohmann::json::object(); ret = nlohmann::json::object();
for (const auto &item : pv.ValueMap()) { for (const auto &item : pv.ValueMap()) {
ret.push_back(nlohmann::json::object_t::value_type( ret.push_back(nlohmann::json::object_t::value_type(
@ -79,7 +79,8 @@ Log::~Log() {
} }
void Log::Record(const std::string &address, const std::string &username, void Log::Record(const std::string &address, const std::string &username,
const std::string &query, const PropertyValue &params) { const std::string &query,
const storage::PropertyValue &params) {
if (!started_.load(std::memory_order_relaxed)) return; if (!started_.load(std::memory_order_relaxed)) return;
auto timestamp = std::chrono::duration_cast<std::chrono::microseconds>( auto timestamp = std::chrono::duration_cast<std::chrono::microseconds>(
std::chrono::system_clock::now().time_since_epoch()) std::chrono::system_clock::now().time_since_epoch())

View File

@ -5,7 +5,7 @@
#include <optional> #include <optional>
#include "data_structures/ring_buffer.hpp" #include "data_structures/ring_buffer.hpp"
#include "storage/common/types/property_value.hpp" #include "storage/v2/property_value.hpp"
#include "utils/file.hpp" #include "utils/file.hpp"
#include "utils/scheduler.hpp" #include "utils/scheduler.hpp"
@ -23,7 +23,7 @@ class Log {
std::string address; std::string address;
std::string username; std::string username;
std::string query; std::string query;
PropertyValue params; storage::PropertyValue params;
}; };
public: public:
@ -44,7 +44,7 @@ class Log {
/// Adds an entry to the audit log. Thread-safe. /// Adds an entry to the audit log. Thread-safe.
void Record(const std::string &address, const std::string &username, void Record(const std::string &address, const std::string &username,
const std::string &query, const PropertyValue &params); const std::string &query, const storage::PropertyValue &params);
/// Reopens the log file. Used for log file rotation. Thread-safe. /// Reopens the log file. Used for log file rotation. Thread-safe.
void ReopenLog(); void ReopenLog();

View File

@ -271,30 +271,30 @@ communication::bolt::Path ToBoltPath(const query::Path &path,
return communication::bolt::Path(vertices, edges); return communication::bolt::Path(vertices, edges);
} }
PropertyValue ToPropertyValue(const Value &value) { storage::PropertyValue ToPropertyValue(const Value &value) {
switch (value.type()) { switch (value.type()) {
case Value::Type::Null: case Value::Type::Null:
return PropertyValue(); return storage::PropertyValue();
case Value::Type::Bool: case Value::Type::Bool:
return PropertyValue(value.ValueBool()); return storage::PropertyValue(value.ValueBool());
case Value::Type::Int: case Value::Type::Int:
return PropertyValue(value.ValueInt()); return storage::PropertyValue(value.ValueInt());
case Value::Type::Double: case Value::Type::Double:
return PropertyValue(value.ValueDouble()); return storage::PropertyValue(value.ValueDouble());
case Value::Type::String: case Value::Type::String:
return PropertyValue(value.ValueString()); return storage::PropertyValue(value.ValueString());
case Value::Type::List: { case Value::Type::List: {
std::vector<PropertyValue> vec; std::vector<storage::PropertyValue> vec;
vec.reserve(value.ValueList().size()); vec.reserve(value.ValueList().size());
for (const auto &value : value.ValueList()) for (const auto &value : value.ValueList())
vec.emplace_back(ToPropertyValue(value)); vec.emplace_back(ToPropertyValue(value));
return PropertyValue(std::move(vec)); return storage::PropertyValue(std::move(vec));
} }
case Value::Type::Map: { case Value::Type::Map: {
std::map<std::string, PropertyValue> map; std::map<std::string, storage::PropertyValue> map;
for (const auto &kv : value.ValueMap()) for (const auto &kv : value.ValueMap())
map.emplace(kv.first, ToPropertyValue(kv.second)); map.emplace(kv.first, ToPropertyValue(kv.second));
return PropertyValue(std::move(map)); return storage::PropertyValue(std::move(map));
} }
case Value::Type::Vertex: case Value::Type::Vertex:
case Value::Type::Edge: case Value::Type::Edge:
@ -305,20 +305,20 @@ PropertyValue ToPropertyValue(const Value &value) {
} }
} }
Value ToBoltValue(const PropertyValue &value) { Value ToBoltValue(const storage::PropertyValue &value) {
switch (value.type()) { switch (value.type()) {
case PropertyValue::Type::Null: case storage::PropertyValue::Type::Null:
return Value(); return Value();
case PropertyValue::Type::Bool: case storage::PropertyValue::Type::Bool:
return Value(value.ValueBool()); return Value(value.ValueBool());
case PropertyValue::Type::Int: case storage::PropertyValue::Type::Int:
return Value(value.ValueInt()); return Value(value.ValueInt());
break; break;
case PropertyValue::Type::Double: case storage::PropertyValue::Type::Double:
return Value(value.ValueDouble()); return Value(value.ValueDouble());
case PropertyValue::Type::String: case storage::PropertyValue::Type::String:
return Value(value.ValueString()); return Value(value.ValueString());
case PropertyValue::Type::List: { case storage::PropertyValue::Type::List: {
const auto &values = value.ValueList(); const auto &values = value.ValueList();
std::vector<Value> vec; std::vector<Value> vec;
vec.reserve(values.size()); vec.reserve(values.size());
@ -327,7 +327,7 @@ Value ToBoltValue(const PropertyValue &value) {
} }
return Value(std::move(vec)); return Value(std::move(vec));
} }
case PropertyValue::Type::Map: { case storage::PropertyValue::Type::Map: {
const auto &map = value.ValueMap(); const auto &map = value.ValueMap();
std::map<std::string, Value> dv_map; std::map<std::string, Value> dv_map;
for (const auto &kv : map) { for (const auto &kv : map) {

View File

@ -3,7 +3,7 @@
#include "communication/bolt/v1/value.hpp" #include "communication/bolt/v1/value.hpp"
#include "query/typed_value.hpp" #include "query/typed_value.hpp"
#include "storage/common/types/property_value.hpp" #include "storage/v2/property_value.hpp"
#include "storage/v2/view.hpp" #include "storage/v2/view.hpp"
#ifdef MG_SINGLE_NODE_V2 #ifdef MG_SINGLE_NODE_V2
@ -70,8 +70,8 @@ communication::bolt::Value ToBoltValue(const query::TypedValue &value,
query::TypedValue ToTypedValue(const communication::bolt::Value &value); query::TypedValue ToTypedValue(const communication::bolt::Value &value);
communication::bolt::Value ToBoltValue(const PropertyValue &value); communication::bolt::Value ToBoltValue(const storage::PropertyValue &value);
PropertyValue ToPropertyValue(const communication::bolt::Value &value); storage::PropertyValue ToPropertyValue(const communication::bolt::Value &value);
} // namespace glue } // namespace glue

View File

@ -50,12 +50,12 @@ using TEncoder =
std::vector<std::string> BoltSession::Interpret( std::vector<std::string> BoltSession::Interpret(
const std::string &query, const std::string &query,
const std::map<std::string, communication::bolt::Value> &params) { const std::map<std::string, communication::bolt::Value> &params) {
std::map<std::string, PropertyValue> params_pv; std::map<std::string, storage::PropertyValue> params_pv;
for (const auto &kv : params) for (const auto &kv : params)
params_pv.emplace(kv.first, glue::ToPropertyValue(kv.second)); params_pv.emplace(kv.first, glue::ToPropertyValue(kv.second));
#ifndef MG_SINGLE_NODE_HA #ifndef MG_SINGLE_NODE_HA
audit_log_->Record(endpoint_.address(), user_ ? user_->username() : "", query, audit_log_->Record(endpoint_.address(), user_ ? user_->username() : "", query,
PropertyValue(params_pv)); storage::PropertyValue(params_pv));
#endif #endif
try { try {
auto result = interpreter_.Prepare(query, params_pv); auto result = interpreter_.Prepare(query, params_pv);

View File

@ -11,7 +11,7 @@
#include "query/frontend/ast/ast.hpp" #include "query/frontend/ast/ast.hpp"
#include "query/frontend/semantic/symbol.hpp" #include "query/frontend/semantic/symbol.hpp"
#include "query/typed_value.hpp" #include "query/typed_value.hpp"
#include "storage/common/types/types.hpp" #include "storage/v2/id_types.hpp"
#include "storage/v2/view.hpp" #include "storage/v2/view.hpp"
namespace query { namespace query {
@ -73,10 +73,10 @@ inline void ExpectType(const Symbol &symbol, const TypedValue &value,
/// ///
/// @throw QueryRuntimeException if value cannot be set as a property value /// @throw QueryRuntimeException if value cannot be set as a property value
template <class TRecordAccessor> template <class TRecordAccessor>
void PropsSetChecked(TRecordAccessor *record, const storage::Property &key, void PropsSetChecked(TRecordAccessor *record, const storage::PropertyId &key,
const TypedValue &value) { const TypedValue &value) {
try { try {
auto maybe_error = record->SetProperty(key, PropertyValue(value)); auto maybe_error = record->SetProperty(key, storage::PropertyValue(value));
if (maybe_error.HasError()) { if (maybe_error.HasError()) {
switch (maybe_error.GetError()) { switch (maybe_error.GetError()) {
case storage::Error::SERIALIZATION_ERROR: case storage::Error::SERIALIZATION_ERROR:

View File

@ -18,17 +18,17 @@ struct EvaluationContext {
int64_t timestamp{-1}; int64_t timestamp{-1};
Parameters parameters; Parameters parameters;
/// All properties indexable via PropertyIx /// All properties indexable via PropertyIx
std::vector<storage::Property> properties; std::vector<storage::PropertyId> properties;
/// All labels indexable via LabelIx /// All labels indexable via LabelIx
std::vector<storage::Label> labels; std::vector<storage::LabelId> labels;
/// All counters generated by `counter` function, mutable because the function /// All counters generated by `counter` function, mutable because the function
/// modifies the values /// modifies the values
mutable std::unordered_map<std::string, int64_t> counters; mutable std::unordered_map<std::string, int64_t> counters;
}; };
inline std::vector<storage::Property> NamesToProperties( inline std::vector<storage::PropertyId> NamesToProperties(
const std::vector<std::string> &property_names, DbAccessor *dba) { const std::vector<std::string> &property_names, DbAccessor *dba) {
std::vector<storage::Property> properties; std::vector<storage::PropertyId> properties;
properties.reserve(property_names.size()); properties.reserve(property_names.size());
for (const auto &name : property_names) { for (const auto &name : property_names) {
properties.push_back(dba->NameToProperty(name)); properties.push_back(dba->NameToProperty(name));
@ -36,9 +36,9 @@ inline std::vector<storage::Property> NamesToProperties(
return properties; return properties;
} }
inline std::vector<storage::Label> NamesToLabels( inline std::vector<storage::LabelId> NamesToLabels(
const std::vector<std::string> &label_names, DbAccessor *dba) { const std::vector<std::string> &label_names, DbAccessor *dba) {
std::vector<storage::Label> labels; std::vector<storage::LabelId> labels;
labels.reserve(label_names.size()); labels.reserve(label_names.size());
for (const auto &name : label_names) { for (const auto &name : label_names) {
labels.push_back(dba->NameToLabel(name)); labels.push_back(dba->NameToLabel(name));

View File

@ -6,9 +6,9 @@
#include <cppitertools/imap.hpp> #include <cppitertools/imap.hpp>
#include "query/exceptions.hpp" #include "query/exceptions.hpp"
#include "storage/common/types/property_value.hpp"
#include "storage/common/types/types.hpp"
#include "storage/edge_accessor.hpp" #include "storage/edge_accessor.hpp"
#include "storage/v2/id_types.hpp"
#include "storage/v2/property_value.hpp"
#include "storage/v2/result.hpp" #include "storage/v2/result.hpp"
#include "storage/v2/view.hpp" #include "storage/v2/view.hpp"
#include "storage/vertex_accessor.hpp" #include "storage/vertex_accessor.hpp"
@ -33,22 +33,22 @@ class EdgeAccessor final {
public: public:
explicit EdgeAccessor(storage::EdgeAccessor impl) : impl_(std::move(impl)) {} explicit EdgeAccessor(storage::EdgeAccessor impl) : impl_(std::move(impl)) {}
storage::EdgeType EdgeType() const { return impl_.EdgeType(); } storage::EdgeTypeId EdgeType() const { return impl_.EdgeType(); }
auto Properties(storage::View view) const { return impl_.Properties(view); } auto Properties(storage::View view) const { return impl_.Properties(view); }
storage::Result<PropertyValue> GetProperty(storage::View view, storage::Result<storage::PropertyValue> GetProperty(storage::View view,
storage::Property key) const { storage::PropertyId key) const {
return impl_.GetProperty(key, view); return impl_.GetProperty(key, view);
} }
storage::Result<bool> SetProperty(storage::Property key, storage::Result<bool> SetProperty(storage::PropertyId key,
const PropertyValue &value) { const storage::PropertyValue &value) {
return impl_.SetProperty(key, value); return impl_.SetProperty(key, value);
} }
storage::Result<bool> RemoveProperty(storage::Property key) { storage::Result<bool> RemoveProperty(storage::PropertyId key) {
return SetProperty(key, PropertyValue()); return SetProperty(key, storage::PropertyValue());
} }
utils::BasicResult<storage::Error, void> ClearProperties() { utils::BasicResult<storage::Error, void> ClearProperties() {
@ -86,33 +86,33 @@ class VertexAccessor final {
auto Labels(storage::View view) const { return impl_.Labels(view); } auto Labels(storage::View view) const { return impl_.Labels(view); }
storage::Result<bool> AddLabel(storage::Label label) { storage::Result<bool> AddLabel(storage::LabelId label) {
return impl_.AddLabel(label); return impl_.AddLabel(label);
} }
storage::Result<bool> RemoveLabel(storage::Label label) { storage::Result<bool> RemoveLabel(storage::LabelId label) {
return impl_.RemoveLabel(label); return impl_.RemoveLabel(label);
} }
storage::Result<bool> HasLabel(storage::View view, storage::Result<bool> HasLabel(storage::View view,
storage::Label label) const { storage::LabelId label) const {
return impl_.HasLabel(label, view); return impl_.HasLabel(label, view);
} }
auto Properties(storage::View view) const { return impl_.Properties(view); } auto Properties(storage::View view) const { return impl_.Properties(view); }
storage::Result<PropertyValue> GetProperty(storage::View view, storage::Result<storage::PropertyValue> GetProperty(storage::View view,
storage::Property key) const { storage::PropertyId key) const {
return impl_.GetProperty(key, view); return impl_.GetProperty(key, view);
} }
storage::Result<bool> SetProperty(storage::Property key, storage::Result<bool> SetProperty(storage::PropertyId key,
const PropertyValue &value) { const storage::PropertyValue &value) {
return impl_.SetProperty(key, value); return impl_.SetProperty(key, value);
} }
storage::Result<bool> RemoveProperty(storage::Property key) { storage::Result<bool> RemoveProperty(storage::PropertyId key) {
return SetProperty(key, PropertyValue()); return SetProperty(key, storage::PropertyValue());
} }
utils::BasicResult<storage::Error, void> ClearProperties() { utils::BasicResult<storage::Error, void> ClearProperties() {
@ -122,7 +122,7 @@ class VertexAccessor final {
} }
auto InEdges(storage::View view, auto InEdges(storage::View view,
const std::vector<storage::EdgeType> &edge_types) const const std::vector<storage::EdgeTypeId> &edge_types) const
-> storage::Result<decltype(iter::imap(MakeEdgeAccessor, -> storage::Result<decltype(iter::imap(MakeEdgeAccessor,
*impl_.InEdges(view)))> { *impl_.InEdges(view)))> {
auto maybe_edges = impl_.InEdges(view, edge_types); auto maybe_edges = impl_.InEdges(view, edge_types);
@ -133,7 +133,7 @@ class VertexAccessor final {
auto InEdges(storage::View view) const { return InEdges(view, {}); } auto InEdges(storage::View view) const { return InEdges(view, {}); }
auto InEdges(storage::View view, auto InEdges(storage::View view,
const std::vector<storage::EdgeType> &edge_types, const std::vector<storage::EdgeTypeId> &edge_types,
const VertexAccessor &dest) const const VertexAccessor &dest) const
-> storage::Result<decltype(iter::imap(MakeEdgeAccessor, -> storage::Result<decltype(iter::imap(MakeEdgeAccessor,
*impl_.InEdges(view)))> { *impl_.InEdges(view)))> {
@ -143,7 +143,7 @@ class VertexAccessor final {
} }
auto OutEdges(storage::View view, auto OutEdges(storage::View view,
const std::vector<storage::EdgeType> &edge_types) const const std::vector<storage::EdgeTypeId> &edge_types) const
-> storage::Result<decltype(iter::imap(MakeEdgeAccessor, -> storage::Result<decltype(iter::imap(MakeEdgeAccessor,
*impl_.OutEdges(view)))> { *impl_.OutEdges(view)))> {
auto maybe_edges = impl_.OutEdges(view, edge_types); auto maybe_edges = impl_.OutEdges(view, edge_types);
@ -154,7 +154,7 @@ class VertexAccessor final {
auto OutEdges(storage::View view) const { return OutEdges(view, {}); } auto OutEdges(storage::View view) const { return OutEdges(view, {}); }
auto OutEdges(storage::View view, auto OutEdges(storage::View view,
const std::vector<storage::EdgeType> &edge_types, const std::vector<storage::EdgeTypeId> &edge_types,
const VertexAccessor &dest) const const VertexAccessor &dest) const
-> storage::Result<decltype(iter::imap(MakeEdgeAccessor, -> storage::Result<decltype(iter::imap(MakeEdgeAccessor,
*impl_.OutEdges(view)))> { *impl_.OutEdges(view)))> {
@ -525,20 +525,20 @@ class DbAccessor final {
return VerticesIterable(accessor_->Vertices(view)); return VerticesIterable(accessor_->Vertices(view));
} }
VerticesIterable Vertices(storage::View view, storage::Label label) { VerticesIterable Vertices(storage::View view, storage::LabelId label) {
return VerticesIterable(accessor_->Vertices(label, view)); return VerticesIterable(accessor_->Vertices(label, view));
} }
VerticesIterable Vertices(storage::View view, storage::Label label, VerticesIterable Vertices(storage::View view, storage::LabelId label,
storage::Property property, storage::PropertyId property,
const PropertyValue &value) { const storage::PropertyValue &value) {
return VerticesIterable(accessor_->Vertices(label, property, value, view)); return VerticesIterable(accessor_->Vertices(label, property, value, view));
} }
VerticesIterable Vertices( VerticesIterable Vertices(
storage::View view, storage::Label label, storage::Property property, storage::View view, storage::LabelId label, storage::PropertyId property,
const std::optional<utils::Bound<PropertyValue>> &lower, const std::optional<utils::Bound<storage::PropertyValue>> &lower,
const std::optional<utils::Bound<PropertyValue>> &upper) { const std::optional<utils::Bound<storage::PropertyValue>> &upper) {
return VerticesIterable( return VerticesIterable(
accessor_->Vertices(label, property, lower, upper, view)); accessor_->Vertices(label, property, lower, upper, view));
} }
@ -549,7 +549,7 @@ class DbAccessor final {
storage::Result<EdgeAccessor> InsertEdge(VertexAccessor *from, storage::Result<EdgeAccessor> InsertEdge(VertexAccessor *from,
VertexAccessor *to, VertexAccessor *to,
const storage::EdgeType &edge_type) { const storage::EdgeTypeId &edge_type) {
auto maybe_edge = auto maybe_edge =
accessor_->CreateEdge(&from->impl_, &to->impl_, edge_type); accessor_->CreateEdge(&from->impl_, &to->impl_, edge_type);
if (maybe_edge.HasError()) if (maybe_edge.HasError())
@ -569,29 +569,29 @@ class DbAccessor final {
return accessor_->DeleteVertex(&vertex_accessor->impl_); return accessor_->DeleteVertex(&vertex_accessor->impl_);
} }
storage::Property NameToProperty(const std::string_view &name) { storage::PropertyId NameToProperty(const std::string_view &name) {
// TODO: New storage should work with string_view to avoid needless // TODO: New storage should work with string_view to avoid needless
// allocation. // allocation.
return accessor_->NameToProperty(std::string(name)); return accessor_->NameToProperty(std::string(name));
} }
storage::Label NameToLabel(const std::string_view &name) { storage::LabelId NameToLabel(const std::string_view &name) {
return accessor_->NameToLabel(std::string(name)); return accessor_->NameToLabel(std::string(name));
} }
storage::EdgeType NameToEdgeType(const std::string_view &name) { storage::EdgeTypeId NameToEdgeType(const std::string_view &name) {
return accessor_->NameToEdgeType(std::string(name)); return accessor_->NameToEdgeType(std::string(name));
} }
const std::string &PropertyToName(storage::Property prop) const { const std::string &PropertyToName(storage::PropertyId prop) const {
return accessor_->PropertyToName(prop); return accessor_->PropertyToName(prop);
} }
const std::string &LabelToName(storage::Label label) const { const std::string &LabelToName(storage::LabelId label) const {
return accessor_->LabelToName(label); return accessor_->LabelToName(label);
} }
const std::string &EdgeTypeToName(storage::EdgeType type) const { const std::string &EdgeTypeToName(storage::EdgeTypeId type) const {
return accessor_->EdgeTypeToName(type); return accessor_->EdgeTypeToName(type);
} }
@ -603,35 +603,35 @@ class DbAccessor final {
void Abort() { accessor_->Abort(); } void Abort() { accessor_->Abort(); }
bool LabelIndexExists(storage::Label label) const { bool LabelIndexExists(storage::LabelId label) const {
return accessor_->LabelIndexExists(label); return accessor_->LabelIndexExists(label);
} }
bool LabelPropertyIndexExists(storage::Label label, bool LabelPropertyIndexExists(storage::LabelId label,
storage::Property prop) const { storage::PropertyId prop) const {
return accessor_->LabelPropertyIndexExists(label, prop); return accessor_->LabelPropertyIndexExists(label, prop);
} }
int64_t VerticesCount() const { return accessor_->ApproximateVertexCount(); } int64_t VerticesCount() const { return accessor_->ApproximateVertexCount(); }
int64_t VerticesCount(storage::Label label) const { int64_t VerticesCount(storage::LabelId label) const {
return accessor_->ApproximateVertexCount(label); return accessor_->ApproximateVertexCount(label);
} }
int64_t VerticesCount(storage::Label label, int64_t VerticesCount(storage::LabelId label,
storage::Property property) const { storage::PropertyId property) const {
return accessor_->ApproximateVertexCount(label, property); return accessor_->ApproximateVertexCount(label, property);
} }
int64_t VerticesCount(storage::Label label, storage::Property property, int64_t VerticesCount(storage::LabelId label, storage::PropertyId property,
const PropertyValue &value) const { const storage::PropertyValue &value) const {
return accessor_->ApproximateVertexCount(label, property, value); return accessor_->ApproximateVertexCount(label, property, value);
} }
int64_t VerticesCount( int64_t VerticesCount(
storage::Label label, storage::Property property, storage::LabelId label, storage::PropertyId property,
const std::optional<utils::Bound<PropertyValue>> &lower, const std::optional<utils::Bound<storage::PropertyValue>> &lower,
const std::optional<utils::Bound<PropertyValue>> &upper) const { const std::optional<utils::Bound<storage::PropertyValue>> &upper) const {
return accessor_->ApproximateVertexCount(label, property, lower, upper); return accessor_->ApproximateVertexCount(label, property, lower, upper);
} }

View File

@ -36,24 +36,24 @@ void DumpPreciseDouble(std::ostream *os, double value) {
*os << temp_oss.str(); *os << temp_oss.str();
} }
void DumpPropertyValue(std::ostream *os, const PropertyValue &value) { void DumpPropertyValue(std::ostream *os, const storage::PropertyValue &value) {
switch (value.type()) { switch (value.type()) {
case PropertyValue::Type::Null: case storage::PropertyValue::Type::Null:
*os << "Null"; *os << "Null";
return; return;
case PropertyValue::Type::Bool: case storage::PropertyValue::Type::Bool:
*os << (value.ValueBool() ? "true" : "false"); *os << (value.ValueBool() ? "true" : "false");
return; return;
case PropertyValue::Type::String: case storage::PropertyValue::Type::String:
*os << ::utils::Escape(value.ValueString()); *os << ::utils::Escape(value.ValueString());
return; return;
case PropertyValue::Type::Int: case storage::PropertyValue::Type::Int:
*os << value.ValueInt(); *os << value.ValueInt();
return; return;
case PropertyValue::Type::Double: case storage::PropertyValue::Type::Double:
DumpPreciseDouble(os, value.ValueDouble()); DumpPreciseDouble(os, value.ValueDouble());
return; return;
case PropertyValue::Type::List: { case storage::PropertyValue::Type::List: {
*os << "["; *os << "[";
const auto &list = value.ValueList(); const auto &list = value.ValueList();
utils::PrintIterable(*os, list, ", ", [](auto &os, const auto &item) { utils::PrintIterable(*os, list, ", ", [](auto &os, const auto &item) {
@ -62,7 +62,7 @@ void DumpPropertyValue(std::ostream *os, const PropertyValue &value) {
*os << "]"; *os << "]";
return; return;
} }
case PropertyValue::Type::Map: { case storage::PropertyValue::Type::Map: {
*os << "{"; *os << "{";
const auto &map = value.ValueMap(); const auto &map = value.ValueMap();
utils::PrintIterable(*os, map, ", ", [](auto &os, const auto &kv) { utils::PrintIterable(*os, map, ", ", [](auto &os, const auto &kv) {
@ -75,13 +75,14 @@ void DumpPropertyValue(std::ostream *os, const PropertyValue &value) {
} }
} }
void DumpProperties(std::ostream *os, query::DbAccessor *dba, void DumpProperties(
std::ostream *os, query::DbAccessor *dba,
#ifdef MG_SINGLE_NODE_V2 #ifdef MG_SINGLE_NODE_V2
const std::map<storage::Property, PropertyValue> &store, const std::map<storage::PropertyId, storage::PropertyValue> &store,
#else #else
const PropertyValueStore &store, const PropertyValueStore &store,
#endif #endif
std::optional<uint64_t> property_id = std::nullopt) { std::optional<uint64_t> property_id = std::nullopt) {
*os << "{"; *os << "{";
if (property_id) { if (property_id) {
*os << kInternalPropertyId << ": " << *property_id; *os << kInternalPropertyId << ": " << *property_id;

View File

@ -9,7 +9,7 @@
#include "query/frontend/semantic/symbol.hpp" #include "query/frontend/semantic/symbol.hpp"
#include "query/interpret/awesome_memgraph_functions.hpp" #include "query/interpret/awesome_memgraph_functions.hpp"
#include "query/typed_value.hpp" #include "query/typed_value.hpp"
#include "storage/common/types/property_value.hpp" #include "storage/v2/property_value.hpp"
#include "utils/typeinfo.hpp" #include "utils/typeinfo.hpp"
cpp<# cpp<#
@ -579,7 +579,7 @@ cpp<#
(:clone)) (:clone))
(lcp:define-class primitive-literal (base-literal) (lcp:define-class primitive-literal (base-literal)
((value "PropertyValue" :scope :public) ((value "::storage::PropertyValue" :scope :public)
(token-position :int32_t :scope :public :initval -1 (token-position :int32_t :scope :public :initval -1
:documentation "This field contains token position of literal used to create PrimitiveLiteral object. If PrimitiveLiteral object is not created from query, leave its value at -1.")) :documentation "This field contains token position of literal used to create PrimitiveLiteral object. If PrimitiveLiteral object is not created from query, leave its value at -1."))
(:public (:public

View File

@ -77,7 +77,7 @@ void PrintObject(std::ostream *out, Expression *expr);
void PrintObject(std::ostream *out, Identifier *expr); void PrintObject(std::ostream *out, Identifier *expr);
void PrintObject(std::ostream *out, const PropertyValue &value); void PrintObject(std::ostream *out, const storage::PropertyValue &value);
template <typename T> template <typename T>
void PrintObject(std::ostream *out, const std::vector<T> &vec); void PrintObject(std::ostream *out, const std::vector<T> &vec);
@ -117,33 +117,33 @@ void PrintObject(std::ostream *out, Identifier *expr) {
PrintObject(out, static_cast<Expression *>(expr)); PrintObject(out, static_cast<Expression *>(expr));
} }
void PrintObject(std::ostream *out, const PropertyValue &value) { void PrintObject(std::ostream *out, const storage::PropertyValue &value) {
switch (value.type()) { switch (value.type()) {
case PropertyValue::Type::Null: case storage::PropertyValue::Type::Null:
*out << "null"; *out << "null";
break; break;
case PropertyValue::Type::String: case storage::PropertyValue::Type::String:
PrintObject(out, value.ValueString()); PrintObject(out, value.ValueString());
break; break;
case PropertyValue::Type::Bool: case storage::PropertyValue::Type::Bool:
*out << (value.ValueBool() ? "true" : "false"); *out << (value.ValueBool() ? "true" : "false");
break; break;
case PropertyValue::Type::Int: case storage::PropertyValue::Type::Int:
PrintObject(out, value.ValueInt()); PrintObject(out, value.ValueInt());
break; break;
case PropertyValue::Type::Double: case storage::PropertyValue::Type::Double:
PrintObject(out, value.ValueDouble()); PrintObject(out, value.ValueDouble());
break; break;
case PropertyValue::Type::List: case storage::PropertyValue::Type::List:
PrintObject(out, value.ValueList()); PrintObject(out, value.ValueList());
break; break;
case PropertyValue::Type::Map: case storage::PropertyValue::Type::Map:
PrintObject(out, value.ValueMap()); PrintObject(out, value.ValueMap());
break; break;
} }

View File

@ -68,7 +68,7 @@ StrippedQuery::StrippedQuery(const std::string &query) : original_(query) {
auto replace_stripped = [this, &token_strings](int position, auto replace_stripped = [this, &token_strings](int position,
const auto &value, const auto &value,
const std::string &new_value) { const std::string &new_value) {
literals_.Add(position, PropertyValue(value)); literals_.Add(position, storage::PropertyValue(value));
token_strings.push_back(new_value); token_strings.push_back(new_value);
}; };

View File

@ -558,8 +558,8 @@ class ExpressionEvaluator : public ExpressionVisitor<TypedValue> {
private: private:
template <class TRecordAccessor> template <class TRecordAccessor>
PropertyValue GetProperty(const TRecordAccessor &record_accessor, storage::PropertyValue GetProperty(const TRecordAccessor &record_accessor,
PropertyIx prop) { PropertyIx prop) {
auto maybe_prop = auto maybe_prop =
record_accessor.GetProperty(view_, ctx_->properties[prop.ix]); record_accessor.GetProperty(view_, ctx_->properties[prop.ix]);
if (maybe_prop.HasError() && if (maybe_prop.HasError() &&
@ -592,8 +592,8 @@ class ExpressionEvaluator : public ExpressionVisitor<TypedValue> {
} }
template <class TRecordAccessor> template <class TRecordAccessor>
PropertyValue GetProperty(const TRecordAccessor &record_accessor, storage::PropertyValue GetProperty(const TRecordAccessor &record_accessor,
const std::string_view &name) { const std::string_view &name) {
auto maybe_prop = auto maybe_prop =
record_accessor.GetProperty(view_, dba_->NameToProperty(name)); record_accessor.GetProperty(view_, dba_->NameToProperty(name));
if (maybe_prop.HasError() && if (maybe_prop.HasError() &&
@ -625,7 +625,7 @@ class ExpressionEvaluator : public ExpressionVisitor<TypedValue> {
return *maybe_prop; return *maybe_prop;
} }
storage::Label GetLabel(LabelIx label) { return ctx_->labels[label.ix]; } storage::LabelId GetLabel(LabelIx label) { return ctx_->labels[label.ix]; }
Frame *frame_; Frame *frame_;
const SymbolTable *symbol_table_; const SymbolTable *symbol_table_;

View File

@ -38,7 +38,7 @@ namespace query {
*/ */
struct ParsedQuery { struct ParsedQuery {
std::string query_string; std::string query_string;
std::map<std::string, PropertyValue> user_parameters; std::map<std::string, storage::PropertyValue> user_parameters;
Parameters parameters; Parameters parameters;
frontend::StrippedQuery stripped_query; frontend::StrippedQuery stripped_query;
AstStorage ast_storage; AstStorage ast_storage;
@ -46,10 +46,10 @@ struct ParsedQuery {
std::vector<AuthQuery::Privilege> required_privileges; std::vector<AuthQuery::Privilege> required_privileges;
}; };
ParsedQuery ParseQuery(const std::string &query_string, ParsedQuery ParseQuery(
const std::map<std::string, PropertyValue> &params, const std::string &query_string,
utils::SkipList<QueryCacheEntry> *cache, const std::map<std::string, storage::PropertyValue> &params,
utils::SpinLock *antlr_lock) { utils::SkipList<QueryCacheEntry> *cache, utils::SpinLock *antlr_lock) {
// Strip the query for caching purposes. The process of stripping a query // Strip the query for caching purposes. The process of stripping a query
// "normalizes" it by replacing any literals with new parameters . This // "normalizes" it by replacing any literals with new parameters . This
// results in just the *structure* of the query being taken into account for // results in just the *structure* of the query being taken into account for
@ -1117,8 +1117,9 @@ PreparedQuery PrepareConstraintQuery(
} }
std::pair<std::vector<std::string>, std::vector<query::AuthQuery::Privilege>> std::pair<std::vector<std::string>, std::vector<query::AuthQuery::Privilege>>
Interpreter::Prepare(const std::string &query_string, Interpreter::Prepare(
const std::map<std::string, PropertyValue> &params) { const std::string &query_string,
const std::map<std::string, storage::PropertyValue> &params) {
// Clear the last prepared query. // Clear the last prepared query.
prepared_query_ = std::nullopt; prepared_query_ = std::nullopt;
execution_memory_.Release(); execution_memory_.Release();

View File

@ -250,7 +250,7 @@ class Interpreter final {
*/ */
std::pair<std::vector<std::string>, std::vector<query::AuthQuery::Privilege>> std::pair<std::vector<std::string>, std::vector<query::AuthQuery::Privilege>>
Prepare(const std::string &query, Prepare(const std::string &query,
const std::map<std::string, PropertyValue> &params); const std::map<std::string, storage::PropertyValue> &params);
/** /**
* Execute the last prepared query and stream *all* of the results into the * Execute the last prepared query and stream *all* of the results into the

View File

@ -6,7 +6,7 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "storage/common/types/property_value.hpp" #include "storage/v2/property_value.hpp"
/** /**
* Encapsulates user provided parameters (and stripped literals) * Encapsulates user provided parameters (and stripped literals)
@ -22,7 +22,7 @@ struct Parameters {
* @param position Token position in query of value. * @param position Token position in query of value.
* @param value * @param value
*/ */
void Add(int position, const PropertyValue &value) { void Add(int position, const storage::PropertyValue &value) {
storage_.emplace_back(position, value); storage_.emplace_back(position, value);
} }
@ -32,7 +32,7 @@ struct Parameters {
* @param position Token position in query of value. * @param position Token position in query of value.
* @return Value for the given token position. * @return Value for the given token position.
*/ */
const PropertyValue &AtTokenPosition(int position) const { const storage::PropertyValue &AtTokenPosition(int position) const {
auto found = auto found =
std::find_if(storage_.begin(), storage_.end(), std::find_if(storage_.begin(), storage_.end(),
[&](const auto &a) { return a.first == position; }); [&](const auto &a) { return a.first == position; });
@ -48,7 +48,7 @@ struct Parameters {
* @param position Which stripped param is sought. * @param position Which stripped param is sought.
* @return Token position and value for sought param. * @return Token position and value for sought param.
*/ */
const std::pair<int, PropertyValue> &At(int position) const { const std::pair<int, storage::PropertyValue> &At(int position) const {
CHECK(position < static_cast<int>(storage_.size())) << "Invalid position"; CHECK(position < static_cast<int>(storage_.size())) << "Invalid position";
return storage_[position]; return storage_[position];
} }
@ -60,7 +60,7 @@ struct Parameters {
auto end() const { return storage_.end(); } auto end() const { return storage_.end(); }
private: private:
std::vector<std::pair<int, PropertyValue>> storage_; std::vector<std::pair<int, storage::PropertyValue>> storage_;
}; };
} // namespace query } // namespace query

View File

@ -205,19 +205,20 @@ class CostEstimator : public HierarchicalLogicalOperatorVisitor {
// converts an optional ScanAll range bound into a property value // converts an optional ScanAll range bound into a property value
// if the bound is present and is a constant expression convertible to // if the bound is present and is a constant expression convertible to
// a property value. otherwise returns nullopt // a property value. otherwise returns nullopt
std::optional<utils::Bound<PropertyValue>> BoundToPropertyValue( std::optional<utils::Bound<storage::PropertyValue>> BoundToPropertyValue(
std::optional<ScanAllByLabelPropertyRange::Bound> bound) { std::optional<ScanAllByLabelPropertyRange::Bound> bound) {
if (bound) { if (bound) {
auto property_value = ConstPropertyValue(bound->value()); auto property_value = ConstPropertyValue(bound->value());
if (property_value) if (property_value)
return utils::Bound<PropertyValue>(*property_value, bound->type()); return utils::Bound<storage::PropertyValue>(*property_value,
bound->type());
} }
return std::nullopt; return std::nullopt;
} }
// If the expression is a constant property value, it is returned. Otherwise, // If the expression is a constant property value, it is returned. Otherwise,
// return nullopt. // return nullopt.
std::optional<PropertyValue> ConstPropertyValue( std::optional<storage::PropertyValue> ConstPropertyValue(
const Expression *expression) { const Expression *expression) {
if (auto *literal = utils::Downcast<const PrimitiveLiteral>(expression)) { if (auto *literal = utils::Downcast<const PrimitiveLiteral>(expression)) {
return literal->value_; return literal->value_;

View File

@ -384,7 +384,7 @@ std::vector<Symbol> ScanAll::ModifiedSymbols(const SymbolTable &table) const {
} }
ScanAllByLabel::ScanAllByLabel(const std::shared_ptr<LogicalOperator> &input, ScanAllByLabel::ScanAllByLabel(const std::shared_ptr<LogicalOperator> &input,
Symbol output_symbol, storage::Label label, Symbol output_symbol, storage::LabelId label,
storage::View view) storage::View view)
: ScanAll(input, output_symbol, view), label_(label) {} : ScanAll(input, output_symbol, view), label_(label) {}
@ -401,7 +401,7 @@ UniqueCursorPtr ScanAllByLabel::MakeCursor(utils::MemoryResource *mem) const {
ScanAllByLabelPropertyRange::ScanAllByLabelPropertyRange( ScanAllByLabelPropertyRange::ScanAllByLabelPropertyRange(
const std::shared_ptr<LogicalOperator> &input, Symbol output_symbol, const std::shared_ptr<LogicalOperator> &input, Symbol output_symbol,
storage::Label label, storage::Property property, storage::LabelId label, storage::PropertyId property,
const std::string &property_name, std::optional<Bound> lower_bound, const std::string &property_name, std::optional<Bound> lower_bound,
std::optional<Bound> upper_bound, storage::View view) std::optional<Bound> upper_bound, storage::View view)
: ScanAll(input, output_symbol, view), : ScanAll(input, output_symbol, view),
@ -424,13 +424,12 @@ UniqueCursorPtr ScanAllByLabelPropertyRange::MakeCursor(
ExpressionEvaluator evaluator(&frame, context.symbol_table, ExpressionEvaluator evaluator(&frame, context.symbol_table,
context.evaluation_context, context.evaluation_context,
context.db_accessor, view_); context.db_accessor, view_);
auto convert = auto convert = [&evaluator](const auto &bound)
[&evaluator]( -> std::optional<utils::Bound<storage::PropertyValue>> {
const auto &bound) -> std::optional<utils::Bound<PropertyValue>> {
if (!bound) return std::nullopt; if (!bound) return std::nullopt;
const auto &value = bound->value()->Accept(evaluator); const auto &value = bound->value()->Accept(evaluator);
try { try {
const auto &property_value = PropertyValue(value); const auto &property_value = storage::PropertyValue(value);
switch (property_value.type()) { switch (property_value.type()) {
case storage::PropertyValue::Type::Bool: case storage::PropertyValue::Type::Bool:
case storage::PropertyValue::Type::List: case storage::PropertyValue::Type::List:
@ -447,8 +446,8 @@ UniqueCursorPtr ScanAllByLabelPropertyRange::MakeCursor(
// These are all fine, there's also Point, Date and Time data types // These are all fine, there's also Point, Date and Time data types
// which were added to Cypher, but we don't have support for those // which were added to Cypher, but we don't have support for those
// yet. // yet.
return std::make_optional( return std::make_optional(utils::Bound<storage::PropertyValue>(
utils::Bound<PropertyValue>(property_value, bound->type())); property_value, bound->type()));
} }
} catch (const TypedValueException &) { } catch (const TypedValueException &) {
throw QueryRuntimeException("'{}' cannot be used as a property value.", throw QueryRuntimeException("'{}' cannot be used as a property value.",
@ -470,7 +469,7 @@ UniqueCursorPtr ScanAllByLabelPropertyRange::MakeCursor(
ScanAllByLabelPropertyValue::ScanAllByLabelPropertyValue( ScanAllByLabelPropertyValue::ScanAllByLabelPropertyValue(
const std::shared_ptr<LogicalOperator> &input, Symbol output_symbol, const std::shared_ptr<LogicalOperator> &input, Symbol output_symbol,
storage::Label label, storage::Property property, storage::LabelId label, storage::PropertyId property,
const std::string &property_name, Expression *expression, const std::string &property_name, Expression *expression,
storage::View view) storage::View view)
: ScanAll(input, output_symbol, view), : ScanAll(input, output_symbol, view),
@ -487,7 +486,7 @@ UniqueCursorPtr ScanAllByLabelPropertyValue::MakeCursor(
utils::MemoryResource *mem) const { utils::MemoryResource *mem) const {
auto vertices = [this](Frame &frame, ExecutionContext &context) auto vertices = [this](Frame &frame, ExecutionContext &context)
-> std::optional<decltype(context.db_accessor->Vertices( -> std::optional<decltype(context.db_accessor->Vertices(
view_, label_, property_, PropertyValue()))> { view_, label_, property_, storage::PropertyValue()))> {
auto *db = context.db_accessor; auto *db = context.db_accessor;
ExpressionEvaluator evaluator(&frame, context.symbol_table, ExpressionEvaluator evaluator(&frame, context.symbol_table,
context.evaluation_context, context.evaluation_context,
@ -499,7 +498,7 @@ UniqueCursorPtr ScanAllByLabelPropertyValue::MakeCursor(
value.type()); value.type());
} }
return std::make_optional( return std::make_optional(
db->Vertices(view_, label_, property_, PropertyValue(value))); db->Vertices(view_, label_, property_, storage::PropertyValue(value)));
}; };
return MakeUniqueCursorPtr<ScanAllCursor<decltype(vertices)>>( return MakeUniqueCursorPtr<ScanAllCursor<decltype(vertices)>>(
mem, output_symbol_, input_->MakeCursor(mem), std::move(vertices)); mem, output_symbol_, input_->MakeCursor(mem), std::move(vertices));
@ -567,7 +566,7 @@ auto UnwrapEdgesResult(storage::Result<TEdges> &&result) {
Expand::Expand(const std::shared_ptr<LogicalOperator> &input, Expand::Expand(const std::shared_ptr<LogicalOperator> &input,
Symbol input_symbol, Symbol node_symbol, Symbol edge_symbol, Symbol input_symbol, Symbol node_symbol, Symbol edge_symbol,
EdgeAtom::Direction direction, EdgeAtom::Direction direction,
const std::vector<storage::EdgeType> &edge_types, const std::vector<storage::EdgeTypeId> &edge_types,
bool existing_node, storage::View view) bool existing_node, storage::View view)
: input_(input ? input : std::make_shared<Once>()), : input_(input ? input : std::make_shared<Once>()),
input_symbol_(input_symbol), input_symbol_(input_symbol),
@ -712,16 +711,14 @@ bool Expand::ExpandCursor::InitEdges(Frame &frame, ExecutionContext &context) {
} }
} }
ExpandVariable::ExpandVariable(const std::shared_ptr<LogicalOperator> &input, ExpandVariable::ExpandVariable(
Symbol input_symbol, Symbol node_symbol, const std::shared_ptr<LogicalOperator> &input, Symbol input_symbol,
Symbol edge_symbol, EdgeAtom::Type type, Symbol node_symbol, Symbol edge_symbol, EdgeAtom::Type type,
EdgeAtom::Direction direction, EdgeAtom::Direction direction,
const std::vector<storage::EdgeType> &edge_types, const std::vector<storage::EdgeTypeId> &edge_types, bool is_reverse,
bool is_reverse, Expression *lower_bound, Expression *lower_bound, Expression *upper_bound, bool existing_node,
Expression *upper_bound, bool existing_node, ExpansionLambda filter_lambda, std::optional<ExpansionLambda> weight_lambda,
ExpansionLambda filter_lambda, std::optional<Symbol> total_weight)
std::optional<ExpansionLambda> weight_lambda,
std::optional<Symbol> total_weight)
: input_(input ? input : std::make_shared<Once>()), : input_(input ? input : std::make_shared<Once>()),
input_symbol_(input_symbol), input_symbol_(input_symbol),
common_{node_symbol, edge_symbol, direction, edge_types, existing_node}, common_{node_symbol, edge_symbol, direction, edge_types, existing_node},
@ -784,7 +781,7 @@ size_t UnwrapDegreeResult(storage::Result<size_t> maybe_degree) {
*/ */
auto ExpandFromVertex(const VertexAccessor &vertex, auto ExpandFromVertex(const VertexAccessor &vertex,
EdgeAtom::Direction direction, EdgeAtom::Direction direction,
const std::vector<storage::EdgeType> &edge_types, const std::vector<storage::EdgeTypeId> &edge_types,
utils::MemoryResource *memory) { utils::MemoryResource *memory) {
// wraps an EdgeAccessor into a pair <accessor, direction> // wraps an EdgeAccessor into a pair <accessor, direction>
auto wrapper = [](EdgeAtom::Direction direction, auto &&edges) { auto wrapper = [](EdgeAtom::Direction direction, auto &&edges) {
@ -2042,7 +2039,7 @@ void Delete::DeleteCursor::Shutdown() { input_cursor_->Shutdown(); }
void Delete::DeleteCursor::Reset() { input_cursor_->Reset(); } void Delete::DeleteCursor::Reset() { input_cursor_->Reset(); }
SetProperty::SetProperty(const std::shared_ptr<LogicalOperator> &input, SetProperty::SetProperty(const std::shared_ptr<LogicalOperator> &input,
storage::Property property, PropertyLookup *lhs, storage::PropertyId property, PropertyLookup *lhs,
Expression *rhs) Expression *rhs)
: input_(input), property_(property), lhs_(lhs), rhs_(rhs) {} : input_(input), property_(property), lhs_(lhs), rhs_(rhs) {}
@ -2255,7 +2252,7 @@ void SetProperties::SetPropertiesCursor::Reset() { input_cursor_->Reset(); }
SetLabels::SetLabels(const std::shared_ptr<LogicalOperator> &input, SetLabels::SetLabels(const std::shared_ptr<LogicalOperator> &input,
Symbol input_symbol, Symbol input_symbol,
const std::vector<storage::Label> &labels) const std::vector<storage::LabelId> &labels)
: input_(input), input_symbol_(input_symbol), labels_(labels) {} : input_(input), input_symbol_(input_symbol), labels_(labels) {}
ACCEPT_WITH_INPUT(SetLabels) ACCEPT_WITH_INPUT(SetLabels)
@ -2308,7 +2305,8 @@ void SetLabels::SetLabelsCursor::Shutdown() { input_cursor_->Shutdown(); }
void SetLabels::SetLabelsCursor::Reset() { input_cursor_->Reset(); } void SetLabels::SetLabelsCursor::Reset() { input_cursor_->Reset(); }
RemoveProperty::RemoveProperty(const std::shared_ptr<LogicalOperator> &input, RemoveProperty::RemoveProperty(const std::shared_ptr<LogicalOperator> &input,
storage::Property property, PropertyLookup *lhs) storage::PropertyId property,
PropertyLookup *lhs)
: input_(input), property_(property), lhs_(lhs) {} : input_(input), property_(property), lhs_(lhs) {}
ACCEPT_WITH_INPUT(RemoveProperty) ACCEPT_WITH_INPUT(RemoveProperty)
@ -2385,7 +2383,7 @@ void RemoveProperty::RemovePropertyCursor::Reset() { input_cursor_->Reset(); }
RemoveLabels::RemoveLabels(const std::shared_ptr<LogicalOperator> &input, RemoveLabels::RemoveLabels(const std::shared_ptr<LogicalOperator> &input,
Symbol input_symbol, Symbol input_symbol,
const std::vector<storage::Label> &labels) const std::vector<storage::LabelId> &labels)
: input_(input), input_symbol_(input_symbol), labels_(labels) {} : input_(input), input_symbol_(input_symbol), labels_(labels) {}
ACCEPT_WITH_INPUT(RemoveLabels) ACCEPT_WITH_INPUT(RemoveLabels)

View File

@ -14,7 +14,7 @@
#include "query/frontend/ast/ast.hpp" #include "query/frontend/ast/ast.hpp"
#include "query/frontend/semantic/symbol.hpp" #include "query/frontend/semantic/symbol.hpp"
#include "query/typed_value.hpp" #include "query/typed_value.hpp"
#include "storage/common/types/types.hpp" #include "storage/v2/id_types.hpp"
#include "utils/bound.hpp" #include "utils/bound.hpp"
#include "utils/future.hpp" #include "utils/future.hpp"
#include "utils/hashing/fnv.hpp" #include "utils/hashing/fnv.hpp"
@ -336,7 +336,7 @@ and false on every following Pull.")
slk::Load(&size, reader); slk::Load(&size, reader);
self->${member}.resize(size); self->${member}.resize(size);
for (size_t i = 0; i < size; ++i) { for (size_t i = 0; i < size; ++i) {
storage::Property prop; storage::PropertyId prop;
slk::Load(&prop, reader); slk::Load(&prop, reader);
auto *expr = query::LoadAstPointer<query::Expression>( auto *expr = query::LoadAstPointer<query::Expression>(
&helper->ast_storage, reader); &helper->ast_storage, reader);
@ -346,8 +346,8 @@ and false on every following Pull.")
(lcp:define-struct node-creation-info () (lcp:define-struct node-creation-info ()
((symbol "Symbol") ((symbol "Symbol")
(labels "std::vector<storage::Label>") (labels "std::vector<storage::LabelId>")
(properties "std::vector<std::pair<storage::Property, Expression *>>" (properties "std::vector<std::pair<storage::PropertyId, Expression *>>"
:slk-save #'slk-save-properties :slk-save #'slk-save-properties
:slk-load #'slk-load-properties)) :slk-load #'slk-load-properties))
(:serialize (:slk :save-args '((helper "query::plan::LogicalOperator::SaveHelper *")) (:serialize (:slk :save-args '((helper "query::plan::LogicalOperator::SaveHelper *"))
@ -417,10 +417,10 @@ a preceeding `MATCH`), or multiple nodes (`MATCH ... CREATE` or
(lcp:define-struct edge-creation-info () (lcp:define-struct edge-creation-info ()
((symbol "Symbol") ((symbol "Symbol")
(properties "std::vector<std::pair<storage::Property, Expression *>>" (properties "std::vector<std::pair<storage::PropertyId, Expression *>>"
:slk-save #'slk-save-properties :slk-save #'slk-save-properties
:slk-load #'slk-load-properties) :slk-load #'slk-load-properties)
(edge-type "::storage::EdgeType") (edge-type "::storage::EdgeTypeId")
(direction "::EdgeAtom::Direction" :initval "EdgeAtom::Direction::BOTH")) (direction "::EdgeAtom::Direction" :initval "EdgeAtom::Direction::BOTH"))
(:serialize (:slk :save-args '((helper "query::plan::LogicalOperator::SaveHelper *")) (:serialize (:slk :save-args '((helper "query::plan::LogicalOperator::SaveHelper *"))
:load-args '((helper "query::plan::LogicalOperator::SlkLoadHelper *")))) :load-args '((helper "query::plan::LogicalOperator::SlkLoadHelper *"))))
@ -564,7 +564,7 @@ with a constructor argument.
(:clone)) (:clone))
(lcp:define-class scan-all-by-label (scan-all) (lcp:define-class scan-all-by-label (scan-all)
((label "::storage::Label" :scope :public)) ((label "::storage::LabelId" :scope :public))
(:documentation (:documentation
"Behaves like @c ScanAll, but this operator produces only vertices with "Behaves like @c ScanAll, but this operator produces only vertices with
given label. given label.
@ -576,7 +576,7 @@ given label.
#>cpp #>cpp
ScanAllByLabel() {} ScanAllByLabel() {}
ScanAllByLabel(const std::shared_ptr<LogicalOperator> &input, ScanAllByLabel(const std::shared_ptr<LogicalOperator> &input,
Symbol output_symbol, storage::Label label, Symbol output_symbol, storage::LabelId label,
storage::View view = storage::View::OLD); storage::View view = storage::View::OLD);
bool Accept(HierarchicalLogicalOperatorVisitor &visitor) override; bool Accept(HierarchicalLogicalOperatorVisitor &visitor) override;
UniqueCursorPtr MakeCursor(utils::MemoryResource *) const override; UniqueCursorPtr MakeCursor(utils::MemoryResource *) const override;
@ -642,8 +642,8 @@ given label.
cpp<#) cpp<#)
(lcp:define-class scan-all-by-label-property-range (scan-all) (lcp:define-class scan-all-by-label-property-range (scan-all)
((label "::storage::Label" :scope :public) ((label "::storage::LabelId" :scope :public)
(property "::storage::Property" :scope :public) (property "::storage::PropertyId" :scope :public)
(property-name "std::string" :scope :public) (property-name "std::string" :scope :public)
(lower-bound "std::optional<Bound>" :scope :public (lower-bound "std::optional<Bound>" :scope :public
:slk-save #'slk-save-optional-bound :slk-save #'slk-save-optional-bound
@ -680,8 +680,8 @@ property value which is inside a range (inclusive or exlusive).
* @param view storage::View used when obtaining vertices. * @param view storage::View used when obtaining vertices.
*/ */
ScanAllByLabelPropertyRange(const std::shared_ptr<LogicalOperator> &input, ScanAllByLabelPropertyRange(const std::shared_ptr<LogicalOperator> &input,
Symbol output_symbol, storage::Label label, Symbol output_symbol, storage::LabelId label,
storage::Property property, storage::PropertyId property,
const std::string &property_name, const std::string &property_name,
std::optional<Bound> lower_bound, std::optional<Bound> lower_bound,
std::optional<Bound> upper_bound, std::optional<Bound> upper_bound,
@ -694,8 +694,8 @@ property value which is inside a range (inclusive or exlusive).
(:clone)) (:clone))
(lcp:define-class scan-all-by-label-property-value (scan-all) (lcp:define-class scan-all-by-label-property-value (scan-all)
((label "::storage::Label" :scope :public) ((label "::storage::LabelId" :scope :public)
(property "::storage::Property" :scope :public) (property "::storage::PropertyId" :scope :public)
(property-name "std::string" :scope :public) (property-name "std::string" :scope :public)
(expression "Expression *" :scope :public (expression "Expression *" :scope :public
:slk-save #'slk-save-ast-pointer :slk-save #'slk-save-ast-pointer
@ -721,8 +721,8 @@ property value.
* @param view storage::View used when obtaining vertices. * @param view storage::View used when obtaining vertices.
*/ */
ScanAllByLabelPropertyValue(const std::shared_ptr<LogicalOperator> &input, ScanAllByLabelPropertyValue(const std::shared_ptr<LogicalOperator> &input,
Symbol output_symbol, storage::Label label, Symbol output_symbol, storage::LabelId label,
storage::Property property, storage::PropertyId property,
const std::string &property_name, const std::string &property_name,
Expression *expression, Expression *expression,
storage::View view = storage::View::OLD); storage::View view = storage::View::OLD);
@ -764,8 +764,8 @@ This is where a TypedValue containing a list of expanded edges will be stored.")
(direction "::EdgeAtom::Direction" (direction "::EdgeAtom::Direction"
:documentation "EdgeAtom::Direction determining the direction of edge :documentation "EdgeAtom::Direction determining the direction of edge
expansion. The direction is relative to the starting vertex for each expansion.") expansion. The direction is relative to the starting vertex for each expansion.")
(edge-types "std::vector<storage::EdgeType>" (edge-types "std::vector<storage::EdgeTypeId>"
:documentation "storage::EdgeType specifying which edges we want :documentation "storage::EdgeTypeId specifying which edges we want
to expand. If empty, all edges are valid. If not empty, only edges with one of to expand. If empty, all edges are valid. If not empty, only edges with one of
the given types are valid.") the given types are valid.")
(existing-node :bool :documentation "If the given node atom refer to a symbol (existing-node :bool :documentation "If the given node atom refer to a symbol
@ -806,7 +806,7 @@ pulled.")
*/ */
Expand(const std::shared_ptr<LogicalOperator> &input, Symbol input_symbol, Expand(const std::shared_ptr<LogicalOperator> &input, Symbol input_symbol,
Symbol node_symbol, Symbol edge_symbol, EdgeAtom::Direction direction, Symbol node_symbol, Symbol edge_symbol, EdgeAtom::Direction direction,
const std::vector<storage::EdgeType> &edge_types, bool existing_node, const std::vector<storage::EdgeTypeId> &edge_types, bool existing_node,
storage::View view); storage::View view);
Expand() {} Expand() {}
@ -953,7 +953,7 @@ pulled.")
ExpandVariable(const std::shared_ptr<LogicalOperator> &input, ExpandVariable(const std::shared_ptr<LogicalOperator> &input,
Symbol input_symbol, Symbol node_symbol, Symbol edge_symbol, Symbol input_symbol, Symbol node_symbol, Symbol edge_symbol,
EdgeAtom::Type type, EdgeAtom::Direction direction, EdgeAtom::Type type, EdgeAtom::Direction direction,
const std::vector<storage::EdgeType> &edge_types, const std::vector<storage::EdgeTypeId> &edge_types,
bool is_reverse, Expression *lower_bound, bool is_reverse, Expression *lower_bound,
Expression *upper_bound, bool existing_node, Expression *upper_bound, bool existing_node,
ExpansionLambda filter_lambda, ExpansionLambda filter_lambda,
@ -1159,7 +1159,7 @@ Has a flag for using DETACH DELETE when deleting vertices.")
((input "std::shared_ptr<LogicalOperator>" :scope :public ((input "std::shared_ptr<LogicalOperator>" :scope :public
:slk-save #'slk-save-operator-pointer :slk-save #'slk-save-operator-pointer
:slk-load #'slk-load-operator-pointer) :slk-load #'slk-load-operator-pointer)
(property "::storage::Property" :scope :public) (property "::storage::PropertyId" :scope :public)
(lhs "PropertyLookup *" :scope :public (lhs "PropertyLookup *" :scope :public
:slk-save #'slk-save-ast-pointer :slk-save #'slk-save-ast-pointer
:slk-load (slk-load-ast-pointer "PropertyLookup")) :slk-load (slk-load-ast-pointer "PropertyLookup"))
@ -1176,7 +1176,7 @@ can be stored (a TypedValue that can be converted to PropertyValue).")
SetProperty() {} SetProperty() {}
SetProperty(const std::shared_ptr<LogicalOperator> &input, SetProperty(const std::shared_ptr<LogicalOperator> &input,
storage::Property property, PropertyLookup *lhs, storage::PropertyId property, PropertyLookup *lhs,
Expression *rhs); Expression *rhs);
bool Accept(HierarchicalLogicalOperatorVisitor &visitor) override; bool Accept(HierarchicalLogicalOperatorVisitor &visitor) override;
UniqueCursorPtr MakeCursor(utils::MemoryResource *) const override; UniqueCursorPtr MakeCursor(utils::MemoryResource *) const override;
@ -1269,7 +1269,7 @@ that the old properties are discarded and replaced with new ones.")
:slk-save #'slk-save-operator-pointer :slk-save #'slk-save-operator-pointer
:slk-load #'slk-load-operator-pointer) :slk-load #'slk-load-operator-pointer)
(input-symbol "Symbol" :scope :public) (input-symbol "Symbol" :scope :public)
(labels "std::vector<storage::Label>" :scope :public)) (labels "std::vector<storage::LabelId>" :scope :public))
(:documentation (:documentation
"Logical operator for setting an arbitrary number of labels on a Vertex. "Logical operator for setting an arbitrary number of labels on a Vertex.
@ -1279,7 +1279,7 @@ It does NOT remove labels that are already set on that Vertex.")
SetLabels() {} SetLabels() {}
SetLabels(const std::shared_ptr<LogicalOperator> &input, Symbol input_symbol, SetLabels(const std::shared_ptr<LogicalOperator> &input, Symbol input_symbol,
const std::vector<storage::Label> &labels); const std::vector<storage::LabelId> &labels);
bool Accept(HierarchicalLogicalOperatorVisitor &visitor) override; bool Accept(HierarchicalLogicalOperatorVisitor &visitor) override;
UniqueCursorPtr MakeCursor(utils::MemoryResource *) const override; UniqueCursorPtr MakeCursor(utils::MemoryResource *) const override;
std::vector<Symbol> ModifiedSymbols(const SymbolTable &) const override; std::vector<Symbol> ModifiedSymbols(const SymbolTable &) const override;
@ -1311,7 +1311,7 @@ It does NOT remove labels that are already set on that Vertex.")
((input "std::shared_ptr<LogicalOperator>" :scope :public ((input "std::shared_ptr<LogicalOperator>" :scope :public
:slk-save #'slk-save-operator-pointer :slk-save #'slk-save-operator-pointer
:slk-load #'slk-load-operator-pointer) :slk-load #'slk-load-operator-pointer)
(property "::storage::Property" :scope :public) (property "::storage::PropertyId" :scope :public)
(lhs "PropertyLookup *" :scope :public (lhs "PropertyLookup *" :scope :public
:slk-save #'slk-save-ast-pointer :slk-save #'slk-save-ast-pointer
:slk-load (slk-load-ast-pointer "PropertyLookup"))) :slk-load (slk-load-ast-pointer "PropertyLookup")))
@ -1322,7 +1322,7 @@ It does NOT remove labels that are already set on that Vertex.")
RemoveProperty() {} RemoveProperty() {}
RemoveProperty(const std::shared_ptr<LogicalOperator> &input, RemoveProperty(const std::shared_ptr<LogicalOperator> &input,
storage::Property property, PropertyLookup *lhs); storage::PropertyId property, PropertyLookup *lhs);
bool Accept(HierarchicalLogicalOperatorVisitor &visitor) override; bool Accept(HierarchicalLogicalOperatorVisitor &visitor) override;
UniqueCursorPtr MakeCursor(utils::MemoryResource *) const override; UniqueCursorPtr MakeCursor(utils::MemoryResource *) const override;
std::vector<Symbol> ModifiedSymbols(const SymbolTable &) const override; std::vector<Symbol> ModifiedSymbols(const SymbolTable &) const override;
@ -1355,7 +1355,7 @@ It does NOT remove labels that are already set on that Vertex.")
:slk-save #'slk-save-operator-pointer :slk-save #'slk-save-operator-pointer
:slk-load #'slk-load-operator-pointer) :slk-load #'slk-load-operator-pointer)
(input-symbol "Symbol" :scope :public) (input-symbol "Symbol" :scope :public)
(labels "std::vector<storage::Label>" :scope :public)) (labels "std::vector<storage::LabelId>" :scope :public))
(:documentation (:documentation
"Logical operator for removing an arbitrary number of labels on a Vertex. "Logical operator for removing an arbitrary number of labels on a Vertex.
@ -1365,7 +1365,7 @@ If a label does not exist on a Vertex, nothing happens.")
RemoveLabels() {} RemoveLabels() {}
RemoveLabels(const std::shared_ptr<LogicalOperator> &input, RemoveLabels(const std::shared_ptr<LogicalOperator> &input,
Symbol input_symbol, const std::vector<storage::Label> &labels); Symbol input_symbol, const std::vector<storage::LabelId> &labels);
bool Accept(HierarchicalLogicalOperatorVisitor &visitor) override; bool Accept(HierarchicalLogicalOperatorVisitor &visitor) override;
UniqueCursorPtr MakeCursor(utils::MemoryResource *) const override; UniqueCursorPtr MakeCursor(utils::MemoryResource *) const override;
std::vector<Symbol> ModifiedSymbols(const SymbolTable &) const override; std::vector<Symbol> ModifiedSymbols(const SymbolTable &) const override;

View File

@ -332,15 +332,15 @@ json ToJson(const utils::Bound<Expression *> &bound) {
json ToJson(const Symbol &symbol) { return symbol.name(); } json ToJson(const Symbol &symbol) { return symbol.name(); }
json ToJson(storage::EdgeType edge_type, const DbAccessor &dba) { json ToJson(storage::EdgeTypeId edge_type, const DbAccessor &dba) {
return dba.EdgeTypeToName(edge_type); return dba.EdgeTypeToName(edge_type);
} }
json ToJson(storage::Label label, const DbAccessor &dba) { json ToJson(storage::LabelId label, const DbAccessor &dba) {
return dba.LabelToName(label); return dba.LabelToName(label);
} }
json ToJson(storage::Property property, const DbAccessor &dba) { json ToJson(storage::PropertyId property, const DbAccessor &dba) {
return dba.PropertyToName(property); return dba.PropertyToName(property);
} }
@ -352,7 +352,7 @@ json ToJson(NamedExpression *nexpr) {
} }
json ToJson( json ToJson(
const std::vector<std::pair<storage::Property, Expression *>> &properties, const std::vector<std::pair<storage::PropertyId, Expression *>> &properties,
const DbAccessor &dba) { const DbAccessor &dba) {
json json; json json;
for (const auto &prop_pair : properties) { for (const auto &prop_pair : properties) {

View File

@ -120,16 +120,16 @@ nlohmann::json ToJson(const utils::Bound<Expression *> &bound);
nlohmann::json ToJson(const Symbol &symbol); nlohmann::json ToJson(const Symbol &symbol);
nlohmann::json ToJson(storage::EdgeType edge_type, const DbAccessor &dba); nlohmann::json ToJson(storage::EdgeTypeId edge_type, const DbAccessor &dba);
nlohmann::json ToJson(storage::Label label, const DbAccessor &dba); nlohmann::json ToJson(storage::LabelId label, const DbAccessor &dba);
nlohmann::json ToJson(storage::Property property, const DbAccessor &dba); nlohmann::json ToJson(storage::PropertyId property, const DbAccessor &dba);
nlohmann::json ToJson(NamedExpression *nexpr); nlohmann::json ToJson(NamedExpression *nexpr);
nlohmann::json ToJson( nlohmann::json ToJson(
const std::vector<std::pair<storage::Property, Expression *>> &properties, const std::vector<std::pair<storage::PropertyId, Expression *>> &properties,
const DbAccessor &dba); const DbAccessor &dba);
nlohmann::json ToJson(const NodeCreationInfo &node_info, const DbAccessor &dba); nlohmann::json ToJson(const NodeCreationInfo &node_info, const DbAccessor &dba);

View File

@ -439,11 +439,11 @@ class IndexLookupRewriter final : public HierarchicalLogicalOperatorVisitor {
} }
} }
storage::Label GetLabel(LabelIx label) { storage::LabelId GetLabel(LabelIx label) {
return db_->NameToLabel(label.name); return db_->NameToLabel(label.name);
} }
storage::Property GetProperty(PropertyIx prop) { storage::PropertyId GetProperty(PropertyIx prop) {
return db_->NameToProperty(prop.name); return db_->NameToProperty(prop.name);
} }

View File

@ -238,15 +238,15 @@ class RuleBasedPlanner {
private: private:
TPlanningContext *context_; TPlanningContext *context_;
storage::Label GetLabel(LabelIx label) { storage::LabelId GetLabel(LabelIx label) {
return context_->db->NameToLabel(label.name); return context_->db->NameToLabel(label.name);
} }
storage::Property GetProperty(PropertyIx prop) { storage::PropertyId GetProperty(PropertyIx prop) {
return context_->db->NameToProperty(prop.name); return context_->db->NameToProperty(prop.name);
} }
storage::EdgeType GetEdgeType(EdgeTypeIx edge_type) { storage::EdgeTypeId GetEdgeType(EdgeTypeIx edge_type) {
return context_->db->NameToEdgeType(edge_type.name); return context_->db->NameToEdgeType(edge_type.name);
} }
@ -268,12 +268,12 @@ class RuleBasedPlanner {
std::unordered_set<Symbol> &bound_symbols) { std::unordered_set<Symbol> &bound_symbols) {
auto node_to_creation_info = [&](const NodeAtom &node) { auto node_to_creation_info = [&](const NodeAtom &node) {
const auto &node_symbol = symbol_table.at(*node.identifier_); const auto &node_symbol = symbol_table.at(*node.identifier_);
std::vector<storage::Label> labels; std::vector<storage::LabelId> labels;
labels.reserve(node.labels_.size()); labels.reserve(node.labels_.size());
for (const auto &label : node.labels_) { for (const auto &label : node.labels_) {
labels.push_back(GetLabel(label)); labels.push_back(GetLabel(label));
} }
std::vector<std::pair<storage::Property, Expression *>> properties; std::vector<std::pair<storage::PropertyId, Expression *>> properties;
properties.reserve(node.properties_.size()); properties.reserve(node.properties_.size());
for (const auto &kv : node.properties_) { for (const auto &kv : node.properties_) {
properties.push_back({GetProperty(kv.first), kv.second}); properties.push_back({GetProperty(kv.first), kv.second});
@ -306,7 +306,7 @@ class RuleBasedPlanner {
LOG(FATAL) << "Symbols used for created edges cannot be redeclared."; LOG(FATAL) << "Symbols used for created edges cannot be redeclared.";
} }
auto node_info = node_to_creation_info(*node); auto node_info = node_to_creation_info(*node);
std::vector<std::pair<storage::Property, Expression *>> properties; std::vector<std::pair<storage::PropertyId, Expression *>> properties;
properties.reserve(edge->properties_.size()); properties.reserve(edge->properties_.size());
for (const auto &kv : edge->properties_) { for (const auto &kv : edge->properties_) {
properties.push_back({GetProperty(kv.first), kv.second}); properties.push_back({GetProperty(kv.first), kv.second});
@ -362,7 +362,7 @@ class RuleBasedPlanner {
std::move(input_op), input_symbol, set->expression_, op); std::move(input_op), input_symbol, set->expression_, op);
} else if (auto *set = utils::Downcast<query::SetLabels>(clause)) { } else if (auto *set = utils::Downcast<query::SetLabels>(clause)) {
const auto &input_symbol = symbol_table.at(*set->identifier_); const auto &input_symbol = symbol_table.at(*set->identifier_);
std::vector<storage::Label> labels; std::vector<storage::LabelId> labels;
labels.reserve(set->labels_.size()); labels.reserve(set->labels_.size());
for (const auto &label : set->labels_) { for (const auto &label : set->labels_) {
labels.push_back(GetLabel(label)); labels.push_back(GetLabel(label));
@ -375,7 +375,7 @@ class RuleBasedPlanner {
rem->property_lookup_); rem->property_lookup_);
} else if (auto *rem = utils::Downcast<query::RemoveLabels>(clause)) { } else if (auto *rem = utils::Downcast<query::RemoveLabels>(clause)) {
const auto &input_symbol = symbol_table.at(*rem->identifier_); const auto &input_symbol = symbol_table.at(*rem->identifier_);
std::vector<storage::Label> labels; std::vector<storage::LabelId> labels;
labels.reserve(rem->labels_.size()); labels.reserve(rem->labels_.size());
for (const auto &label : rem->labels_) { for (const auto &label : rem->labels_) {
labels.push_back(GetLabel(label)); labels.push_back(GetLabel(label));
@ -427,7 +427,7 @@ class RuleBasedPlanner {
const auto &edge_symbol = symbol_table.at(*edge->identifier_); const auto &edge_symbol = symbol_table.at(*edge->identifier_);
CHECK(!utils::Contains(bound_symbols, edge_symbol)) CHECK(!utils::Contains(bound_symbols, edge_symbol))
<< "Existing edges are not supported"; << "Existing edges are not supported";
std::vector<storage::EdgeType> edge_types; std::vector<storage::EdgeTypeId> edge_types;
edge_types.reserve(edge->edge_types_.size()); edge_types.reserve(edge->edge_types_.size());
for (const auto &type : edge->edge_types_) { for (const auto &type : edge->edge_types_) {
edge_types.push_back(GetEdgeType(type)); edge_types.push_back(GetEdgeType(type));

View File

@ -4,8 +4,8 @@
#include <optional> #include <optional>
#include "query/typed_value.hpp" #include "query/typed_value.hpp"
#include "storage/common/types/property_value.hpp" #include "storage/v2/id_types.hpp"
#include "storage/common/types/types.hpp" #include "storage/v2/property_value.hpp"
#include "utils/bound.hpp" #include "utils/bound.hpp"
#include "utils/hashing/fnv.hpp" #include "utils/hashing/fnv.hpp"
@ -31,13 +31,13 @@ class VertexCountCache {
return *vertices_count_; return *vertices_count_;
} }
int64_t VerticesCount(storage::Label label) { int64_t VerticesCount(storage::LabelId label) {
if (label_vertex_count_.find(label) == label_vertex_count_.end()) if (label_vertex_count_.find(label) == label_vertex_count_.end())
label_vertex_count_[label] = db_->VerticesCount(label); label_vertex_count_[label] = db_->VerticesCount(label);
return label_vertex_count_.at(label); return label_vertex_count_.at(label);
} }
int64_t VerticesCount(storage::Label label, storage::Property property) { int64_t VerticesCount(storage::LabelId label, storage::PropertyId property) {
auto key = std::make_pair(label, property); auto key = std::make_pair(label, property);
if (label_property_vertex_count_.find(key) == if (label_property_vertex_count_.find(key) ==
label_property_vertex_count_.end()) label_property_vertex_count_.end())
@ -45,8 +45,8 @@ class VertexCountCache {
return label_property_vertex_count_.at(key); return label_property_vertex_count_.at(key);
} }
int64_t VerticesCount(storage::Label label, storage::Property property, int64_t VerticesCount(storage::LabelId label, storage::PropertyId property,
const PropertyValue &value) { const storage::PropertyValue &value) {
auto label_prop = std::make_pair(label, property); auto label_prop = std::make_pair(label, property);
auto &value_vertex_count = property_value_vertex_count_[label_prop]; auto &value_vertex_count = property_value_vertex_count_[label_prop];
// TODO: Why do we even need TypedValue in this whole file? // TODO: Why do we even need TypedValue in this whole file?
@ -57,9 +57,9 @@ class VertexCountCache {
} }
int64_t VerticesCount( int64_t VerticesCount(
storage::Label label, storage::Property property, storage::LabelId label, storage::PropertyId property,
const std::optional<utils::Bound<PropertyValue>> &lower, const std::optional<utils::Bound<storage::PropertyValue>> &lower,
const std::optional<utils::Bound<PropertyValue>> &upper) { const std::optional<utils::Bound<storage::PropertyValue>> &upper) {
auto label_prop = std::make_pair(label, property); auto label_prop = std::make_pair(label, property);
auto &bounds_vertex_count = property_bounds_vertex_count_[label_prop]; auto &bounds_vertex_count = property_bounds_vertex_count_[label_prop];
BoundsKey bounds = std::make_pair(lower, upper); BoundsKey bounds = std::make_pair(lower, upper);
@ -69,27 +69,27 @@ class VertexCountCache {
return bounds_vertex_count.at(bounds); return bounds_vertex_count.at(bounds);
} }
bool LabelIndexExists(storage::Label label) { bool LabelIndexExists(storage::LabelId label) {
return db_->LabelIndexExists(label); return db_->LabelIndexExists(label);
} }
bool LabelPropertyIndexExists(storage::Label label, bool LabelPropertyIndexExists(storage::LabelId label,
storage::Property property) { storage::PropertyId property) {
return db_->LabelPropertyIndexExists(label, property); return db_->LabelPropertyIndexExists(label, property);
} }
private: private:
typedef std::pair<storage::Label, storage::Property> LabelPropertyKey; typedef std::pair<storage::LabelId, storage::PropertyId> LabelPropertyKey;
struct LabelPropertyHash { struct LabelPropertyHash {
size_t operator()(const LabelPropertyKey &key) const { size_t operator()(const LabelPropertyKey &key) const {
return utils::HashCombine<storage::Label, storage::Property>{}( return utils::HashCombine<storage::LabelId, storage::PropertyId>{}(
key.first, key.second); key.first, key.second);
} }
}; };
typedef std::pair<std::optional<utils::Bound<PropertyValue>>, typedef std::pair<std::optional<utils::Bound<storage::PropertyValue>>,
std::optional<utils::Bound<PropertyValue>>> std::optional<utils::Bound<storage::PropertyValue>>>
BoundsKey; BoundsKey;
struct BoundsHash { struct BoundsHash {
@ -124,7 +124,7 @@ class VertexCountCache {
TDbAccessor *db_; TDbAccessor *db_;
std::optional<int64_t> vertices_count_; std::optional<int64_t> vertices_count_;
std::unordered_map<storage::Label, int64_t> label_vertex_count_; std::unordered_map<storage::LabelId, int64_t> label_vertex_count_;
std::unordered_map<LabelPropertyKey, int64_t, LabelPropertyHash> std::unordered_map<LabelPropertyKey, int64_t, LabelPropertyHash>
label_property_vertex_count_; label_property_vertex_count_;
std::unordered_map< std::unordered_map<

View File

@ -300,29 +300,29 @@ mgp_value::mgp_value(const query::TypedValue &tv, const mgp_graph *graph,
} }
} }
mgp_value::mgp_value(const PropertyValue &pv, utils::MemoryResource *m) mgp_value::mgp_value(const storage::PropertyValue &pv, utils::MemoryResource *m)
: memory(m) { : memory(m) {
switch (pv.type()) { switch (pv.type()) {
case PropertyValue::Type::Null: case storage::PropertyValue::Type::Null:
type = MGP_VALUE_TYPE_NULL; type = MGP_VALUE_TYPE_NULL;
break; break;
case PropertyValue::Type::Bool: case storage::PropertyValue::Type::Bool:
type = MGP_VALUE_TYPE_BOOL; type = MGP_VALUE_TYPE_BOOL;
bool_v = pv.ValueBool(); bool_v = pv.ValueBool();
break; break;
case PropertyValue::Type::Int: case storage::PropertyValue::Type::Int:
type = MGP_VALUE_TYPE_INT; type = MGP_VALUE_TYPE_INT;
int_v = pv.ValueInt(); int_v = pv.ValueInt();
break; break;
case PropertyValue::Type::Double: case storage::PropertyValue::Type::Double:
type = MGP_VALUE_TYPE_DOUBLE; type = MGP_VALUE_TYPE_DOUBLE;
double_v = pv.ValueDouble(); double_v = pv.ValueDouble();
break; break;
case PropertyValue::Type::String: case storage::PropertyValue::Type::String:
type = MGP_VALUE_TYPE_STRING; type = MGP_VALUE_TYPE_STRING;
new (&string_v) utils::pmr::string(pv.ValueString(), m); new (&string_v) utils::pmr::string(pv.ValueString(), m);
break; break;
case PropertyValue::Type::List: { case storage::PropertyValue::Type::List: {
// Fill the stack allocated container and then construct the actual member // Fill the stack allocated container and then construct the actual member
// value. This handles the case when filling the container throws // value. This handles the case when filling the container throws
// something and our destructor doesn't get called so member value isn't // something and our destructor doesn't get called so member value isn't
@ -337,7 +337,7 @@ mgp_value::mgp_value(const PropertyValue &pv, utils::MemoryResource *m)
list_v = allocator.new_object<mgp_list>(std::move(elems)); list_v = allocator.new_object<mgp_list>(std::move(elems));
break; break;
} }
case PropertyValue::Type::Map: { case storage::PropertyValue::Type::Map: {
// Fill the stack allocated container and then construct the actual member // Fill the stack allocated container and then construct the actual member
// value. This handles the case when filling the container throws // value. This handles the case when filling the container throws
// something and our destructor doesn't get called so member value isn't // something and our destructor doesn't get called so member value isn't
@ -922,7 +922,7 @@ mgp_label mgp_vertex_label_at(const mgp_vertex *v, size_t i) {
} }
int mgp_vertex_has_label_named(const mgp_vertex *v, const char *name) { int mgp_vertex_has_label_named(const mgp_vertex *v, const char *name) {
storage::Label label; storage::LabelId label;
try { try {
// This will allocate a std::string from `name`, which may throw // This will allocate a std::string from `name`, which may throw
// std::bad_alloc or std::length_error. This could be avoided with a // std::bad_alloc or std::length_error. This could be avoided with a

View File

@ -58,9 +58,9 @@ struct mgp_value {
mgp_value(const query::TypedValue &, const mgp_graph *, mgp_value(const query::TypedValue &, const mgp_graph *,
utils::MemoryResource *); utils::MemoryResource *);
/// Construct by copying PropertyValue using utils::MemoryResource. /// Construct by copying storage::PropertyValue using utils::MemoryResource.
/// @throw std::bad_alloc /// @throw std::bad_alloc
mgp_value(const PropertyValue &, utils::MemoryResource *); mgp_value(const storage::PropertyValue &, utils::MemoryResource *);
/// Copy construction without utils::MemoryResource is not allowed. /// Copy construction without utils::MemoryResource is not allowed.
mgp_value(const mgp_value &) = delete; mgp_value(const mgp_value &) = delete;
@ -468,7 +468,6 @@ struct mgp_vertices_iterator {
decltype(graph->impl->Vertices(graph->view)) vertices; decltype(graph->impl->Vertices(graph->view)) vertices;
decltype(vertices.begin()) current_it; decltype(vertices.begin()) current_it;
std::optional<mgp_vertex> current_v; std::optional<mgp_vertex> current_v;
}; };
struct mgp_type { struct mgp_type {

View File

@ -14,34 +14,34 @@
namespace query { namespace query {
TypedValue::TypedValue(const PropertyValue &value) TypedValue::TypedValue(const storage::PropertyValue &value)
// TODO: MemoryResource in PropertyValue // TODO: MemoryResource in storage::PropertyValue
: TypedValue(value, utils::NewDeleteResource()) {} : TypedValue(value, utils::NewDeleteResource()) {}
TypedValue::TypedValue(const PropertyValue &value, TypedValue::TypedValue(const storage::PropertyValue &value,
utils::MemoryResource *memory) utils::MemoryResource *memory)
: memory_(memory) { : memory_(memory) {
switch (value.type()) { switch (value.type()) {
case PropertyValue::Type::Null: case storage::PropertyValue::Type::Null:
type_ = Type::Null; type_ = Type::Null;
return; return;
case PropertyValue::Type::Bool: case storage::PropertyValue::Type::Bool:
type_ = Type::Bool; type_ = Type::Bool;
bool_v = value.ValueBool(); bool_v = value.ValueBool();
return; return;
case PropertyValue::Type::Int: case storage::PropertyValue::Type::Int:
type_ = Type::Int; type_ = Type::Int;
int_v = value.ValueInt(); int_v = value.ValueInt();
return; return;
case PropertyValue::Type::Double: case storage::PropertyValue::Type::Double:
type_ = Type::Double; type_ = Type::Double;
double_v = value.ValueDouble(); double_v = value.ValueDouble();
return; return;
case PropertyValue::Type::String: case storage::PropertyValue::Type::String:
type_ = Type::String; type_ = Type::String;
new (&string_v) TString(value.ValueString(), memory_); new (&string_v) TString(value.ValueString(), memory_);
return; return;
case PropertyValue::Type::List: { case storage::PropertyValue::Type::List: {
type_ = Type::List; type_ = Type::List;
const auto &vec = value.ValueList(); const auto &vec = value.ValueList();
new (&list_v) TVector(memory_); new (&list_v) TVector(memory_);
@ -49,7 +49,7 @@ TypedValue::TypedValue(const PropertyValue &value,
for (const auto &v : vec) list_v.emplace_back(v); for (const auto &v : vec) list_v.emplace_back(v);
return; return;
} }
case PropertyValue::Type::Map: { case storage::PropertyValue::Type::Map: {
type_ = Type::Map; type_ = Type::Map;
const auto &map = value.ValueMap(); const auto &map = value.ValueMap();
new (&map_v) TMap(memory_); new (&map_v) TMap(memory_);
@ -60,33 +60,34 @@ TypedValue::TypedValue(const PropertyValue &value,
LOG(FATAL) << "Unsupported type"; LOG(FATAL) << "Unsupported type";
} }
TypedValue::TypedValue(PropertyValue &&other) /* noexcept */ TypedValue::TypedValue(storage::PropertyValue &&other) /* noexcept */
// TODO: MemoryResource in PropertyValue, so this can be noexcept // TODO: MemoryResource in storage::PropertyValue, so this can be noexcept
: TypedValue(std::move(other), utils::NewDeleteResource()) {} : TypedValue(std::move(other), utils::NewDeleteResource()) {}
TypedValue::TypedValue(PropertyValue &&other, utils::MemoryResource *memory) TypedValue::TypedValue(storage::PropertyValue &&other,
utils::MemoryResource *memory)
: memory_(memory) { : memory_(memory) {
switch (other.type()) { switch (other.type()) {
case PropertyValue::Type::Null: case storage::PropertyValue::Type::Null:
type_ = Type::Null; type_ = Type::Null;
break; break;
case PropertyValue::Type::Bool: case storage::PropertyValue::Type::Bool:
type_ = Type::Bool; type_ = Type::Bool;
bool_v = other.ValueBool(); bool_v = other.ValueBool();
break; break;
case PropertyValue::Type::Int: case storage::PropertyValue::Type::Int:
type_ = Type::Int; type_ = Type::Int;
int_v = other.ValueInt(); int_v = other.ValueInt();
break; break;
case PropertyValue::Type::Double: case storage::PropertyValue::Type::Double:
type_ = Type::Double; type_ = Type::Double;
double_v = other.ValueDouble(); double_v = other.ValueDouble();
break; break;
case PropertyValue::Type::String: case storage::PropertyValue::Type::String:
type_ = Type::String; type_ = Type::String;
new (&string_v) TString(other.ValueString(), memory_); new (&string_v) TString(other.ValueString(), memory_);
break; break;
case PropertyValue::Type::List: { case storage::PropertyValue::Type::List: {
type_ = Type::List; type_ = Type::List;
auto &vec = other.ValueList(); auto &vec = other.ValueList();
new (&list_v) TVector(memory_); new (&list_v) TVector(memory_);
@ -94,7 +95,7 @@ TypedValue::TypedValue(PropertyValue &&other, utils::MemoryResource *memory)
for (auto &v : vec) list_v.emplace_back(std::move(v)); for (auto &v : vec) list_v.emplace_back(std::move(v));
break; break;
} }
case PropertyValue::Type::Map: { case storage::PropertyValue::Type::Map: {
type_ = Type::Map; type_ = Type::Map;
auto &map = other.ValueMap(); auto &map = other.ValueMap();
new (&map_v) TMap(memory_); new (&map_v) TMap(memory_);
@ -103,7 +104,7 @@ TypedValue::TypedValue(PropertyValue &&other, utils::MemoryResource *memory)
} }
} }
other = PropertyValue(); other = storage::PropertyValue();
} }
TypedValue::TypedValue(const TypedValue &other) TypedValue::TypedValue(const TypedValue &other)
@ -186,25 +187,25 @@ TypedValue::TypedValue(TypedValue &&other, utils::MemoryResource *memory)
other.DestroyValue(); other.DestroyValue();
} }
TypedValue::operator PropertyValue() const { TypedValue::operator storage::PropertyValue() const {
switch (type_) { switch (type_) {
case TypedValue::Type::Null: case TypedValue::Type::Null:
return PropertyValue(); return storage::PropertyValue();
case TypedValue::Type::Bool: case TypedValue::Type::Bool:
return PropertyValue(bool_v); return storage::PropertyValue(bool_v);
case TypedValue::Type::Int: case TypedValue::Type::Int:
return PropertyValue(int_v); return storage::PropertyValue(int_v);
case TypedValue::Type::Double: case TypedValue::Type::Double:
return PropertyValue(double_v); return storage::PropertyValue(double_v);
case TypedValue::Type::String: case TypedValue::Type::String:
return PropertyValue(std::string(string_v)); return storage::PropertyValue(std::string(string_v));
case TypedValue::Type::List: case TypedValue::Type::List:
return PropertyValue( return storage::PropertyValue(
std::vector<PropertyValue>(list_v.begin(), list_v.end())); std::vector<storage::PropertyValue>(list_v.begin(), list_v.end()));
case TypedValue::Type::Map: { case TypedValue::Type::Map: {
std::map<std::string, PropertyValue> map; std::map<std::string, storage::PropertyValue> map;
for (const auto &kv : map_v) map.emplace(kv.first, kv.second); for (const auto &kv : map_v) map.emplace(kv.first, kv.second);
return PropertyValue(std::move(map)); return storage::PropertyValue(std::move(map));
} }
default: default:
break; break;
@ -475,33 +476,33 @@ TypedValue &TypedValue::operator=(TypedValue &&other) noexcept(false) {
void TypedValue::DestroyValue() { void TypedValue::DestroyValue() {
switch (type_) { switch (type_) {
// destructor for primitive types does nothing // destructor for primitive types does nothing
case Type::Null: case Type::Null:
case Type::Bool: case Type::Bool:
case Type::Int: case Type::Int:
case Type::Double: case Type::Double:
break; break;
// we need to call destructors for non primitive types since we used // we need to call destructors for non primitive types since we used
// placement new // placement new
case Type::String: case Type::String:
string_v.~TString(); string_v.~TString();
break; break;
case Type::List: case Type::List:
list_v.~TVector(); list_v.~TVector();
break; break;
case Type::Map: case Type::Map:
map_v.~TMap(); map_v.~TMap();
break; break;
case Type::Vertex: case Type::Vertex:
vertex_v.~VertexAccessor(); vertex_v.~VertexAccessor();
break; break;
case Type::Edge: case Type::Edge:
edge_v.~EdgeAccessor(); edge_v.~EdgeAccessor();
break; break;
case Type::Path: case Type::Path:
path_v.~Path(); path_v.~Path();
break; break;
} }
type_ = TypedValue::Type::Null; type_ = TypedValue::Type::Null;

View File

@ -140,8 +140,8 @@ class TypedValue {
double_v = value; double_v = value;
} }
// conversion function to PropertyValue // conversion function to storage::PropertyValue
explicit operator PropertyValue() const; explicit operator storage::PropertyValue() const;
// copy constructors for non-primitive types // copy constructors for non-primitive types
explicit TypedValue(const std::string &value, utils::MemoryResource *memory = explicit TypedValue(const std::string &value, utils::MemoryResource *memory =
@ -262,10 +262,11 @@ class TypedValue {
} }
/** Construct a copy using default utils::NewDeleteResource() */ /** Construct a copy using default utils::NewDeleteResource() */
explicit TypedValue(const PropertyValue &value); explicit TypedValue(const storage::PropertyValue &value);
/** Construct a copy using the given utils::MemoryResource */ /** Construct a copy using the given utils::MemoryResource */
TypedValue(const PropertyValue &value, utils::MemoryResource *memory); TypedValue(const storage::PropertyValue &value,
utils::MemoryResource *memory);
// move constructors for non-primitive types // move constructors for non-primitive types
@ -408,13 +409,13 @@ class TypedValue {
* Default utils::NewDeleteResource() is used for allocations. After the move, * Default utils::NewDeleteResource() is used for allocations. After the move,
* other will be set to Null. * other will be set to Null.
*/ */
explicit TypedValue(PropertyValue &&other); explicit TypedValue(storage::PropertyValue &&other);
/** /**
* Construct with the value of other, but use the given utils::MemoryResource. * Construct with the value of other, but use the given utils::MemoryResource.
* After the move, other will be set to Null. * After the move, other will be set to Null.
*/ */
TypedValue(PropertyValue &&other, utils::MemoryResource *memory); TypedValue(storage::PropertyValue &&other, utils::MemoryResource *memory);
// copy assignment operators // copy assignment operators
TypedValue &operator=(const char *); TypedValue &operator=(const char *);
@ -490,7 +491,7 @@ class TypedValue {
bool IsNumeric() const; bool IsNumeric() const;
/** Convenience function for checking if this TypedValue can be converted into /** Convenience function for checking if this TypedValue can be converted into
* PropertyValue */ * storage::PropertyValue */
bool IsPropertyValue() const; bool IsPropertyValue() const;
utils::MemoryResource *GetMemoryResource() const { return memory_; } utils::MemoryResource *GetMemoryResource() const { return memory_; }

View File

@ -99,7 +99,7 @@ static auto CreateIndexedVertices(int index_count, int vertex_count,
for (int index = 0; index < index_count; ++index) { for (int index = 0; index < index_count; ++index) {
auto vertex = dba.CreateVertex(); auto vertex = dba.CreateVertex();
CHECK(vertex.AddLabel(label).HasValue()); CHECK(vertex.AddLabel(label).HasValue());
CHECK(vertex.SetProperty(prop, PropertyValue(index)).HasValue()); CHECK(vertex.SetProperty(prop, storage::PropertyValue(index)).HasValue());
} }
} }
CHECK(!dba.Commit().HasError()); CHECK(!dba.Commit().HasError());

View File

@ -143,7 +143,7 @@ class InteractiveDbAccessor {
int64_t VerticesCount() { return vertices_count_; } int64_t VerticesCount() { return vertices_count_; }
int64_t VerticesCount(storage::Label label_id) { int64_t VerticesCount(storage::LabelId label_id) {
auto label = dba_->LabelToName(label_id); auto label = dba_->LabelToName(label_id);
if (label_vertex_count_.find(label) == label_vertex_count_.end()) { if (label_vertex_count_.find(label) == label_vertex_count_.end()) {
label_vertex_count_[label] = ReadVertexCount("label '" + label + "'"); label_vertex_count_[label] = ReadVertexCount("label '" + label + "'");
@ -151,8 +151,8 @@ class InteractiveDbAccessor {
return label_vertex_count_.at(label); return label_vertex_count_.at(label);
} }
int64_t VerticesCount(storage::Label label_id, int64_t VerticesCount(storage::LabelId label_id,
storage::Property property_id) { storage::PropertyId property_id) {
auto label = dba_->LabelToName(label_id); auto label = dba_->LabelToName(label_id);
auto property = dba_->PropertyToName(property_id); auto property = dba_->PropertyToName(property_id);
auto key = std::make_pair(label, property); auto key = std::make_pair(label, property);
@ -164,8 +164,9 @@ class InteractiveDbAccessor {
return label_property_vertex_count_.at(key); return label_property_vertex_count_.at(key);
} }
int64_t VerticesCount(storage::Label label_id, storage::Property property_id, int64_t VerticesCount(storage::LabelId label_id,
const PropertyValue &value) { storage::PropertyId property_id,
const storage::PropertyValue &value) {
auto label = dba_->LabelToName(label_id); auto label = dba_->LabelToName(label_id);
auto property = dba_->PropertyToName(property_id); auto property = dba_->PropertyToName(property_id);
auto label_prop = std::make_pair(label, property); auto label_prop = std::make_pair(label, property);
@ -184,9 +185,9 @@ class InteractiveDbAccessor {
} }
int64_t VerticesCount( int64_t VerticesCount(
storage::Label label_id, storage::Property property_id, storage::LabelId label_id, storage::PropertyId property_id,
const std::optional<utils::Bound<PropertyValue>> lower, const std::optional<utils::Bound<storage::PropertyValue>> lower,
const std::optional<utils::Bound<PropertyValue>> upper) { const std::optional<utils::Bound<storage::PropertyValue>> upper) {
auto label = dba_->LabelToName(label_id); auto label = dba_->LabelToName(label_id);
auto property = dba_->PropertyToName(property_id); auto property = dba_->PropertyToName(property_id);
std::stringstream range_string; std::stringstream range_string;
@ -203,10 +204,10 @@ class InteractiveDbAccessor {
"' in range " + range_string.str()); "' in range " + range_string.str());
} }
bool LabelIndexExists(storage::Label label) { return true; } bool LabelIndexExists(storage::LabelId label) { return true; }
bool LabelPropertyIndexExists(storage::Label label_id, bool LabelPropertyIndexExists(storage::LabelId label_id,
storage::Property property_id) { storage::PropertyId property_id) {
auto label = dba_->LabelToName(label_id); auto label = dba_->LabelToName(label_id);
auto property = dba_->PropertyToName(property_id); auto property = dba_->PropertyToName(property_id);
auto key = std::make_pair(label, property); auto key = std::make_pair(label, property);

View File

@ -198,7 +198,7 @@ class Database {
virtual std::unique_ptr<query::plan::LogicalOperator> MakeBfsOperator( virtual std::unique_ptr<query::plan::LogicalOperator> MakeBfsOperator(
query::Symbol source_sym, query::Symbol sink_sym, query::Symbol edge_sym, query::Symbol source_sym, query::Symbol sink_sym, query::Symbol edge_sym,
query::EdgeAtom::Direction direction, query::EdgeAtom::Direction direction,
const std::vector<storage::EdgeType> &edge_types, const std::vector<storage::EdgeTypeId> &edge_types,
const std::shared_ptr<query::plan::LogicalOperator> &input, const std::shared_ptr<query::plan::LogicalOperator> &input,
bool existing_node, query::Expression *lower_bound, bool existing_node, query::Expression *lower_bound,
query::Expression *upper_bound, query::Expression *upper_bound,
@ -344,7 +344,7 @@ void BfsTest(Database *db, int lower_bound, int upper_bound,
// We block each entity in the graph and run BFS. // We block each entity in the graph and run BFS.
input_op = YieldEntities(&dba, vertices, edges, blocked_sym, nullptr); input_op = YieldEntities(&dba, vertices, edges, blocked_sym, nullptr);
filter_expr = IF(AND(NEQ(inner_node, blocked), NEQ(inner_edge, blocked)), filter_expr = IF(AND(NEQ(inner_node, blocked), NEQ(inner_edge, blocked)),
LITERAL(true), LITERAL(PropertyValue())); LITERAL(true), LITERAL(storage::PropertyValue()));
break; break;
case FilterLambdaType::USE_CTX: case FilterLambdaType::USE_CTX:
// We only block vertex #5 and run BFS. // We only block vertex #5 and run BFS.
@ -354,7 +354,7 @@ void BfsTest(Database *db, int lower_bound, int upper_bound,
{query::TypedValue(vertices[5])}}); {query::TypedValue(vertices[5])}});
filter_expr = NEQ(PROPERTY_LOOKUP(inner_node, PROPERTY_PAIR("id")), filter_expr = NEQ(PROPERTY_LOOKUP(inner_node, PROPERTY_PAIR("id")),
PARAMETER_LOOKUP(0)); PARAMETER_LOOKUP(0));
context.evaluation_context.parameters.Add(0, PropertyValue(5)); context.evaluation_context.parameters.Add(0, storage::PropertyValue(5));
break; break;
case FilterLambdaType::ERROR: case FilterLambdaType::ERROR:
// Evaluate to 42 for vertex #5 which is on worker 1. // Evaluate to 42 for vertex #5 which is on worker 1.
@ -372,7 +372,7 @@ void BfsTest(Database *db, int lower_bound, int upper_bound,
input_op = YieldVertices(&dba, vertices, sink_sym, input_op); input_op = YieldVertices(&dba, vertices, sink_sym, input_op);
} }
std::vector<storage::EdgeType> storage_edge_types; std::vector<storage::EdgeTypeId> storage_edge_types;
for (const auto &t : edge_types) { for (const auto &t : edge_types) {
storage_edge_types.push_back(dba.NameToEdgeType(t)); storage_edge_types.push_back(dba.NameToEdgeType(t));
} }

View File

@ -12,7 +12,7 @@ class SingleNodeDb : public Database {
std::unique_ptr<LogicalOperator> MakeBfsOperator( std::unique_ptr<LogicalOperator> MakeBfsOperator(
Symbol source_sym, Symbol sink_sym, Symbol edge_sym, Symbol source_sym, Symbol sink_sym, Symbol edge_sym,
EdgeAtom::Direction direction, EdgeAtom::Direction direction,
const std::vector<storage::EdgeType> &edge_types, const std::vector<storage::EdgeTypeId> &edge_types,
const std::shared_ptr<LogicalOperator> &input, bool existing_node, const std::shared_ptr<LogicalOperator> &input, bool existing_node,
Expression *lower_bound, Expression *upper_bound, Expression *lower_bound, Expression *upper_bound,
const ExpansionLambda &filter_lambda) override { const ExpansionLambda &filter_lambda) override {
@ -34,7 +34,7 @@ class SingleNodeDb : public Database {
auto vertex = dba->InsertVertex(); auto vertex = dba->InsertVertex();
CHECK(vertex CHECK(vertex
.SetProperty(dba->NameToProperty("id"), .SetProperty(dba->NameToProperty("id"),
PropertyValue(static_cast<int64_t>(id))) storage::PropertyValue(static_cast<int64_t>(id)))
.HasValue()); .HasValue());
vertex_addr.push_back(vertex); vertex_addr.push_back(vertex);
} }
@ -46,9 +46,11 @@ class SingleNodeDb : public Database {
auto &from = vertex_addr[u]; auto &from = vertex_addr[u];
auto &to = vertex_addr[v]; auto &to = vertex_addr[v];
auto edge = dba->InsertEdge(&from, &to, dba->NameToEdgeType(type)); auto edge = dba->InsertEdge(&from, &to, dba->NameToEdgeType(type));
CHECK(edge->SetProperty(dba->NameToProperty("from"), PropertyValue(u)) CHECK(edge->SetProperty(dba->NameToProperty("from"),
storage::PropertyValue(u))
.HasValue()); .HasValue());
CHECK(edge->SetProperty(dba->NameToProperty("to"), PropertyValue(v)) CHECK(edge->SetProperty(dba->NameToProperty("to"),
storage::PropertyValue(v))
.HasValue()); .HasValue());
edge_addr.push_back(*edge); edge_addr.push_back(*edge);
} }

View File

@ -173,7 +173,7 @@ TEST(BoltEncoder, VertexAndEdge) {
ASSERT_TRUE(va1.AddLabel(l2).HasValue()); ASSERT_TRUE(va1.AddLabel(l2).HasValue());
auto p1 = dba.NameToProperty("prop1"); auto p1 = dba.NameToProperty("prop1");
auto p2 = dba.NameToProperty("prop2"); auto p2 = dba.NameToProperty("prop2");
PropertyValue pv1(12), pv2(200); storage::PropertyValue pv1(12), pv2(200);
ASSERT_TRUE(va1.SetProperty(p1, pv1).HasValue()); ASSERT_TRUE(va1.SetProperty(p1, pv1).HasValue());
ASSERT_TRUE(va1.SetProperty(p2, pv2).HasValue()); ASSERT_TRUE(va1.SetProperty(p2, pv2).HasValue());
@ -182,7 +182,7 @@ TEST(BoltEncoder, VertexAndEdge) {
auto ea = dba.CreateEdge(&va1, &va2, et); auto ea = dba.CreateEdge(&va1, &va2, et);
auto p3 = dba.NameToProperty("prop3"); auto p3 = dba.NameToProperty("prop3");
auto p4 = dba.NameToProperty("prop4"); auto p4 = dba.NameToProperty("prop4");
PropertyValue pv3(42), pv4(1234); storage::PropertyValue pv3(42), pv4(1234);
ASSERT_TRUE(ea->SetProperty(p3, pv3).HasValue()); ASSERT_TRUE(ea->SetProperty(p3, pv3).HasValue());
ASSERT_TRUE(ea->SetProperty(p4, pv4).HasValue()); ASSERT_TRUE(ea->SetProperty(p4, pv4).HasValue());

View File

@ -36,8 +36,9 @@ class InterpreterTest : public ::testing::Test {
* *
* Return the query stream. * Return the query stream.
*/ */
auto Interpret(const std::string &query, auto Interpret(
const std::map<std::string, PropertyValue> &params = {}) { const std::string &query,
const std::map<std::string, storage::PropertyValue> &params = {}) {
ResultStreamFaker stream(&db_); ResultStreamFaker stream(&db_);
auto [header, _] = interpreter_.Prepare(query, params); auto [header, _] = interpreter_.Prepare(query, params);
@ -109,8 +110,9 @@ TEST_F(InterpreterTest, AstCache) {
// Run query with same ast multiple times with different parameters. // Run query with same ast multiple times with different parameters.
TEST_F(InterpreterTest, Parameters) { TEST_F(InterpreterTest, Parameters) {
{ {
auto stream = Interpret("RETURN $2 + $`a b`", {{"2", PropertyValue(10)}, auto stream =
{"a b", PropertyValue(15)}}); Interpret("RETURN $2 + $`a b`", {{"2", storage::PropertyValue(10)},
{"a b", storage::PropertyValue(15)}});
ASSERT_EQ(stream.GetHeader().size(), 1U); ASSERT_EQ(stream.GetHeader().size(), 1U);
EXPECT_EQ(stream.GetHeader()[0], "$2 + $`a b`"); EXPECT_EQ(stream.GetHeader()[0], "$2 + $`a b`");
ASSERT_EQ(stream.GetResults().size(), 1U); ASSERT_EQ(stream.GetResults().size(), 1U);
@ -119,9 +121,10 @@ TEST_F(InterpreterTest, Parameters) {
} }
{ {
// Not needed parameter. // Not needed parameter.
auto stream = Interpret("RETURN $2 + $`a b`", {{"2", PropertyValue(10)}, auto stream =
{"a b", PropertyValue(15)}, Interpret("RETURN $2 + $`a b`", {{"2", storage::PropertyValue(10)},
{"c", PropertyValue(10)}}); {"a b", storage::PropertyValue(15)},
{"c", storage::PropertyValue(10)}});
ASSERT_EQ(stream.GetHeader().size(), 1U); ASSERT_EQ(stream.GetHeader().size(), 1U);
EXPECT_EQ(stream.GetHeader()[0], "$2 + $`a b`"); EXPECT_EQ(stream.GetHeader()[0], "$2 + $`a b`");
ASSERT_EQ(stream.GetResults().size(), 1U); ASSERT_EQ(stream.GetResults().size(), 1U);
@ -130,9 +133,9 @@ TEST_F(InterpreterTest, Parameters) {
} }
{ {
// Cached ast, different parameters. // Cached ast, different parameters.
auto stream = auto stream = Interpret("RETURN $2 + $`a b`",
Interpret("RETURN $2 + $`a b`", {{"2", storage::PropertyValue("da")},
{{"2", PropertyValue("da")}, {"a b", PropertyValue("ne")}}); {"a b", storage::PropertyValue("ne")}});
ASSERT_EQ(stream.GetResults().size(), 1U); ASSERT_EQ(stream.GetResults().size(), 1U);
ASSERT_EQ(stream.GetResults()[0].size(), 1U); ASSERT_EQ(stream.GetResults()[0].size(), 1U);
ASSERT_EQ(stream.GetResults()[0][0].ValueString(), "dane"); ASSERT_EQ(stream.GetResults()[0][0].ValueString(), "dane");
@ -141,8 +144,9 @@ TEST_F(InterpreterTest, Parameters) {
// Non-primitive literal. // Non-primitive literal.
auto stream = Interpret( auto stream = Interpret(
"RETURN $2", "RETURN $2",
{{"2", PropertyValue(std::vector<PropertyValue>{ {{"2", storage::PropertyValue(std::vector<storage::PropertyValue>{
PropertyValue(5), PropertyValue(2), PropertyValue(3)})}}); storage::PropertyValue(5), storage::PropertyValue(2),
storage::PropertyValue(3)})}});
ASSERT_EQ(stream.GetResults().size(), 1U); ASSERT_EQ(stream.GetResults().size(), 1U);
ASSERT_EQ(stream.GetResults()[0].size(), 1U); ASSERT_EQ(stream.GetResults()[0].size(), 1U);
auto result = query::test_common::ToIntList( auto result = query::test_common::ToIntList(
@ -151,9 +155,10 @@ TEST_F(InterpreterTest, Parameters) {
} }
{ {
// Cached ast, unprovided parameter. // Cached ast, unprovided parameter.
ASSERT_THROW(Interpret("RETURN $2 + $`a b`", {{"2", PropertyValue("da")}, ASSERT_THROW(
{"ab", PropertyValue("ne")}}), Interpret("RETURN $2 + $`a b`", {{"2", storage::PropertyValue("da")},
query::UnprovidedParameterError); {"ab", storage::PropertyValue("ne")}}),
query::UnprovidedParameterError);
} }
} }
@ -177,10 +182,11 @@ TEST_F(InterpreterTest, Bfs) {
query::DbAccessor dba(&storage_dba); query::DbAccessor dba(&storage_dba);
auto add_node = [&](int level, bool reachable) { auto add_node = [&](int level, bool reachable) {
auto node = dba.InsertVertex(); auto node = dba.InsertVertex();
CHECK(node.SetProperty(dba.NameToProperty(kId), PropertyValue(id++)) CHECK(node.SetProperty(dba.NameToProperty(kId),
storage::PropertyValue(id++))
.HasValue()); .HasValue());
CHECK(node.SetProperty(dba.NameToProperty(kReachable), CHECK(node.SetProperty(dba.NameToProperty(kReachable),
PropertyValue(reachable)) storage::PropertyValue(reachable))
.HasValue()); .HasValue());
levels[level].push_back(node); levels[level].push_back(node);
return node; return node;
@ -189,7 +195,7 @@ TEST_F(InterpreterTest, Bfs) {
auto add_edge = [&](auto &v1, auto &v2, bool reachable) { auto add_edge = [&](auto &v1, auto &v2, bool reachable) {
auto edge = dba.InsertEdge(&v1, &v2, dba.NameToEdgeType("edge")); auto edge = dba.InsertEdge(&v1, &v2, dba.NameToEdgeType("edge"));
CHECK(edge->SetProperty(dba.NameToProperty(kReachable), CHECK(edge->SetProperty(dba.NameToProperty(kReachable),
PropertyValue(reachable)) storage::PropertyValue(reachable))
.HasValue()); .HasValue());
}; };
@ -361,7 +367,7 @@ TEST_F(InterpreterTest, ExplainQueryWithParams) {
EXPECT_EQ(interpreter_context_.plan_cache.size(), 0U); EXPECT_EQ(interpreter_context_.plan_cache.size(), 0U);
EXPECT_EQ(interpreter_context_.ast_cache.size(), 0U); EXPECT_EQ(interpreter_context_.ast_cache.size(), 0U);
auto stream = Interpret("EXPLAIN MATCH (n) WHERE n.id = $id RETURN *;", auto stream = Interpret("EXPLAIN MATCH (n) WHERE n.id = $id RETURN *;",
{{"id", PropertyValue(42)}}); {{"id", storage::PropertyValue(42)}});
ASSERT_EQ(stream.GetHeader().size(), 1U); ASSERT_EQ(stream.GetHeader().size(), 1U);
EXPECT_EQ(stream.GetHeader().front(), "QUERY PLAN"); EXPECT_EQ(stream.GetHeader().front(), "QUERY PLAN");
std::vector<std::string> expected_rows{" * Produce {n}", " * Filter", std::vector<std::string> expected_rows{" * Produce {n}", " * Filter",
@ -378,7 +384,7 @@ TEST_F(InterpreterTest, ExplainQueryWithParams) {
// We should have AST cache for EXPLAIN ... and for inner MATCH ... // We should have AST cache for EXPLAIN ... and for inner MATCH ...
EXPECT_EQ(interpreter_context_.ast_cache.size(), 2U); EXPECT_EQ(interpreter_context_.ast_cache.size(), 2U);
Interpret("MATCH (n) WHERE n.id = $id RETURN *;", Interpret("MATCH (n) WHERE n.id = $id RETURN *;",
{{"id", PropertyValue("something else")}}); {{"id", storage::PropertyValue("something else")}});
EXPECT_EQ(interpreter_context_.plan_cache.size(), 1U); EXPECT_EQ(interpreter_context_.plan_cache.size(), 1U);
EXPECT_EQ(interpreter_context_.ast_cache.size(), 2U); EXPECT_EQ(interpreter_context_.ast_cache.size(), 2U);
} }
@ -411,7 +417,7 @@ TEST_F(InterpreterTest, ProfileQueryWithParams) {
EXPECT_EQ(interpreter_context_.plan_cache.size(), 0U); EXPECT_EQ(interpreter_context_.plan_cache.size(), 0U);
EXPECT_EQ(interpreter_context_.ast_cache.size(), 0U); EXPECT_EQ(interpreter_context_.ast_cache.size(), 0U);
auto stream = Interpret("PROFILE MATCH (n) WHERE n.id = $id RETURN *;", auto stream = Interpret("PROFILE MATCH (n) WHERE n.id = $id RETURN *;",
{{"id", PropertyValue(42)}}); {{"id", storage::PropertyValue(42)}});
std::vector<std::string> expected_header{"OPERATOR", "ACTUAL HITS", std::vector<std::string> expected_header{"OPERATOR", "ACTUAL HITS",
"RELATIVE TIME", "ABSOLUTE TIME"}; "RELATIVE TIME", "ABSOLUTE TIME"};
EXPECT_EQ(stream.GetHeader(), expected_header); EXPECT_EQ(stream.GetHeader(), expected_header);
@ -429,7 +435,7 @@ TEST_F(InterpreterTest, ProfileQueryWithParams) {
// We should have AST cache for PROFILE ... and for inner MATCH ... // We should have AST cache for PROFILE ... and for inner MATCH ...
EXPECT_EQ(interpreter_context_.ast_cache.size(), 2U); EXPECT_EQ(interpreter_context_.ast_cache.size(), 2U);
Interpret("MATCH (n) WHERE n.id = $id RETURN *;", Interpret("MATCH (n) WHERE n.id = $id RETURN *;",
{{"id", PropertyValue("something else")}}); {{"id", storage::PropertyValue("something else")}});
EXPECT_EQ(interpreter_context_.plan_cache.size(), 1U); EXPECT_EQ(interpreter_context_.plan_cache.size(), 1U);
EXPECT_EQ(interpreter_context_.ast_cache.size(), 2U); EXPECT_EQ(interpreter_context_.ast_cache.size(), 2U);
} }

View File

@ -86,7 +86,7 @@ class QueryCostEstimator : public ::testing::Test {
template <typename TValue> template <typename TValue>
Expression *Parameter(TValue value) { Expression *Parameter(TValue value) {
int token_position = parameters_.size(); int token_position = parameters_.size();
parameters_.Add(token_position, PropertyValue(value)); parameters_.Add(token_position, storage::PropertyValue(value));
return storage_.Create<ParameterLookup>(token_position); return storage_.Create<ParameterLookup>(token_position);
} }

View File

@ -27,13 +27,13 @@ struct DatabaseState {
struct Vertex { struct Vertex {
int64_t id; int64_t id;
std::set<std::string> labels; std::set<std::string> labels;
std::map<std::string, PropertyValue> props; std::map<std::string, storage::PropertyValue> props;
}; };
struct Edge { struct Edge {
int64_t from, to; int64_t from, to;
std::string edge_type; std::string edge_type;
std::map<std::string, PropertyValue> props; std::map<std::string, storage::PropertyValue> props;
}; };
struct LabelItem { struct LabelItem {
@ -120,7 +120,7 @@ DatabaseState GetState(storage::Storage *db) {
for (const auto &label : *maybe_labels) { for (const auto &label : *maybe_labels) {
labels.insert(dba.LabelToName(label)); labels.insert(dba.LabelToName(label));
} }
std::map<std::string, PropertyValue> props; std::map<std::string, storage::PropertyValue> props;
auto maybe_properties = vertex.Properties(storage::View::NEW); auto maybe_properties = vertex.Properties(storage::View::NEW);
CHECK(maybe_properties.HasValue()); CHECK(maybe_properties.HasValue());
for (const auto &kv : *maybe_properties) { for (const auto &kv : *maybe_properties) {
@ -139,7 +139,7 @@ DatabaseState GetState(storage::Storage *db) {
CHECK(maybe_edges.HasValue()); CHECK(maybe_edges.HasValue());
for (const auto &edge : *maybe_edges) { for (const auto &edge : *maybe_edges) {
const auto &edge_type_name = dba.EdgeTypeToName(edge.EdgeType()); const auto &edge_type_name = dba.EdgeTypeToName(edge.EdgeType());
std::map<std::string, PropertyValue> props; std::map<std::string, storage::PropertyValue> props;
auto maybe_properties = edge.Properties(storage::View::NEW); auto maybe_properties = edge.Properties(storage::View::NEW);
CHECK(maybe_properties.HasValue()); CHECK(maybe_properties.HasValue());
for (const auto &kv : *maybe_properties) { for (const auto &kv : *maybe_properties) {
@ -192,10 +192,10 @@ auto Execute(storage::Storage *db, const std::string &query) {
return stream; return stream;
} }
VertexAccessor CreateVertex(storage::Storage::Accessor *dba, VertexAccessor CreateVertex(
const std::vector<std::string> &labels, storage::Storage::Accessor *dba, const std::vector<std::string> &labels,
const std::map<std::string, PropertyValue> &props, const std::map<std::string, storage::PropertyValue> &props,
bool add_property_id = true) { bool add_property_id = true) {
CHECK(dba); CHECK(dba);
auto vertex = dba->CreateVertex(); auto vertex = dba->CreateVertex();
for (const auto &label_name : labels) { for (const auto &label_name : labels) {
@ -208,16 +208,17 @@ VertexAccessor CreateVertex(storage::Storage::Accessor *dba,
if (add_property_id) { if (add_property_id) {
CHECK(vertex CHECK(vertex
.SetProperty(dba->NameToProperty(kPropertyId), .SetProperty(dba->NameToProperty(kPropertyId),
PropertyValue(vertex.Gid().AsInt())) storage::PropertyValue(vertex.Gid().AsInt()))
.HasValue()); .HasValue());
} }
return vertex; return vertex;
} }
EdgeAccessor CreateEdge(storage::Storage::Accessor *dba, VertexAccessor *from, EdgeAccessor CreateEdge(
VertexAccessor *to, const std::string &edge_type_name, storage::Storage::Accessor *dba, VertexAccessor *from, VertexAccessor *to,
const std::map<std::string, PropertyValue> &props, const std::string &edge_type_name,
bool add_property_id = true) { const std::map<std::string, storage::PropertyValue> &props,
bool add_property_id = true) {
CHECK(dba); CHECK(dba);
auto edge = dba->CreateEdge(from, to, dba->NameToEdgeType(edge_type_name)); auto edge = dba->CreateEdge(from, to, dba->NameToEdgeType(edge_type_name));
CHECK(edge.HasValue()); CHECK(edge.HasValue());
@ -227,7 +228,7 @@ EdgeAccessor CreateEdge(storage::Storage::Accessor *dba, VertexAccessor *from,
} }
if (add_property_id) { if (add_property_id) {
CHECK(edge->SetProperty(dba->NameToProperty(kPropertyId), CHECK(edge->SetProperty(dba->NameToProperty(kPropertyId),
PropertyValue(edge->Gid().AsInt())) storage::PropertyValue(edge->Gid().AsInt()))
.HasValue()); .HasValue());
} }
return *edge; return *edge;
@ -335,7 +336,7 @@ TEST(DumpTest, VertexWithSingleProperty) {
storage::Storage db; storage::Storage db;
{ {
auto dba = db.Access(); auto dba = db.Access();
CreateVertex(&dba, {}, {{"prop", PropertyValue(42)}}, false); CreateVertex(&dba, {}, {{"prop", storage::PropertyValue(42)}}, false);
ASSERT_FALSE(dba.Commit().HasError()); ASSERT_FALSE(dba.Commit().HasError());
} }
@ -453,7 +454,8 @@ TEST(DumpTest, EdgeWithProperties) {
auto dba = db.Access(); auto dba = db.Access();
auto u = CreateVertex(&dba, {}, {}, false); auto u = CreateVertex(&dba, {}, {}, false);
auto v = CreateVertex(&dba, {}, {}, false); auto v = CreateVertex(&dba, {}, {}, false);
CreateEdge(&dba, &u, &v, "EdgeType", {{"prop", PropertyValue(13)}}, false); CreateEdge(&dba, &u, &v, "EdgeType", {{"prop", storage::PropertyValue(13)}},
false);
ASSERT_FALSE(dba.Commit().HasError()); ASSERT_FALSE(dba.Commit().HasError());
} }
@ -480,7 +482,8 @@ TEST(DumpTest, IndicesKeys) {
storage::Storage db; storage::Storage db;
{ {
auto dba = db.Access(); auto dba = db.Access();
CreateVertex(&dba, {"Label1", "Label2"}, {{"p", PropertyValue(1)}}, false); CreateVertex(&dba, {"Label1", "Label2"}, {{"p", storage::PropertyValue(1)}},
false);
ASSERT_FALSE(dba.Commit().HasError()); ASSERT_FALSE(dba.Commit().HasError());
} }
ASSERT_TRUE( ASSERT_TRUE(
@ -508,7 +511,7 @@ TEST(DumpTest, ExistenceConstraints) {
storage::Storage db; storage::Storage db;
{ {
auto dba = db.Access(); auto dba = db.Access();
CreateVertex(&dba, {"Label"}, {{"prop", PropertyValue(1)}}, false); CreateVertex(&dba, {"Label"}, {{"prop", storage::PropertyValue(1)}}, false);
ASSERT_FALSE(dba.Commit().HasError()); ASSERT_FALSE(dba.Commit().HasError());
} }
{ {
@ -539,11 +542,12 @@ TEST(DumpTest, CheckStateVertexWithMultipleProperties) {
storage::Storage db; storage::Storage db;
{ {
auto dba = db.Access(); auto dba = db.Access();
std::map<std::string, PropertyValue> prop1 = { std::map<std::string, storage::PropertyValue> prop1 = {
{"nested1", PropertyValue(1337)}, {"nested2", PropertyValue(3.14)}}; {"nested1", storage::PropertyValue(1337)},
CreateVertex( {"nested2", storage::PropertyValue(3.14)}};
&dba, {"Label1", "Label2"}, CreateVertex(&dba, {"Label1", "Label2"},
{{"prop1", PropertyValue(prop1)}, {"prop2", PropertyValue("$'\t'")}}); {{"prop1", storage::PropertyValue(prop1)},
{"prop2", storage::PropertyValue("$'\t'")}});
ASSERT_FALSE(dba.Commit().HasError()); ASSERT_FALSE(dba.Commit().HasError());
} }
@ -572,22 +576,28 @@ TEST(DumpTest, CheckStateSimpleGraph) {
storage::Storage db; storage::Storage db;
{ {
auto dba = db.Access(); auto dba = db.Access();
auto u = CreateVertex(&dba, {"Person"}, {{"name", PropertyValue("Ivan")}}); auto u = CreateVertex(&dba, {"Person"},
auto v = CreateVertex(&dba, {"Person"}, {{"name", PropertyValue("Josko")}}); {{"name", storage::PropertyValue("Ivan")}});
auto w = CreateVertex( auto v = CreateVertex(&dba, {"Person"},
&dba, {"Person"}, {{"name", storage::PropertyValue("Josko")}});
{{"name", PropertyValue("Bosko")}, {"id", PropertyValue(0)}}); auto w = CreateVertex(&dba, {"Person"},
auto z = CreateVertex( {{"name", storage::PropertyValue("Bosko")},
&dba, {"Person"}, {"id", storage::PropertyValue(0)}});
{{"name", PropertyValue("Buha")}, {"id", PropertyValue(1)}}); auto z = CreateVertex(&dba, {"Person"},
{{"name", storage::PropertyValue("Buha")},
{"id", storage::PropertyValue(1)}});
CreateEdge(&dba, &u, &v, "Knows", {}); CreateEdge(&dba, &u, &v, "Knows", {});
CreateEdge(&dba, &v, &w, "Knows", {{"how_long", PropertyValue(5)}}); CreateEdge(&dba, &v, &w, "Knows",
CreateEdge(&dba, &w, &u, "Knows", {{"how", PropertyValue("distant past")}}); {{"how_long", storage::PropertyValue(5)}});
CreateEdge(&dba, &w, &u, "Knows",
{{"how", storage::PropertyValue("distant past")}});
CreateEdge(&dba, &v, &u, "Knows", {}); CreateEdge(&dba, &v, &u, "Knows", {});
CreateEdge(&dba, &v, &u, "Likes", {}); CreateEdge(&dba, &v, &u, "Likes", {});
CreateEdge(&dba, &z, &u, "Knows", {}); CreateEdge(&dba, &z, &u, "Knows", {});
CreateEdge(&dba, &w, &z, "Knows", {{"how", PropertyValue("school")}}); CreateEdge(&dba, &w, &z, "Knows",
CreateEdge(&dba, &w, &z, "Likes", {{"how", PropertyValue("very much")}}); {{"how", storage::PropertyValue("school")}});
CreateEdge(&dba, &w, &z, "Likes",
{{"how", storage::PropertyValue("very much")}});
ASSERT_FALSE(dba.Commit().HasError()); ASSERT_FALSE(dba.Commit().HasError());
} }
{ {

View File

@ -121,20 +121,20 @@ TEST_F(ExpressionEvaluatorTest, AndOperatorNull) {
{ {
// Null doesn't short circuit // Null doesn't short circuit
auto *op = storage.Create<AndOperator>( auto *op = storage.Create<AndOperator>(
storage.Create<PrimitiveLiteral>(PropertyValue()), storage.Create<PrimitiveLiteral>(storage::PropertyValue()),
storage.Create<PrimitiveLiteral>(5)); storage.Create<PrimitiveLiteral>(5));
EXPECT_THROW(Eval(op), QueryRuntimeException); EXPECT_THROW(Eval(op), QueryRuntimeException);
} }
{ {
auto *op = storage.Create<AndOperator>( auto *op = storage.Create<AndOperator>(
storage.Create<PrimitiveLiteral>(PropertyValue()), storage.Create<PrimitiveLiteral>(storage::PropertyValue()),
storage.Create<PrimitiveLiteral>(true)); storage.Create<PrimitiveLiteral>(true));
auto value = Eval(op); auto value = Eval(op);
EXPECT_TRUE(value.IsNull()); EXPECT_TRUE(value.IsNull());
} }
{ {
auto *op = storage.Create<AndOperator>( auto *op = storage.Create<AndOperator>(
storage.Create<PrimitiveLiteral>(PropertyValue()), storage.Create<PrimitiveLiteral>(storage::PropertyValue()),
storage.Create<PrimitiveLiteral>(false)); storage.Create<PrimitiveLiteral>(false));
auto value = Eval(op); auto value = Eval(op);
ASSERT_TRUE(value.IsBool()); ASSERT_TRUE(value.IsBool());
@ -295,7 +295,7 @@ TEST_F(ExpressionEvaluatorTest, InListOperator) {
} }
{ {
auto *list_literal = storage.Create<ListLiteral>(std::vector<Expression *>{ auto *list_literal = storage.Create<ListLiteral>(std::vector<Expression *>{
storage.Create<PrimitiveLiteral>(PropertyValue()), storage.Create<PrimitiveLiteral>(storage::PropertyValue()),
storage.Create<PrimitiveLiteral>(2), storage.Create<PrimitiveLiteral>(2),
storage.Create<PrimitiveLiteral>("a")}); storage.Create<PrimitiveLiteral>("a")});
// Element doesn't exist in list with null element. // Element doesn't exist in list with null element.
@ -308,21 +308,22 @@ TEST_F(ExpressionEvaluatorTest, InListOperator) {
// Null list. // Null list.
auto *op = storage.Create<InListOperator>( auto *op = storage.Create<InListOperator>(
storage.Create<PrimitiveLiteral>("x"), storage.Create<PrimitiveLiteral>("x"),
storage.Create<PrimitiveLiteral>(PropertyValue())); storage.Create<PrimitiveLiteral>(storage::PropertyValue()));
auto value = Eval(op); auto value = Eval(op);
EXPECT_TRUE(value.IsNull()); EXPECT_TRUE(value.IsNull());
} }
{ {
// Null literal. // Null literal.
auto *op = storage.Create<InListOperator>( auto *op = storage.Create<InListOperator>(
storage.Create<PrimitiveLiteral>(PropertyValue()), list_literal); storage.Create<PrimitiveLiteral>(storage::PropertyValue()),
list_literal);
auto value = Eval(op); auto value = Eval(op);
EXPECT_TRUE(value.IsNull()); EXPECT_TRUE(value.IsNull());
} }
{ {
// Null literal, empty list. // Null literal, empty list.
auto *op = storage.Create<InListOperator>( auto *op = storage.Create<InListOperator>(
storage.Create<PrimitiveLiteral>(PropertyValue()), storage.Create<PrimitiveLiteral>(storage::PropertyValue()),
storage.Create<ListLiteral>(std::vector<Expression *>())); storage.Create<ListLiteral>(std::vector<Expression *>()));
auto value = Eval(op); auto value = Eval(op);
EXPECT_FALSE(value.ValueBool()); EXPECT_FALSE(value.ValueBool());
@ -365,7 +366,7 @@ TEST_F(ExpressionEvaluatorTest, ListIndexing) {
{ {
// Indexing with one operator being null. // Indexing with one operator being null.
auto *op = storage.Create<SubscriptOperator>( auto *op = storage.Create<SubscriptOperator>(
storage.Create<PrimitiveLiteral>(PropertyValue()), storage.Create<PrimitiveLiteral>(storage::PropertyValue()),
storage.Create<PrimitiveLiteral>(-2)); storage.Create<PrimitiveLiteral>(-2));
auto value = Eval(op); auto value = Eval(op);
EXPECT_TRUE(value.IsNull()); EXPECT_TRUE(value.IsNull());
@ -407,7 +408,8 @@ TEST_F(ExpressionEvaluatorTest, MapIndexing) {
{ {
// Indexing with Null. // Indexing with Null.
auto *op = storage.Create<SubscriptOperator>( auto *op = storage.Create<SubscriptOperator>(
map_literal, storage.Create<PrimitiveLiteral>(PropertyValue())); map_literal,
storage.Create<PrimitiveLiteral>(storage::PropertyValue()));
auto value = Eval(op); auto value = Eval(op);
EXPECT_TRUE(value.IsNull()); EXPECT_TRUE(value.IsNull());
} }
@ -419,8 +421,8 @@ TEST_F(ExpressionEvaluatorTest, VertexAndEdgeIndexing) {
auto v1 = dba.InsertVertex(); auto v1 = dba.InsertVertex();
auto e11 = dba.InsertEdge(&v1, &v1, edge_type); auto e11 = dba.InsertEdge(&v1, &v1, edge_type);
ASSERT_TRUE(e11.HasValue()); ASSERT_TRUE(e11.HasValue());
ASSERT_TRUE(v1.SetProperty(prop, PropertyValue(42)).HasValue()); ASSERT_TRUE(v1.SetProperty(prop, storage::PropertyValue(42)).HasValue());
ASSERT_TRUE(e11->SetProperty(prop, PropertyValue(43)).HasValue()); ASSERT_TRUE(e11->SetProperty(prop, storage::PropertyValue(43)).HasValue());
dba.AdvanceCommand(); dba.AdvanceCommand();
auto *vertex_id = CreateIdentifierWithValue("v1", TypedValue(v1)); auto *vertex_id = CreateIdentifierWithValue("v1", TypedValue(v1));
@ -462,12 +464,12 @@ TEST_F(ExpressionEvaluatorTest, VertexAndEdgeIndexing) {
{ {
// Indexing with Null. // Indexing with Null.
auto *op1 = storage.Create<SubscriptOperator>( auto *op1 = storage.Create<SubscriptOperator>(
vertex_id, storage.Create<PrimitiveLiteral>(PropertyValue())); vertex_id, storage.Create<PrimitiveLiteral>(storage::PropertyValue()));
auto value1 = Eval(op1); auto value1 = Eval(op1);
EXPECT_TRUE(value1.IsNull()); EXPECT_TRUE(value1.IsNull());
auto *op2 = storage.Create<SubscriptOperator>( auto *op2 = storage.Create<SubscriptOperator>(
edge_id, storage.Create<PrimitiveLiteral>(PropertyValue())); edge_id, storage.Create<PrimitiveLiteral>(storage::PropertyValue()));
auto value2 = Eval(op2); auto value2 = Eval(op2);
EXPECT_TRUE(value2.IsNull()); EXPECT_TRUE(value2.IsNull());
} }
@ -535,7 +537,8 @@ TEST_F(ExpressionEvaluatorTest, ListSlicingOperator) {
{ {
// Bound of illegal type and null value bound. // Bound of illegal type and null value bound.
auto *op = storage.Create<ListSlicingOperator>( auto *op = storage.Create<ListSlicingOperator>(
list_literal, storage.Create<PrimitiveLiteral>(PropertyValue()), list_literal,
storage.Create<PrimitiveLiteral>(storage::PropertyValue()),
storage.Create<PrimitiveLiteral>("mirko")); storage.Create<PrimitiveLiteral>("mirko"));
EXPECT_THROW(Eval(op), QueryRuntimeException); EXPECT_THROW(Eval(op), QueryRuntimeException);
} }
@ -549,7 +552,7 @@ TEST_F(ExpressionEvaluatorTest, ListSlicingOperator) {
{ {
// Null value list with undefined upper bound. // Null value list with undefined upper bound.
auto *op = storage.Create<ListSlicingOperator>( auto *op = storage.Create<ListSlicingOperator>(
storage.Create<PrimitiveLiteral>(PropertyValue()), storage.Create<PrimitiveLiteral>(storage::PropertyValue()),
storage.Create<PrimitiveLiteral>(-2), nullptr); storage.Create<PrimitiveLiteral>(-2), nullptr);
auto value = Eval(op); auto value = Eval(op);
EXPECT_TRUE(value.IsNull()); EXPECT_TRUE(value.IsNull());
@ -559,7 +562,7 @@ TEST_F(ExpressionEvaluatorTest, ListSlicingOperator) {
// Null value index. // Null value index.
auto *op = storage.Create<ListSlicingOperator>( auto *op = storage.Create<ListSlicingOperator>(
list_literal, storage.Create<PrimitiveLiteral>(-2), list_literal, storage.Create<PrimitiveLiteral>(-2),
storage.Create<PrimitiveLiteral>(PropertyValue())); storage.Create<PrimitiveLiteral>(storage::PropertyValue()));
auto value = Eval(op); auto value = Eval(op);
EXPECT_TRUE(value.IsNull()); EXPECT_TRUE(value.IsNull());
; ;
@ -624,7 +627,7 @@ TEST_F(ExpressionEvaluatorTest, IsNullOperator) {
auto val1 = Eval(op); auto val1 = Eval(op);
ASSERT_EQ(val1.ValueBool(), false); ASSERT_EQ(val1.ValueBool(), false);
op = storage.Create<IsNullOperator>( op = storage.Create<IsNullOperator>(
storage.Create<PrimitiveLiteral>(PropertyValue())); storage.Create<PrimitiveLiteral>(storage::PropertyValue()));
auto val2 = Eval(op); auto val2 = Eval(op);
ASSERT_EQ(val2.ValueBool(), true); ASSERT_EQ(val2.ValueBool(), true);
} }
@ -693,7 +696,7 @@ TEST_F(ExpressionEvaluatorTest, ListLiteral) {
} }
TEST_F(ExpressionEvaluatorTest, ParameterLookup) { TEST_F(ExpressionEvaluatorTest, ParameterLookup) {
ctx.parameters.Add(0, PropertyValue(42)); ctx.parameters.Add(0, storage::PropertyValue(42));
auto *param_lookup = storage.Create<ParameterLookup>(0); auto *param_lookup = storage.Create<ParameterLookup>(0);
auto value = Eval(param_lookup); auto value = Eval(param_lookup);
ASSERT_TRUE(value.IsInt()); ASSERT_TRUE(value.IsInt());
@ -715,7 +718,7 @@ TEST_F(ExpressionEvaluatorTest, All) {
TEST_F(ExpressionEvaluatorTest, FunctionAllNullList) { TEST_F(ExpressionEvaluatorTest, FunctionAllNullList) {
AstStorage storage; AstStorage storage;
auto *all = ALL("x", LITERAL(PropertyValue()), WHERE(LITERAL(true))); auto *all = ALL("x", LITERAL(storage::PropertyValue()), WHERE(LITERAL(true)));
const auto x_sym = symbol_table.CreateSymbol("x", true); const auto x_sym = symbol_table.CreateSymbol("x", true);
all->identifier_->MapTo(x_sym); all->identifier_->MapTo(x_sym);
auto value = Eval(all); auto value = Eval(all);
@ -758,7 +761,8 @@ TEST_F(ExpressionEvaluatorTest, FunctionSingle2) {
TEST_F(ExpressionEvaluatorTest, FunctionSingleNullList) { TEST_F(ExpressionEvaluatorTest, FunctionSingleNullList) {
AstStorage storage; AstStorage storage;
auto *single = SINGLE("x", LITERAL(PropertyValue()), WHERE(LITERAL(true))); auto *single =
SINGLE("x", LITERAL(storage::PropertyValue()), WHERE(LITERAL(true)));
const auto x_sym = symbol_table.CreateSymbol("x", true); const auto x_sym = symbol_table.CreateSymbol("x", true);
single->identifier_->MapTo(x_sym); single->identifier_->MapTo(x_sym);
auto value = Eval(single); auto value = Eval(single);
@ -785,9 +789,9 @@ TEST_F(ExpressionEvaluatorTest, FunctionReduce) {
TEST_F(ExpressionEvaluatorTest, FunctionExtract) { TEST_F(ExpressionEvaluatorTest, FunctionExtract) {
AstStorage storage; AstStorage storage;
auto *ident_x = IDENT("x"); auto *ident_x = IDENT("x");
auto *extract = auto *extract = EXTRACT(
EXTRACT("x", LIST(LITERAL(1), LITERAL(2), LITERAL(PropertyValue())), "x", LIST(LITERAL(1), LITERAL(2), LITERAL(storage::PropertyValue())),
ADD(ident_x, LITERAL(1))); ADD(ident_x, LITERAL(1)));
const auto x_sym = symbol_table.CreateSymbol("x", true); const auto x_sym = symbol_table.CreateSymbol("x", true);
extract->identifier_->MapTo(x_sym); extract->identifier_->MapTo(x_sym);
ident_x->MapTo(x_sym); ident_x->MapTo(x_sym);
@ -804,7 +808,7 @@ TEST_F(ExpressionEvaluatorTest, FunctionExtractNull) {
AstStorage storage; AstStorage storage;
auto *ident_x = IDENT("x"); auto *ident_x = IDENT("x");
auto *extract = auto *extract =
EXTRACT("x", LITERAL(PropertyValue()), ADD(ident_x, LITERAL(1))); EXTRACT("x", LITERAL(storage::PropertyValue()), ADD(ident_x, LITERAL(1)));
const auto x_sym = symbol_table.CreateSymbol("x", true); const auto x_sym = symbol_table.CreateSymbol("x", true);
extract->identifier_->MapTo(x_sym); extract->identifier_->MapTo(x_sym);
ident_x->MapTo(x_sym); ident_x->MapTo(x_sym);
@ -897,16 +901,16 @@ TEST_F(ExpressionEvaluatorTest, RegexMatch) {
class ExpressionEvaluatorPropertyLookup : public ExpressionEvaluatorTest { class ExpressionEvaluatorPropertyLookup : public ExpressionEvaluatorTest {
protected: protected:
std::pair<std::string, storage::Property> prop_age = std::pair<std::string, storage::PropertyId> prop_age =
std::make_pair("age", dba.NameToProperty("age")); std::make_pair("age", dba.NameToProperty("age"));
std::pair<std::string, storage::Property> prop_height = std::pair<std::string, storage::PropertyId> prop_height =
std::make_pair("height", dba.NameToProperty("height")); std::make_pair("height", dba.NameToProperty("height"));
Identifier *identifier = storage.Create<Identifier>("element"); Identifier *identifier = storage.Create<Identifier>("element");
Symbol symbol = symbol_table.CreateSymbol("element", true); Symbol symbol = symbol_table.CreateSymbol("element", true);
void SetUp() { identifier->MapTo(symbol); } void SetUp() { identifier->MapTo(symbol); }
auto Value(std::pair<std::string, storage::Property> property) { auto Value(std::pair<std::string, storage::PropertyId> property) {
auto *op = storage.Create<PropertyLookup>( auto *op = storage.Create<PropertyLookup>(
identifier, storage.GetPropertyIx(property.first)); identifier, storage.GetPropertyIx(property.first));
return Eval(op); return Eval(op);
@ -915,7 +919,8 @@ class ExpressionEvaluatorPropertyLookup : public ExpressionEvaluatorTest {
TEST_F(ExpressionEvaluatorPropertyLookup, Vertex) { TEST_F(ExpressionEvaluatorPropertyLookup, Vertex) {
auto v1 = dba.InsertVertex(); auto v1 = dba.InsertVertex();
ASSERT_TRUE(v1.SetProperty(prop_age.second, PropertyValue(10)).HasValue()); ASSERT_TRUE(
v1.SetProperty(prop_age.second, storage::PropertyValue(10)).HasValue());
dba.AdvanceCommand(); dba.AdvanceCommand();
frame[symbol] = TypedValue(v1); frame[symbol] = TypedValue(v1);
EXPECT_EQ(Value(prop_age).ValueInt(), 10); EXPECT_EQ(Value(prop_age).ValueInt(), 10);
@ -927,7 +932,8 @@ TEST_F(ExpressionEvaluatorPropertyLookup, Edge) {
auto v2 = dba.InsertVertex(); auto v2 = dba.InsertVertex();
auto e12 = dba.InsertEdge(&v1, &v2, dba.NameToEdgeType("edge_type")); auto e12 = dba.InsertEdge(&v1, &v2, dba.NameToEdgeType("edge_type"));
ASSERT_TRUE(e12.HasValue()); ASSERT_TRUE(e12.HasValue());
ASSERT_TRUE(e12->SetProperty(prop_age.second, PropertyValue(10)).HasValue()); ASSERT_TRUE(
e12->SetProperty(prop_age.second, storage::PropertyValue(10)).HasValue());
dba.AdvanceCommand(); dba.AdvanceCommand();
frame[symbol] = TypedValue(*e12); frame[symbol] = TypedValue(*e12);
EXPECT_EQ(Value(prop_age).ValueInt(), 10); EXPECT_EQ(Value(prop_age).ValueInt(), 10);
@ -1025,17 +1031,21 @@ TEST_F(FunctionTest, Properties) {
ASSERT_THROW(EvaluateFunction("PROPERTIES"), QueryRuntimeException); ASSERT_THROW(EvaluateFunction("PROPERTIES"), QueryRuntimeException);
ASSERT_TRUE(EvaluateFunction("PROPERTIES", TypedValue()).IsNull()); ASSERT_TRUE(EvaluateFunction("PROPERTIES", TypedValue()).IsNull());
auto v1 = dba.InsertVertex(); auto v1 = dba.InsertVertex();
ASSERT_TRUE(v1.SetProperty(dba.NameToProperty("height"), PropertyValue(5))
.HasValue());
ASSERT_TRUE( ASSERT_TRUE(
v1.SetProperty(dba.NameToProperty("age"), PropertyValue(10)).HasValue()); v1.SetProperty(dba.NameToProperty("height"), storage::PropertyValue(5))
.HasValue());
ASSERT_TRUE(
v1.SetProperty(dba.NameToProperty("age"), storage::PropertyValue(10))
.HasValue());
auto v2 = dba.InsertVertex(); auto v2 = dba.InsertVertex();
auto e = dba.InsertEdge(&v1, &v2, dba.NameToEdgeType("type1")); auto e = dba.InsertEdge(&v1, &v2, dba.NameToEdgeType("type1"));
ASSERT_TRUE(e.HasValue()); ASSERT_TRUE(e.HasValue());
ASSERT_TRUE(e->SetProperty(dba.NameToProperty("height"), PropertyValue(3))
.HasValue());
ASSERT_TRUE( ASSERT_TRUE(
e->SetProperty(dba.NameToProperty("age"), PropertyValue(15)).HasValue()); e->SetProperty(dba.NameToProperty("height"), storage::PropertyValue(3))
.HasValue());
ASSERT_TRUE(
e->SetProperty(dba.NameToProperty("age"), storage::PropertyValue(15))
.HasValue());
dba.AdvanceCommand(); dba.AdvanceCommand();
auto prop_values_to_int = [](TypedValue t) { auto prop_values_to_int = [](TypedValue t) {
@ -1284,17 +1294,21 @@ TEST_F(FunctionTest, Keys) {
ASSERT_THROW(EvaluateFunction("KEYS"), QueryRuntimeException); ASSERT_THROW(EvaluateFunction("KEYS"), QueryRuntimeException);
ASSERT_TRUE(EvaluateFunction("KEYS", TypedValue()).IsNull()); ASSERT_TRUE(EvaluateFunction("KEYS", TypedValue()).IsNull());
auto v1 = dba.InsertVertex(); auto v1 = dba.InsertVertex();
ASSERT_TRUE(v1.SetProperty(dba.NameToProperty("height"), PropertyValue(5))
.HasValue());
ASSERT_TRUE( ASSERT_TRUE(
v1.SetProperty(dba.NameToProperty("age"), PropertyValue(10)).HasValue()); v1.SetProperty(dba.NameToProperty("height"), storage::PropertyValue(5))
.HasValue());
ASSERT_TRUE(
v1.SetProperty(dba.NameToProperty("age"), storage::PropertyValue(10))
.HasValue());
auto v2 = dba.InsertVertex(); auto v2 = dba.InsertVertex();
auto e = dba.InsertEdge(&v1, &v2, dba.NameToEdgeType("type1")); auto e = dba.InsertEdge(&v1, &v2, dba.NameToEdgeType("type1"));
ASSERT_TRUE(e.HasValue()); ASSERT_TRUE(e.HasValue());
ASSERT_TRUE( ASSERT_TRUE(
e->SetProperty(dba.NameToProperty("width"), PropertyValue(3)).HasValue()); e->SetProperty(dba.NameToProperty("width"), storage::PropertyValue(3))
.HasValue());
ASSERT_TRUE( ASSERT_TRUE(
e->SetProperty(dba.NameToProperty("age"), PropertyValue(15)).HasValue()); e->SetProperty(dba.NameToProperty("age"), storage::PropertyValue(15))
.HasValue());
dba.AdvanceCommand(); dba.AdvanceCommand();
auto prop_keys_to_string = [](TypedValue t) { auto prop_keys_to_string = [](TypedValue t) {

View File

@ -31,9 +31,9 @@ TEST(QueryPlan, Accumulate) {
auto prop = dba.NameToProperty("x"); auto prop = dba.NameToProperty("x");
auto v1 = dba.InsertVertex(); auto v1 = dba.InsertVertex();
ASSERT_TRUE(v1.SetProperty(prop, PropertyValue(0)).HasValue()); ASSERT_TRUE(v1.SetProperty(prop, storage::PropertyValue(0)).HasValue());
auto v2 = dba.InsertVertex(); auto v2 = dba.InsertVertex();
ASSERT_TRUE(v2.SetProperty(prop, PropertyValue(0)).HasValue()); ASSERT_TRUE(v2.SetProperty(prop, storage::PropertyValue(0)).HasValue());
ASSERT_TRUE(dba.InsertEdge(&v1, &v2, dba.NameToEdgeType("T")).HasValue()); ASSERT_TRUE(dba.InsertEdge(&v1, &v2, dba.NameToEdgeType("T")).HasValue());
dba.AdvanceCommand(); dba.AdvanceCommand();
@ -147,7 +147,7 @@ class QueryPlanAggregateOps : public ::testing::Test {
storage::Storage db; storage::Storage db;
storage::Storage::Accessor storage_dba{db.Access()}; storage::Storage::Accessor storage_dba{db.Access()};
query::DbAccessor dba{&storage_dba}; query::DbAccessor dba{&storage_dba};
storage::Property prop = db.NameToProperty("prop"); storage::PropertyId prop = db.NameToProperty("prop");
AstStorage storage; AstStorage storage;
SymbolTable symbol_table; SymbolTable symbol_table;
@ -156,12 +156,15 @@ class QueryPlanAggregateOps : public ::testing::Test {
// setup is several nodes most of which have an int property set // setup is several nodes most of which have an int property set
// we will take the sum, avg, min, max and count // we will take the sum, avg, min, max and count
// we won't group by anything // we won't group by anything
ASSERT_TRUE( ASSERT_TRUE(dba.InsertVertex()
dba.InsertVertex().SetProperty(prop, PropertyValue(5)).HasValue()); .SetProperty(prop, storage::PropertyValue(5))
ASSERT_TRUE( .HasValue());
dba.InsertVertex().SetProperty(prop, PropertyValue(7)).HasValue()); ASSERT_TRUE(dba.InsertVertex()
ASSERT_TRUE( .SetProperty(prop, storage::PropertyValue(7))
dba.InsertVertex().SetProperty(prop, PropertyValue(12)).HasValue()); .HasValue());
ASSERT_TRUE(dba.InsertVertex()
.SetProperty(prop, storage::PropertyValue(12))
.HasValue());
// a missing property (null) gets ignored by all aggregations except // a missing property (null) gets ignored by all aggregations except
// COUNT(*) // COUNT(*)
dba.InsertVertex(); dba.InsertVertex();
@ -291,9 +294,9 @@ TEST(QueryPlan, AggregateGroupByValues) {
auto storage_dba = db.Access(); auto storage_dba = db.Access();
query::DbAccessor dba(&storage_dba); query::DbAccessor dba(&storage_dba);
// a vector of PropertyValue to be set as property values on vertices // a vector of storage::PropertyValue to be set as property values on vertices
// most of them should result in a distinct group (commented where not) // most of them should result in a distinct group (commented where not)
std::vector<PropertyValue> group_by_vals; std::vector<storage::PropertyValue> group_by_vals;
group_by_vals.emplace_back(4); group_by_vals.emplace_back(4);
group_by_vals.emplace_back(7); group_by_vals.emplace_back(7);
group_by_vals.emplace_back(7.3); group_by_vals.emplace_back(7.3);
@ -303,17 +306,18 @@ TEST(QueryPlan, AggregateGroupByValues) {
group_by_vals.emplace_back("1"); group_by_vals.emplace_back("1");
group_by_vals.emplace_back(true); group_by_vals.emplace_back(true);
group_by_vals.emplace_back(false); group_by_vals.emplace_back(false);
group_by_vals.emplace_back(std::vector<PropertyValue>{PropertyValue(1)});
group_by_vals.emplace_back( group_by_vals.emplace_back(
std::vector<PropertyValue>{PropertyValue(1), PropertyValue(2)}); std::vector<storage::PropertyValue>{storage::PropertyValue(1)});
group_by_vals.emplace_back( group_by_vals.emplace_back(std::vector<storage::PropertyValue>{
std::vector<PropertyValue>{PropertyValue(2), PropertyValue(1)}); storage::PropertyValue(1), storage::PropertyValue(2)});
group_by_vals.emplace_back(PropertyValue()); group_by_vals.emplace_back(std::vector<storage::PropertyValue>{
storage::PropertyValue(2), storage::PropertyValue(1)});
group_by_vals.emplace_back(storage::PropertyValue());
// should NOT result in another group because 7.0 == 7 // should NOT result in another group because 7.0 == 7
group_by_vals.emplace_back(7.0); group_by_vals.emplace_back(7.0);
// should NOT result in another group // should NOT result in another group
group_by_vals.emplace_back( group_by_vals.emplace_back(std::vector<storage::PropertyValue>{
std::vector<PropertyValue>{PropertyValue(1), PropertyValue(2.0)}); storage::PropertyValue(1), storage::PropertyValue(2.0)});
// generate a lot of vertices and set props on them // generate a lot of vertices and set props on them
auto prop = dba.NameToProperty("prop"); auto prop = dba.NameToProperty("prop");
@ -365,12 +369,13 @@ TEST(QueryPlan, AggregateMultipleGroupBy) {
auto prop3 = dba.NameToProperty("prop3"); auto prop3 = dba.NameToProperty("prop3");
for (int i = 0; i < 2 * 3 * 5; ++i) { for (int i = 0; i < 2 * 3 * 5; ++i) {
auto v = dba.InsertVertex(); auto v = dba.InsertVertex();
ASSERT_TRUE(v.SetProperty(prop1, PropertyValue(static_cast<bool>(i % 2)))
.HasValue());
ASSERT_TRUE(v.SetProperty(prop2, PropertyValue(i % 3)).HasValue());
ASSERT_TRUE( ASSERT_TRUE(
v.SetProperty(prop3, PropertyValue("value" + std::to_string(i % 5))) v.SetProperty(prop1, storage::PropertyValue(static_cast<bool>(i % 2)))
.HasValue()); .HasValue());
ASSERT_TRUE(v.SetProperty(prop2, storage::PropertyValue(i % 3)).HasValue());
ASSERT_TRUE(v.SetProperty(prop3, storage::PropertyValue(
"value" + std::to_string(i % 5)))
.HasValue());
} }
dba.AdvanceCommand(); dba.AdvanceCommand();
@ -454,7 +459,7 @@ TEST(QueryPlan, AggregateCountEdgeCases) {
// one vertex, property set // one vertex, property set
for (auto va : dba.Vertices(storage::View::OLD)) for (auto va : dba.Vertices(storage::View::OLD))
ASSERT_TRUE(va.SetProperty(prop, PropertyValue(42)).HasValue()); ASSERT_TRUE(va.SetProperty(prop, storage::PropertyValue(42)).HasValue());
dba.AdvanceCommand(); dba.AdvanceCommand();
EXPECT_EQ(1, count()); EXPECT_EQ(1, count());
@ -465,7 +470,7 @@ TEST(QueryPlan, AggregateCountEdgeCases) {
// two vertices, both with property set // two vertices, both with property set
for (auto va : dba.Vertices(storage::View::OLD)) for (auto va : dba.Vertices(storage::View::OLD))
ASSERT_TRUE(va.SetProperty(prop, PropertyValue(42)).HasValue()); ASSERT_TRUE(va.SetProperty(prop, storage::PropertyValue(42)).HasValue());
dba.AdvanceCommand(); dba.AdvanceCommand();
EXPECT_EQ(2, count()); EXPECT_EQ(2, count());
} }
@ -480,9 +485,10 @@ TEST(QueryPlan, AggregateFirstValueTypes) {
auto v1 = dba.InsertVertex(); auto v1 = dba.InsertVertex();
auto prop_string = dba.NameToProperty("string"); auto prop_string = dba.NameToProperty("string");
ASSERT_TRUE(v1.SetProperty(prop_string, PropertyValue("johhny")).HasValue()); ASSERT_TRUE(
v1.SetProperty(prop_string, storage::PropertyValue("johhny")).HasValue());
auto prop_int = dba.NameToProperty("int"); auto prop_int = dba.NameToProperty("int");
ASSERT_TRUE(v1.SetProperty(prop_int, PropertyValue(12)).HasValue()); ASSERT_TRUE(v1.SetProperty(prop_int, storage::PropertyValue(12)).HasValue());
dba.AdvanceCommand(); dba.AdvanceCommand();
AstStorage storage; AstStorage storage;
@ -536,14 +542,19 @@ TEST(QueryPlan, AggregateTypes) {
query::DbAccessor dba(&storage_dba); query::DbAccessor dba(&storage_dba);
auto p1 = dba.NameToProperty("p1"); // has only string props auto p1 = dba.NameToProperty("p1"); // has only string props
ASSERT_TRUE( ASSERT_TRUE(dba.InsertVertex()
dba.InsertVertex().SetProperty(p1, PropertyValue("string")).HasValue()); .SetProperty(p1, storage::PropertyValue("string"))
ASSERT_TRUE( .HasValue());
dba.InsertVertex().SetProperty(p1, PropertyValue("str2")).HasValue()); ASSERT_TRUE(dba.InsertVertex()
.SetProperty(p1, storage::PropertyValue("str2"))
.HasValue());
auto p2 = dba.NameToProperty("p2"); // combines int and bool auto p2 = dba.NameToProperty("p2"); // combines int and bool
ASSERT_TRUE(dba.InsertVertex().SetProperty(p2, PropertyValue(42)).HasValue()); ASSERT_TRUE(dba.InsertVertex()
ASSERT_TRUE( .SetProperty(p2, storage::PropertyValue(42))
dba.InsertVertex().SetProperty(p2, PropertyValue(true)).HasValue()); .HasValue());
ASSERT_TRUE(dba.InsertVertex()
.SetProperty(p2, storage::PropertyValue(true))
.HasValue());
dba.AdvanceCommand(); dba.AdvanceCommand();
AstStorage storage; AstStorage storage;
@ -597,11 +608,14 @@ TEST(QueryPlan, Unwind) {
SymbolTable symbol_table; SymbolTable symbol_table;
// UNWIND [ [1, true, "x"], [], ["bla"] ] AS x UNWIND x as y RETURN x, y // UNWIND [ [1, true, "x"], [], ["bla"] ] AS x UNWIND x as y RETURN x, y
auto input_expr = storage.Create<PrimitiveLiteral>(std::vector<PropertyValue>{ auto input_expr =
PropertyValue(std::vector<PropertyValue>{ storage.Create<PrimitiveLiteral>(std::vector<storage::PropertyValue>{
PropertyValue(1), PropertyValue(true), PropertyValue("x")}), storage::PropertyValue(std::vector<storage::PropertyValue>{
PropertyValue(std::vector<PropertyValue>{}), storage::PropertyValue(1), storage::PropertyValue(true),
PropertyValue(std::vector<PropertyValue>{PropertyValue("bla")})}); storage::PropertyValue("x")}),
storage::PropertyValue(std::vector<storage::PropertyValue>{}),
storage::PropertyValue(std::vector<storage::PropertyValue>{
storage::PropertyValue("bla")})});
auto x = symbol_table.CreateSymbol("x", true); auto x = symbol_table.CreateSymbol("x", true);
auto unwind_0 = std::make_shared<plan::Unwind>(nullptr, input_expr, x); auto unwind_0 = std::make_shared<plan::Unwind>(nullptr, input_expr, x);

View File

@ -118,25 +118,33 @@ TEST(QueryPlan, OrderBy) {
// contains a series of tests // contains a series of tests
// each test defines the ordering a vector of values in the desired order // each test defines the ordering a vector of values in the desired order
auto Null = PropertyValue(); auto Null = storage::PropertyValue();
std::vector<std::pair<Ordering, std::vector<PropertyValue>>> orderable{ std::vector<std::pair<Ordering, std::vector<storage::PropertyValue>>>
{Ordering::ASC, orderable{
{PropertyValue(0), PropertyValue(0), PropertyValue(0.5), {Ordering::ASC,
PropertyValue(1), PropertyValue(2), PropertyValue(12.6), {storage::PropertyValue(0), storage::PropertyValue(0),
PropertyValue(42), Null, Null}}, storage::PropertyValue(0.5), storage::PropertyValue(1),
{Ordering::ASC, storage::PropertyValue(2), storage::PropertyValue(12.6),
{PropertyValue(false), PropertyValue(false), PropertyValue(true), storage::PropertyValue(42), Null, Null}},
PropertyValue(true), Null, Null}}, {Ordering::ASC,
{Ordering::ASC, {storage::PropertyValue(false), storage::PropertyValue(false),
{PropertyValue("A"), PropertyValue("B"), PropertyValue("a"), storage::PropertyValue(true), storage::PropertyValue(true), Null,
PropertyValue("a"), PropertyValue("aa"), PropertyValue("ab"), Null}},
PropertyValue("aba"), Null, Null}}, {Ordering::ASC,
{Ordering::DESC, {storage::PropertyValue("A"), storage::PropertyValue("B"),
{Null, Null, PropertyValue(33), PropertyValue(33), PropertyValue(32.5), storage::PropertyValue("a"), storage::PropertyValue("a"),
PropertyValue(32), PropertyValue(2.2), PropertyValue(2.1), storage::PropertyValue("aa"), storage::PropertyValue("ab"),
PropertyValue(0)}}, storage::PropertyValue("aba"), Null, Null}},
{Ordering::DESC, {Null, PropertyValue(true), PropertyValue(false)}}, {Ordering::DESC,
{Ordering::DESC, {Null, PropertyValue("zorro"), PropertyValue("borro")}}}; {Null, Null, storage::PropertyValue(33), storage::PropertyValue(33),
storage::PropertyValue(32.5), storage::PropertyValue(32),
storage::PropertyValue(2.2), storage::PropertyValue(2.1),
storage::PropertyValue(0)}},
{Ordering::DESC,
{Null, storage::PropertyValue(true), storage::PropertyValue(false)}},
{Ordering::DESC,
{Null, storage::PropertyValue("zorro"),
storage::PropertyValue("borro")}}};
for (const auto &order_value_pair : orderable) { for (const auto &order_value_pair : orderable) {
std::vector<TypedValue> values; std::vector<TypedValue> values;
@ -164,7 +172,7 @@ TEST(QueryPlan, OrderBy) {
// create the vertices // create the vertices
for (const auto &value : shuffled) for (const auto &value : shuffled)
ASSERT_TRUE(dba.InsertVertex() ASSERT_TRUE(dba.InsertVertex()
.SetProperty(prop, PropertyValue(value)) .SetProperty(prop, storage::PropertyValue(value))
.HasValue()); .HasValue());
dba.AdvanceCommand(); dba.AdvanceCommand();
@ -205,8 +213,10 @@ TEST(QueryPlan, OrderByMultiple) {
std::random_shuffle(prop_values.begin(), prop_values.end()); std::random_shuffle(prop_values.begin(), prop_values.end());
for (const auto &pair : prop_values) { for (const auto &pair : prop_values) {
auto v = dba.InsertVertex(); auto v = dba.InsertVertex();
ASSERT_TRUE(v.SetProperty(p1, PropertyValue(pair.first)).HasValue()); ASSERT_TRUE(
ASSERT_TRUE(v.SetProperty(p2, PropertyValue(pair.second)).HasValue()); v.SetProperty(p1, storage::PropertyValue(pair.first)).HasValue());
ASSERT_TRUE(
v.SetProperty(p2, storage::PropertyValue(pair.second)).HasValue());
} }
dba.AdvanceCommand(); dba.AdvanceCommand();
@ -251,19 +261,25 @@ TEST(QueryPlan, OrderByExceptions) {
// a vector of pairs of typed values that should result // a vector of pairs of typed values that should result
// in an exception when trying to order on them // in an exception when trying to order on them
std::vector<std::pair<PropertyValue, PropertyValue>> exception_pairs{ std::vector<std::pair<storage::PropertyValue, storage::PropertyValue>>
{PropertyValue(42), PropertyValue(true)}, exception_pairs{
{PropertyValue(42), PropertyValue("bla")}, {storage::PropertyValue(42), storage::PropertyValue(true)},
{PropertyValue(42), {storage::PropertyValue(42), storage::PropertyValue("bla")},
PropertyValue(std::vector<PropertyValue>{PropertyValue(42)})}, {storage::PropertyValue(42),
{PropertyValue(true), PropertyValue("bla")}, storage::PropertyValue(std::vector<storage::PropertyValue>{
{PropertyValue(true), storage::PropertyValue(42)})},
PropertyValue(std::vector<PropertyValue>{PropertyValue(true)})}, {storage::PropertyValue(true), storage::PropertyValue("bla")},
{PropertyValue("bla"), {storage::PropertyValue(true),
PropertyValue(std::vector<PropertyValue>{PropertyValue("bla")})}, storage::PropertyValue(std::vector<storage::PropertyValue>{
// illegal comparisons of same-type values storage::PropertyValue(true)})},
{PropertyValue(std::vector<PropertyValue>{PropertyValue(42)}), {storage::PropertyValue("bla"),
PropertyValue(std::vector<PropertyValue>{PropertyValue(42)})}}; storage::PropertyValue(std::vector<storage::PropertyValue>{
storage::PropertyValue("bla")})},
// illegal comparisons of same-type values
{storage::PropertyValue(
std::vector<storage::PropertyValue>{storage::PropertyValue(42)}),
storage::PropertyValue(std::vector<storage::PropertyValue>{
storage::PropertyValue(42)})}};
for (const auto &pair : exception_pairs) { for (const auto &pair : exception_pairs) {
// empty database // empty database
@ -279,7 +295,7 @@ TEST(QueryPlan, OrderByExceptions) {
ASSERT_EQ(2, CountIterable(dba.Vertices(storage::View::OLD))); ASSERT_EQ(2, CountIterable(dba.Vertices(storage::View::OLD)));
for (const auto &va : dba.Vertices(storage::View::OLD)) for (const auto &va : dba.Vertices(storage::View::OLD))
ASSERT_NE(va.GetProperty(storage::View::OLD, prop).GetValue().type(), ASSERT_NE(va.GetProperty(storage::View::OLD, prop).GetValue().type(),
PropertyValue::Type::Null); storage::PropertyValue::Type::Null);
// order by and expect an exception // order by and expect an exception
auto n = MakeScanAll(storage, symbol_table, "n"); auto n = MakeScanAll(storage, symbol_table, "n");

View File

@ -250,8 +250,8 @@ class ExpectScanAllByLabelPropertyValue
: public OpChecker<ScanAllByLabelPropertyValue> { : public OpChecker<ScanAllByLabelPropertyValue> {
public: public:
ExpectScanAllByLabelPropertyValue( ExpectScanAllByLabelPropertyValue(
storage::Label label, storage::LabelId label,
const std::pair<std::string, storage::Property> &prop_pair, const std::pair<std::string, storage::PropertyId> &prop_pair,
query::Expression *expression) query::Expression *expression)
: label_(label), property_(prop_pair.second), expression_(expression) {} : label_(label), property_(prop_pair.second), expression_(expression) {}
@ -265,8 +265,8 @@ class ExpectScanAllByLabelPropertyValue
} }
private: private:
storage::Label label_; storage::LabelId label_;
storage::Property property_; storage::PropertyId property_;
query::Expression *expression_; query::Expression *expression_;
}; };
@ -274,7 +274,7 @@ class ExpectScanAllByLabelPropertyRange
: public OpChecker<ScanAllByLabelPropertyRange> { : public OpChecker<ScanAllByLabelPropertyRange> {
public: public:
ExpectScanAllByLabelPropertyRange( ExpectScanAllByLabelPropertyRange(
storage::Label label, storage::Property property, storage::LabelId label, storage::PropertyId property,
std::optional<ScanAllByLabelPropertyRange::Bound> lower_bound, std::optional<ScanAllByLabelPropertyRange::Bound> lower_bound,
std::optional<ScanAllByLabelPropertyRange::Bound> upper_bound) std::optional<ScanAllByLabelPropertyRange::Bound> upper_bound)
: label_(label), : label_(label),
@ -303,8 +303,8 @@ class ExpectScanAllByLabelPropertyRange
} }
private: private:
storage::Label label_; storage::LabelId label_;
storage::Property property_; storage::PropertyId property_;
std::optional<ScanAllByLabelPropertyRange::Bound> lower_bound_; std::optional<ScanAllByLabelPropertyRange::Bound> lower_bound_;
std::optional<ScanAllByLabelPropertyRange::Bound> upper_bound_; std::optional<ScanAllByLabelPropertyRange::Bound> upper_bound_;
}; };
@ -383,14 +383,14 @@ TPlanner MakePlanner(TDbAccessor *dba, AstStorage &storage,
class FakeDbAccessor { class FakeDbAccessor {
public: public:
int64_t VerticesCount(storage::Label label) const { int64_t VerticesCount(storage::LabelId label) const {
auto found = label_index_.find(label); auto found = label_index_.find(label);
if (found != label_index_.end()) return found->second; if (found != label_index_.end()) return found->second;
return 0; return 0;
} }
int64_t VerticesCount(storage::Label label, int64_t VerticesCount(storage::LabelId label,
storage::Property property) const { storage::PropertyId property) const {
for (auto &index : label_property_index_) { for (auto &index : label_property_index_) {
if (std::get<0>(index) == label && std::get<1>(index) == property) { if (std::get<0>(index) == label && std::get<1>(index) == property) {
return std::get<2>(index); return std::get<2>(index);
@ -399,12 +399,12 @@ class FakeDbAccessor {
return 0; return 0;
} }
bool LabelIndexExists(storage::Label label) const { bool LabelIndexExists(storage::LabelId label) const {
return label_index_.find(label) != label_index_.end(); return label_index_.find(label) != label_index_.end();
} }
bool LabelPropertyIndexExists(storage::Label label, bool LabelPropertyIndexExists(storage::LabelId label,
storage::Property property) const { storage::PropertyId property) const {
for (auto &index : label_property_index_) { for (auto &index : label_property_index_) {
if (std::get<0>(index) == label && std::get<1>(index) == property) { if (std::get<0>(index) == label && std::get<1>(index) == property) {
return true; return true;
@ -413,11 +413,11 @@ class FakeDbAccessor {
return false; return false;
} }
void SetIndexCount(storage::Label label, int64_t count) { void SetIndexCount(storage::LabelId label, int64_t count) {
label_index_[label] = count; label_index_[label] = count;
} }
void SetIndexCount(storage::Label label, storage::Property property, void SetIndexCount(storage::LabelId label, storage::PropertyId property,
int64_t count) { int64_t count) {
for (auto &index : label_property_index_) { for (auto &index : label_property_index_) {
if (std::get<0>(index) == label && std::get<1>(index) == property) { if (std::get<0>(index) == label && std::get<1>(index) == property) {
@ -428,53 +428,53 @@ class FakeDbAccessor {
label_property_index_.emplace_back(label, property, count); label_property_index_.emplace_back(label, property, count);
} }
storage::Label NameToLabel(const std::string &name) { storage::LabelId NameToLabel(const std::string &name) {
auto found = labels_.find(name); auto found = labels_.find(name);
if (found != labels_.end()) return found->second; if (found != labels_.end()) return found->second;
return labels_.emplace(name, storage::Label::FromUint(labels_.size())) return labels_.emplace(name, storage::LabelId::FromUint(labels_.size()))
.first->second; .first->second;
} }
storage::Label Label(const std::string &name) { return NameToLabel(name); } storage::LabelId Label(const std::string &name) { return NameToLabel(name); }
storage::EdgeType NameToEdgeType(const std::string &name) { storage::EdgeTypeId NameToEdgeType(const std::string &name) {
auto found = edge_types_.find(name); auto found = edge_types_.find(name);
if (found != edge_types_.end()) return found->second; if (found != edge_types_.end()) return found->second;
return edge_types_ return edge_types_
.emplace(name, storage::EdgeType::FromUint(edge_types_.size())) .emplace(name, storage::EdgeTypeId::FromUint(edge_types_.size()))
.first->second; .first->second;
} }
storage::Property NameToProperty(const std::string &name) { storage::PropertyId NameToProperty(const std::string &name) {
auto found = properties_.find(name); auto found = properties_.find(name);
if (found != properties_.end()) return found->second; if (found != properties_.end()) return found->second;
return properties_ return properties_
.emplace(name, storage::Property::FromUint(properties_.size())) .emplace(name, storage::PropertyId::FromUint(properties_.size()))
.first->second; .first->second;
} }
storage::Property Property(const std::string &name) { storage::PropertyId Property(const std::string &name) {
return NameToProperty(name); return NameToProperty(name);
} }
std::string PropertyToName(storage::Property property) const { std::string PropertyToName(storage::PropertyId property) const {
for (const auto &kv : properties_) { for (const auto &kv : properties_) {
if (kv.second == property) return kv.first; if (kv.second == property) return kv.first;
} }
LOG(FATAL) << "Unable to find property name"; LOG(FATAL) << "Unable to find property name";
} }
std::string PropertyName(storage::Property property) const { std::string PropertyName(storage::PropertyId property) const {
return PropertyToName(property); return PropertyToName(property);
} }
private: private:
std::unordered_map<std::string, storage::Label> labels_; std::unordered_map<std::string, storage::LabelId> labels_;
std::unordered_map<std::string, storage::EdgeType> edge_types_; std::unordered_map<std::string, storage::EdgeTypeId> edge_types_;
std::unordered_map<std::string, storage::Property> properties_; std::unordered_map<std::string, storage::PropertyId> properties_;
std::unordered_map<storage::Label, int64_t> label_index_; std::unordered_map<storage::LabelId, int64_t> label_index_;
std::vector<std::tuple<storage::Label, storage::Property, int64_t>> std::vector<std::tuple<storage::LabelId, storage::PropertyId, int64_t>>
label_property_index_; label_property_index_;
}; };

View File

@ -101,7 +101,7 @@ ScanAllTuple MakeScanAll(AstStorage &storage, SymbolTable &symbol_table,
*/ */
ScanAllTuple MakeScanAllByLabel( ScanAllTuple MakeScanAllByLabel(
AstStorage &storage, SymbolTable &symbol_table, AstStorage &storage, SymbolTable &symbol_table,
const std::string &identifier, storage::Label label, const std::string &identifier, storage::LabelId label,
std::shared_ptr<LogicalOperator> input = {nullptr}, std::shared_ptr<LogicalOperator> input = {nullptr},
storage::View view = storage::View::OLD) { storage::View view = storage::View::OLD) {
auto node = NODE(identifier); auto node = NODE(identifier);
@ -120,7 +120,7 @@ ScanAllTuple MakeScanAllByLabel(
*/ */
ScanAllTuple MakeScanAllByLabelPropertyRange( ScanAllTuple MakeScanAllByLabelPropertyRange(
AstStorage &storage, SymbolTable &symbol_table, std::string identifier, AstStorage &storage, SymbolTable &symbol_table, std::string identifier,
storage::Label label, storage::Property property, storage::LabelId label, storage::PropertyId property,
const std::string &property_name, std::optional<Bound> lower_bound, const std::string &property_name, std::optional<Bound> lower_bound,
std::optional<Bound> upper_bound, std::optional<Bound> upper_bound,
std::shared_ptr<LogicalOperator> input = {nullptr}, std::shared_ptr<LogicalOperator> input = {nullptr},
@ -142,7 +142,7 @@ ScanAllTuple MakeScanAllByLabelPropertyRange(
*/ */
ScanAllTuple MakeScanAllByLabelPropertyValue( ScanAllTuple MakeScanAllByLabelPropertyValue(
AstStorage &storage, SymbolTable &symbol_table, std::string identifier, AstStorage &storage, SymbolTable &symbol_table, std::string identifier,
storage::Label label, storage::Property property, storage::LabelId label, storage::PropertyId property,
const std::string &property_name, Expression *value, const std::string &property_name, Expression *value,
std::shared_ptr<LogicalOperator> input = {nullptr}, std::shared_ptr<LogicalOperator> input = {nullptr},
storage::View view = storage::View::OLD) { storage::View view = storage::View::OLD) {
@ -166,7 +166,7 @@ ExpandTuple MakeExpand(AstStorage &storage, SymbolTable &symbol_table,
std::shared_ptr<LogicalOperator> input, std::shared_ptr<LogicalOperator> input,
Symbol input_symbol, const std::string &edge_identifier, Symbol input_symbol, const std::string &edge_identifier,
EdgeAtom::Direction direction, EdgeAtom::Direction direction,
const std::vector<storage::EdgeType> &edge_types, const std::vector<storage::EdgeTypeId> &edge_types,
const std::string &node_identifier, bool existing_node, const std::string &node_identifier, bool existing_node,
storage::View view) { storage::View view) {
auto edge = EDGE(edge_identifier, direction); auto edge = EDGE(edge_identifier, direction);

View File

@ -20,7 +20,7 @@ TEST(QueryPlan, CreateNodeWithAttributes) {
auto storage_dba = db.Access(); auto storage_dba = db.Access();
query::DbAccessor dba(&storage_dba); query::DbAccessor dba(&storage_dba);
storage::Label label = dba.NameToLabel("Person"); storage::LabelId label = dba.NameToLabel("Person");
auto property = PROPERTY_PAIR("prop"); auto property = PROPERTY_PAIR("prop");
AstStorage storage; AstStorage storage;
@ -64,7 +64,7 @@ TEST(QueryPlan, CreateReturn) {
auto storage_dba = db.Access(); auto storage_dba = db.Access();
query::DbAccessor dba(&storage_dba); query::DbAccessor dba(&storage_dba);
storage::Label label = dba.NameToLabel("Person"); storage::LabelId label = dba.NameToLabel("Person");
auto property = PROPERTY_PAIR("property"); auto property = PROPERTY_PAIR("property");
AstStorage storage; AstStorage storage;
@ -105,10 +105,10 @@ TEST(QueryPlan, CreateExpand) {
auto storage_dba = db.Access(); auto storage_dba = db.Access();
query::DbAccessor dba(&storage_dba); query::DbAccessor dba(&storage_dba);
storage::Label label_node_1 = dba.NameToLabel("Node1"); storage::LabelId label_node_1 = dba.NameToLabel("Node1");
storage::Label label_node_2 = dba.NameToLabel("Node2"); storage::LabelId label_node_2 = dba.NameToLabel("Node2");
auto property = PROPERTY_PAIR("property"); auto property = PROPERTY_PAIR("property");
storage::EdgeType edge_type = dba.NameToEdgeType("edge_type"); storage::EdgeTypeId edge_type = dba.NameToEdgeType("edge_type");
SymbolTable symbol_table; SymbolTable symbol_table;
AstStorage storage; AstStorage storage;
@ -156,7 +156,7 @@ TEST(QueryPlan, CreateExpand) {
CHECK(maybe_labels.HasValue()); CHECK(maybe_labels.HasValue());
const auto &labels = *maybe_labels; const auto &labels = *maybe_labels;
EXPECT_EQ(labels.size(), 1); EXPECT_EQ(labels.size(), 1);
storage::Label label = labels[0]; storage::LabelId label = labels[0];
if (label == label_node_1) { if (label == label_node_1) {
// node created by first op // node created by first op
EXPECT_EQ( EXPECT_EQ(
@ -225,10 +225,10 @@ TEST(QueryPlan, MatchCreateExpand) {
dba.InsertVertex(); dba.InsertVertex();
dba.AdvanceCommand(); dba.AdvanceCommand();
// storage::Label label_node_1 = dba.NameToLabel("Node1"); // storage::LabelId label_node_1 = dba.NameToLabel("Node1");
// storage::Label label_node_2 = dba.NameToLabel("Node2"); // storage::LabelId label_node_2 = dba.NameToLabel("Node2");
// storage::Property property = dba.NameToLabel("prop"); // storage::PropertyId property = dba.NameToLabel("prop");
storage::EdgeType edge_type = dba.NameToEdgeType("edge_type"); storage::EdgeTypeId edge_type = dba.NameToEdgeType("edge_type");
SymbolTable symbol_table; SymbolTable symbol_table;
AstStorage storage; AstStorage storage;
@ -402,7 +402,8 @@ TEST(QueryPlan, DeleteReturn) {
auto prop = PROPERTY_PAIR("property"); auto prop = PROPERTY_PAIR("property");
for (int i = 0; i < 4; ++i) { for (int i = 0; i < 4; ++i) {
auto va = dba.InsertVertex(); auto va = dba.InsertVertex();
ASSERT_TRUE(va.SetProperty(prop.second, PropertyValue(42)).HasValue()); ASSERT_TRUE(
va.SetProperty(prop.second, storage::PropertyValue(42)).HasValue());
} }
dba.AdvanceCommand(); dba.AdvanceCommand();
@ -529,15 +530,15 @@ TEST(QueryPlan, SetProperty) {
ASSERT_TRUE(maybe_edges.HasValue()); ASSERT_TRUE(maybe_edges.HasValue());
for (auto edge : *maybe_edges) { for (auto edge : *maybe_edges) {
ASSERT_EQ(edge.GetProperty(storage::View::OLD, prop1)->type(), ASSERT_EQ(edge.GetProperty(storage::View::OLD, prop1)->type(),
PropertyValue::Type::Int); storage::PropertyValue::Type::Int);
EXPECT_EQ(edge.GetProperty(storage::View::OLD, prop1)->ValueInt(), 42); EXPECT_EQ(edge.GetProperty(storage::View::OLD, prop1)->ValueInt(), 42);
auto from = edge.From(); auto from = edge.From();
auto to = edge.To(); auto to = edge.To();
ASSERT_EQ(from.GetProperty(storage::View::OLD, prop1)->type(), ASSERT_EQ(from.GetProperty(storage::View::OLD, prop1)->type(),
PropertyValue::Type::Int); storage::PropertyValue::Type::Int);
EXPECT_EQ(from.GetProperty(storage::View::OLD, prop1)->ValueInt(), 42); EXPECT_EQ(from.GetProperty(storage::View::OLD, prop1)->ValueInt(), 42);
ASSERT_EQ(to.GetProperty(storage::View::OLD, prop1)->type(), ASSERT_EQ(to.GetProperty(storage::View::OLD, prop1)->type(),
PropertyValue::Type::Null); storage::PropertyValue::Type::Null);
} }
} }
} }
@ -555,9 +556,9 @@ TEST(QueryPlan, SetProperties) {
auto v1 = dba.InsertVertex(); auto v1 = dba.InsertVertex();
auto v2 = dba.InsertVertex(); auto v2 = dba.InsertVertex();
auto e = dba.InsertEdge(&v1, &v2, dba.NameToEdgeType("R")); auto e = dba.InsertEdge(&v1, &v2, dba.NameToEdgeType("R"));
ASSERT_TRUE(v1.SetProperty(prop_a, PropertyValue(0)).HasValue()); ASSERT_TRUE(v1.SetProperty(prop_a, storage::PropertyValue(0)).HasValue());
ASSERT_TRUE(e->SetProperty(prop_b, PropertyValue(1)).HasValue()); ASSERT_TRUE(e->SetProperty(prop_b, storage::PropertyValue(1)).HasValue());
ASSERT_TRUE(v2.SetProperty(prop_c, PropertyValue(2)).HasValue()); ASSERT_TRUE(v2.SetProperty(prop_c, storage::PropertyValue(2)).HasValue());
dba.AdvanceCommand(); dba.AdvanceCommand();
AstStorage storage; AstStorage storage;
@ -592,29 +593,29 @@ TEST(QueryPlan, SetProperties) {
EXPECT_EQ(from.Properties(storage::View::OLD)->size(), update ? 2 : 1); EXPECT_EQ(from.Properties(storage::View::OLD)->size(), update ? 2 : 1);
if (update) { if (update) {
ASSERT_EQ(from.GetProperty(storage::View::OLD, prop_a)->type(), ASSERT_EQ(from.GetProperty(storage::View::OLD, prop_a)->type(),
PropertyValue::Type::Int); storage::PropertyValue::Type::Int);
EXPECT_EQ(from.GetProperty(storage::View::OLD, prop_a)->ValueInt(), EXPECT_EQ(from.GetProperty(storage::View::OLD, prop_a)->ValueInt(),
0); 0);
} }
ASSERT_EQ(from.GetProperty(storage::View::OLD, prop_b)->type(), ASSERT_EQ(from.GetProperty(storage::View::OLD, prop_b)->type(),
PropertyValue::Type::Int); storage::PropertyValue::Type::Int);
EXPECT_EQ(from.GetProperty(storage::View::OLD, prop_b)->ValueInt(), 1); EXPECT_EQ(from.GetProperty(storage::View::OLD, prop_b)->ValueInt(), 1);
EXPECT_EQ(edge.Properties(storage::View::OLD)->size(), update ? 2 : 1); EXPECT_EQ(edge.Properties(storage::View::OLD)->size(), update ? 2 : 1);
if (update) { if (update) {
ASSERT_EQ(edge.GetProperty(storage::View::OLD, prop_b)->type(), ASSERT_EQ(edge.GetProperty(storage::View::OLD, prop_b)->type(),
PropertyValue::Type::Int); storage::PropertyValue::Type::Int);
EXPECT_EQ(edge.GetProperty(storage::View::OLD, prop_b)->ValueInt(), EXPECT_EQ(edge.GetProperty(storage::View::OLD, prop_b)->ValueInt(),
1); 1);
} }
ASSERT_EQ(edge.GetProperty(storage::View::OLD, prop_c)->type(), ASSERT_EQ(edge.GetProperty(storage::View::OLD, prop_c)->type(),
PropertyValue::Type::Int); storage::PropertyValue::Type::Int);
EXPECT_EQ(edge.GetProperty(storage::View::OLD, prop_c)->ValueInt(), 2); EXPECT_EQ(edge.GetProperty(storage::View::OLD, prop_c)->ValueInt(), 2);
auto to = edge.To(); auto to = edge.To();
EXPECT_EQ(to.Properties(storage::View::OLD)->size(), 1); EXPECT_EQ(to.Properties(storage::View::OLD)->size(), 1);
ASSERT_EQ(to.GetProperty(storage::View::OLD, prop_c)->type(), ASSERT_EQ(to.GetProperty(storage::View::OLD, prop_c)->type(),
PropertyValue::Type::Int); storage::PropertyValue::Type::Int);
EXPECT_EQ(to.GetProperty(storage::View::OLD, prop_c)->ValueInt(), 2); EXPECT_EQ(to.GetProperty(storage::View::OLD, prop_c)->ValueInt(), 2);
} }
} }
@ -641,7 +642,7 @@ TEST(QueryPlan, SetLabels) {
auto n = MakeScanAll(storage, symbol_table, "n"); auto n = MakeScanAll(storage, symbol_table, "n");
auto label_set = std::make_shared<plan::SetLabels>( auto label_set = std::make_shared<plan::SetLabels>(
n.op_, n.sym_, std::vector<storage::Label>{label2, label3}); n.op_, n.sym_, std::vector<storage::LabelId>{label2, label3});
auto context = MakeContext(storage, symbol_table, &dba); auto context = MakeContext(storage, symbol_table, &dba);
EXPECT_EQ(2, PullAll(*label_set, &context)); EXPECT_EQ(2, PullAll(*label_set, &context));
@ -669,15 +670,15 @@ TEST(QueryPlan, RemoveProperty) {
{ {
auto e = dba.InsertEdge(&v1, &v3, edge_type); auto e = dba.InsertEdge(&v1, &v3, edge_type);
ASSERT_TRUE(e.HasValue()); ASSERT_TRUE(e.HasValue());
ASSERT_TRUE(e->SetProperty(prop1, PropertyValue(42)).HasValue()); ASSERT_TRUE(e->SetProperty(prop1, storage::PropertyValue(42)).HasValue());
} }
ASSERT_TRUE(dba.InsertEdge(&v2, &v4, edge_type).HasValue()); ASSERT_TRUE(dba.InsertEdge(&v2, &v4, edge_type).HasValue());
ASSERT_TRUE(v2.SetProperty(prop1, PropertyValue(42)).HasValue()); ASSERT_TRUE(v2.SetProperty(prop1, storage::PropertyValue(42)).HasValue());
ASSERT_TRUE(v3.SetProperty(prop1, PropertyValue(42)).HasValue()); ASSERT_TRUE(v3.SetProperty(prop1, storage::PropertyValue(42)).HasValue());
ASSERT_TRUE(v4.SetProperty(prop1, PropertyValue(42)).HasValue()); ASSERT_TRUE(v4.SetProperty(prop1, storage::PropertyValue(42)).HasValue());
auto prop2 = dba.NameToProperty("prop2"); auto prop2 = dba.NameToProperty("prop2");
ASSERT_TRUE(v1.SetProperty(prop2, PropertyValue(0)).HasValue()); ASSERT_TRUE(v1.SetProperty(prop2, storage::PropertyValue(0)).HasValue());
ASSERT_TRUE(v2.SetProperty(prop2, PropertyValue(0)).HasValue()); ASSERT_TRUE(v2.SetProperty(prop2, storage::PropertyValue(0)).HasValue());
dba.AdvanceCommand(); dba.AdvanceCommand();
AstStorage storage; AstStorage storage;
@ -704,15 +705,15 @@ TEST(QueryPlan, RemoveProperty) {
ASSERT_TRUE(maybe_edges.HasValue()); ASSERT_TRUE(maybe_edges.HasValue());
for (auto edge : *maybe_edges) { for (auto edge : *maybe_edges) {
EXPECT_EQ(edge.GetProperty(storage::View::OLD, prop1)->type(), EXPECT_EQ(edge.GetProperty(storage::View::OLD, prop1)->type(),
PropertyValue::Type::Null); storage::PropertyValue::Type::Null);
auto from = edge.From(); auto from = edge.From();
auto to = edge.To(); auto to = edge.To();
EXPECT_EQ(from.GetProperty(storage::View::OLD, prop1)->type(), EXPECT_EQ(from.GetProperty(storage::View::OLD, prop1)->type(),
PropertyValue::Type::Null); storage::PropertyValue::Type::Null);
EXPECT_EQ(from.GetProperty(storage::View::OLD, prop2)->type(), EXPECT_EQ(from.GetProperty(storage::View::OLD, prop2)->type(),
PropertyValue::Type::Int); storage::PropertyValue::Type::Int);
EXPECT_EQ(to.GetProperty(storage::View::OLD, prop1)->type(), EXPECT_EQ(to.GetProperty(storage::View::OLD, prop1)->type(),
PropertyValue::Type::Int); storage::PropertyValue::Type::Int);
} }
} }
} }
@ -739,7 +740,7 @@ TEST(QueryPlan, RemoveLabels) {
auto n = MakeScanAll(storage, symbol_table, "n"); auto n = MakeScanAll(storage, symbol_table, "n");
auto label_remove = std::make_shared<plan::RemoveLabels>( auto label_remove = std::make_shared<plan::RemoveLabels>(
n.op_, n.sym_, std::vector<storage::Label>{label1, label2}); n.op_, n.sym_, std::vector<storage::LabelId>{label1, label2});
auto context = MakeContext(storage, symbol_table, &dba); auto context = MakeContext(storage, symbol_table, &dba);
EXPECT_EQ(2, PullAll(*label_remove, &context)); EXPECT_EQ(2, PullAll(*label_remove, &context));
@ -757,7 +758,8 @@ TEST(QueryPlan, NodeFilterSet) {
// Create a graph such that (v1 {prop: 42}) is connected to v2 and v3. // Create a graph such that (v1 {prop: 42}) is connected to v2 and v3.
auto v1 = dba.InsertVertex(); auto v1 = dba.InsertVertex();
auto prop = PROPERTY_PAIR("property"); auto prop = PROPERTY_PAIR("property");
ASSERT_TRUE(v1.SetProperty(prop.second, PropertyValue(42)).HasValue()); ASSERT_TRUE(
v1.SetProperty(prop.second, storage::PropertyValue(42)).HasValue());
auto v2 = dba.InsertVertex(); auto v2 = dba.InsertVertex();
auto v3 = dba.InsertVertex(); auto v3 = dba.InsertVertex();
auto edge_type = dba.NameToEdgeType("Edge"); auto edge_type = dba.NameToEdgeType("Edge");
@ -801,7 +803,8 @@ TEST(QueryPlan, FilterRemove) {
// Create a graph such that (v1 {prop: 42}) is connected to v2 and v3. // Create a graph such that (v1 {prop: 42}) is connected to v2 and v3.
auto v1 = dba.InsertVertex(); auto v1 = dba.InsertVertex();
auto prop = PROPERTY_PAIR("property"); auto prop = PROPERTY_PAIR("property");
ASSERT_TRUE(v1.SetProperty(prop.second, PropertyValue(42)).HasValue()); ASSERT_TRUE(
v1.SetProperty(prop.second, storage::PropertyValue(42)).HasValue());
auto v2 = dba.InsertVertex(); auto v2 = dba.InsertVertex();
auto v3 = dba.InsertVertex(); auto v3 = dba.InsertVertex();
auto edge_type = dba.NameToEdgeType("Edge"); auto edge_type = dba.NameToEdgeType("Edge");
@ -829,7 +832,7 @@ TEST(QueryPlan, FilterRemove) {
EXPECT_EQ(2, PullAll(*rem, &context)); EXPECT_EQ(2, PullAll(*rem, &context));
dba.AdvanceCommand(); dba.AdvanceCommand();
EXPECT_EQ(v1.GetProperty(storage::View::OLD, prop.second)->type(), EXPECT_EQ(v1.GetProperty(storage::View::OLD, prop.second)->type(),
PropertyValue::Type::Null); storage::PropertyValue::Type::Null);
} }
TEST(QueryPlan, SetRemove) { TEST(QueryPlan, SetRemove) {
@ -847,9 +850,10 @@ TEST(QueryPlan, SetRemove) {
// MATCH (n) SET n :label1 :label2 REMOVE n :label1 :label2 // MATCH (n) SET n :label1 :label2 REMOVE n :label1 :label2
auto scan_all = MakeScanAll(storage, symbol_table, "n"); auto scan_all = MakeScanAll(storage, symbol_table, "n");
auto set = std::make_shared<plan::SetLabels>( auto set = std::make_shared<plan::SetLabels>(
scan_all.op_, scan_all.sym_, std::vector<storage::Label>{label1, label2}); scan_all.op_, scan_all.sym_,
std::vector<storage::LabelId>{label1, label2});
auto rem = std::make_shared<plan::RemoveLabels>( auto rem = std::make_shared<plan::RemoveLabels>(
set, scan_all.sym_, std::vector<storage::Label>{label1, label2}); set, scan_all.sym_, std::vector<storage::LabelId>{label1, label2});
auto context = MakeContext(storage, symbol_table, &dba); auto context = MakeContext(storage, symbol_table, &dba);
EXPECT_EQ(1, PullAll(*rem, &context)); EXPECT_EQ(1, PullAll(*rem, &context));
dba.AdvanceCommand(); dba.AdvanceCommand();
@ -898,13 +902,13 @@ TEST(QueryPlan, Merge) {
dba.AdvanceCommand(); dba.AdvanceCommand();
ASSERT_EQ(v1.GetProperty(storage::View::OLD, prop.second)->type(), ASSERT_EQ(v1.GetProperty(storage::View::OLD, prop.second)->type(),
PropertyValue::Type::Int); storage::PropertyValue::Type::Int);
ASSERT_EQ(v1.GetProperty(storage::View::OLD, prop.second)->ValueInt(), 1); ASSERT_EQ(v1.GetProperty(storage::View::OLD, prop.second)->ValueInt(), 1);
ASSERT_EQ(v2.GetProperty(storage::View::OLD, prop.second)->type(), ASSERT_EQ(v2.GetProperty(storage::View::OLD, prop.second)->type(),
PropertyValue::Type::Int); storage::PropertyValue::Type::Int);
ASSERT_EQ(v2.GetProperty(storage::View::OLD, prop.second)->ValueInt(), 1); ASSERT_EQ(v2.GetProperty(storage::View::OLD, prop.second)->ValueInt(), 1);
ASSERT_EQ(v3.GetProperty(storage::View::OLD, prop.second)->type(), ASSERT_EQ(v3.GetProperty(storage::View::OLD, prop.second)->type(),
PropertyValue::Type::Int); storage::PropertyValue::Type::Int);
ASSERT_EQ(v3.GetProperty(storage::View::OLD, prop.second)->ValueInt(), 2); ASSERT_EQ(v3.GetProperty(storage::View::OLD, prop.second)->ValueInt(), 2);
} }
@ -977,7 +981,7 @@ TEST(QueryPlan, SetLabelsOnNull) {
auto optional = std::make_shared<plan::Optional>(nullptr, n.op_, auto optional = std::make_shared<plan::Optional>(nullptr, n.op_,
std::vector<Symbol>{n.sym_}); std::vector<Symbol>{n.sym_});
auto set_op = std::make_shared<plan::SetLabels>( auto set_op = std::make_shared<plan::SetLabels>(
optional, n.sym_, std::vector<storage::Label>{label}); optional, n.sym_, std::vector<storage::LabelId>{label});
EXPECT_EQ(0, CountIterable(dba.Vertices(storage::View::OLD))); EXPECT_EQ(0, CountIterable(dba.Vertices(storage::View::OLD)));
auto context = MakeContext(storage, symbol_table, &dba); auto context = MakeContext(storage, symbol_table, &dba);
EXPECT_EQ(1, PullAll(*set_op, &context)); EXPECT_EQ(1, PullAll(*set_op, &context));
@ -1012,7 +1016,7 @@ TEST(QueryPlan, RemoveLabelsOnNull) {
auto optional = std::make_shared<plan::Optional>(nullptr, n.op_, auto optional = std::make_shared<plan::Optional>(nullptr, n.op_,
std::vector<Symbol>{n.sym_}); std::vector<Symbol>{n.sym_});
auto remove_op = std::make_shared<plan::RemoveLabels>( auto remove_op = std::make_shared<plan::RemoveLabels>(
optional, n.sym_, std::vector<storage::Label>{label}); optional, n.sym_, std::vector<storage::LabelId>{label});
EXPECT_EQ(0, CountIterable(dba.Vertices(storage::View::OLD))); EXPECT_EQ(0, CountIterable(dba.Vertices(storage::View::OLD)));
auto context = MakeContext(storage, symbol_table, &dba); auto context = MakeContext(storage, symbol_table, &dba);
EXPECT_EQ(1, PullAll(*remove_op, &context)); EXPECT_EQ(1, PullAll(*remove_op, &context));
@ -1076,8 +1080,9 @@ TEST(QueryPlan, DeleteSetPropertiesFrom) {
// Add a single vertex. // Add a single vertex.
{ {
auto v = dba.InsertVertex(); auto v = dba.InsertVertex();
ASSERT_TRUE(v.SetProperty(dba.NameToProperty("property"), PropertyValue(1)) ASSERT_TRUE(
.HasValue()); v.SetProperty(dba.NameToProperty("property"), storage::PropertyValue(1))
.HasValue());
} }
dba.AdvanceCommand(); dba.AdvanceCommand();
EXPECT_EQ(1, CountIterable(dba.Vertices(storage::View::OLD))); EXPECT_EQ(1, CountIterable(dba.Vertices(storage::View::OLD)));
@ -1113,7 +1118,7 @@ TEST(QueryPlan, DeleteRemoveLabels) {
auto n_get = storage.Create<Identifier>("n")->MapTo(n.sym_); auto n_get = storage.Create<Identifier>("n")->MapTo(n.sym_);
auto delete_op = std::make_shared<plan::Delete>( auto delete_op = std::make_shared<plan::Delete>(
n.op_, std::vector<Expression *>{n_get}, false); n.op_, std::vector<Expression *>{n_get}, false);
std::vector<storage::Label> labels{dba.NameToLabel("label")}; std::vector<storage::LabelId> labels{dba.NameToLabel("label")};
auto rem_op = std::make_shared<plan::RemoveLabels>(delete_op, n.sym_, labels); auto rem_op = std::make_shared<plan::RemoveLabels>(delete_op, n.sym_, labels);
auto context = MakeContext(storage, symbol_table, &dba); auto context = MakeContext(storage, symbol_table, &dba);
EXPECT_THROW(PullAll(*rem_op, &context), QueryRuntimeException); EXPECT_THROW(PullAll(*rem_op, &context), QueryRuntimeException);

View File

@ -148,7 +148,7 @@ TEST(QueryPlan, NodeFilterLabelsAndProperties) {
query::DbAccessor dba(&storage_dba); query::DbAccessor dba(&storage_dba);
// add a few nodes to the database // add a few nodes to the database
storage::Label label = dba.NameToLabel("Label"); storage::LabelId label = dba.NameToLabel("Label");
auto property = PROPERTY_PAIR("Property"); auto property = PROPERTY_PAIR("Property");
auto v1 = dba.InsertVertex(); auto v1 = dba.InsertVertex();
auto v2 = dba.InsertVertex(); auto v2 = dba.InsertVertex();
@ -163,10 +163,14 @@ TEST(QueryPlan, NodeFilterLabelsAndProperties) {
ASSERT_TRUE(v2.AddLabel(label).HasValue()); ASSERT_TRUE(v2.AddLabel(label).HasValue());
ASSERT_TRUE(v3.AddLabel(label).HasValue()); ASSERT_TRUE(v3.AddLabel(label).HasValue());
// v1 and v4 will have the right properties // v1 and v4 will have the right properties
ASSERT_TRUE(v1.SetProperty(property.second, PropertyValue(42)).HasValue()); ASSERT_TRUE(
ASSERT_TRUE(v2.SetProperty(property.second, PropertyValue(1)).HasValue()); v1.SetProperty(property.second, storage::PropertyValue(42)).HasValue());
ASSERT_TRUE(v4.SetProperty(property.second, PropertyValue(42)).HasValue()); ASSERT_TRUE(
ASSERT_TRUE(v5.SetProperty(property.second, PropertyValue(1)).HasValue()); v2.SetProperty(property.second, storage::PropertyValue(1)).HasValue());
ASSERT_TRUE(
v4.SetProperty(property.second, storage::PropertyValue(42)).HasValue());
ASSERT_TRUE(
v5.SetProperty(property.second, storage::PropertyValue(1)).HasValue());
dba.AdvanceCommand(); dba.AdvanceCommand();
AstStorage storage; AstStorage storage;
@ -205,9 +209,9 @@ TEST(QueryPlan, NodeFilterMultipleLabels) {
query::DbAccessor dba(&storage_dba); query::DbAccessor dba(&storage_dba);
// add a few nodes to the database // add a few nodes to the database
storage::Label label1 = dba.NameToLabel("label1"); storage::LabelId label1 = dba.NameToLabel("label1");
storage::Label label2 = dba.NameToLabel("label2"); storage::LabelId label2 = dba.NameToLabel("label2");
storage::Label label3 = dba.NameToLabel("label3"); storage::LabelId label3 = dba.NameToLabel("label3");
// the test will look for nodes that have label1 and label2 // the test will look for nodes that have label1 and label2
dba.InsertVertex(); // NOT accepted dba.InsertVertex(); // NOT accepted
ASSERT_TRUE(dba.InsertVertex().AddLabel(label1).HasValue()); // NOT accepted ASSERT_TRUE(dba.InsertVertex().AddLabel(label1).HasValue()); // NOT accepted
@ -481,9 +485,9 @@ class QueryPlanExpandVariable : public testing::Test {
storage::Storage::Accessor storage_dba{db.Access()}; storage::Storage::Accessor storage_dba{db.Access()};
query::DbAccessor dba{&storage_dba}; query::DbAccessor dba{&storage_dba};
// labels for layers in the double chain // labels for layers in the double chain
std::vector<storage::Label> labels; std::vector<storage::LabelId> labels;
// for all the edges // for all the edges
storage::EdgeType edge_type = dba.NameToEdgeType("edge_type"); storage::EdgeTypeId edge_type = dba.NameToEdgeType("edge_type");
AstStorage storage; AstStorage storage;
SymbolTable symbol_table; SymbolTable symbol_table;
@ -509,7 +513,7 @@ class QueryPlanExpandVariable : public testing::Test {
auto edge = dba.InsertEdge(&v_from, &v_to, edge_type); auto edge = dba.InsertEdge(&v_from, &v_to, edge_type);
ASSERT_TRUE( ASSERT_TRUE(
edge->SetProperty(dba.NameToProperty("p"), edge->SetProperty(dba.NameToProperty("p"),
PropertyValue(fmt::format( storage::PropertyValue(fmt::format(
"V{}{}->V{}{}", from_layer_ind, v_from_ind, "V{}{}->V{}{}", from_layer_ind, v_from_ind,
from_layer_ind + 1, v_to_ind))) from_layer_ind + 1, v_to_ind)))
.HasValue()); .HasValue());
@ -538,7 +542,7 @@ class QueryPlanExpandVariable : public testing::Test {
std::shared_ptr<LogicalOperator> AddMatch( std::shared_ptr<LogicalOperator> AddMatch(
std::shared_ptr<LogicalOperator> input_op, const std::string &node_from, std::shared_ptr<LogicalOperator> input_op, const std::string &node_from,
int layer, EdgeAtom::Direction direction, int layer, EdgeAtom::Direction direction,
const std::vector<storage::EdgeType> &edge_types, const std::vector<storage::EdgeTypeId> &edge_types,
std::optional<size_t> lower, std::optional<size_t> upper, Symbol edge_sym, std::optional<size_t> lower, std::optional<size_t> upper, Symbol edge_sym,
const std::string &node_to, storage::View view, bool is_reverse = false) { const std::string &node_to, storage::View view, bool is_reverse = false) {
auto n_from = MakeScanAll(storage, symbol_table, node_from, input_op); auto n_from = MakeScanAll(storage, symbol_table, node_from, input_op);
@ -821,8 +825,8 @@ class QueryPlanExpandWeightedShortestPath : public testing::Test {
storage::Storage db; storage::Storage db;
storage::Storage::Accessor storage_dba{db.Access()}; storage::Storage::Accessor storage_dba{db.Access()};
query::DbAccessor dba{&storage_dba}; query::DbAccessor dba{&storage_dba};
std::pair<std::string, storage::Property> prop = PROPERTY_PAIR("property"); std::pair<std::string, storage::PropertyId> prop = PROPERTY_PAIR("property");
storage::EdgeType edge_type = dba.NameToEdgeType("edge_type"); storage::EdgeTypeId edge_type = dba.NameToEdgeType("edge_type");
// make 5 vertices because we'll need to compare against them exactly // make 5 vertices because we'll need to compare against them exactly
// v[0] has `prop` with the value 0 // v[0] has `prop` with the value 0
@ -846,14 +850,15 @@ class QueryPlanExpandWeightedShortestPath : public testing::Test {
void SetUp() { void SetUp() {
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
v.push_back(dba.InsertVertex()); v.push_back(dba.InsertVertex());
ASSERT_TRUE( ASSERT_TRUE(v.back()
v.back().SetProperty(prop.second, PropertyValue(i)).HasValue()); .SetProperty(prop.second, storage::PropertyValue(i))
.HasValue());
} }
auto add_edge = [&](int from, int to, double weight) { auto add_edge = [&](int from, int to, double weight) {
auto edge = dba.InsertEdge(&v[from], &v[to], edge_type); auto edge = dba.InsertEdge(&v[from], &v[to], edge_type);
ASSERT_TRUE( ASSERT_TRUE(edge->SetProperty(prop.second, storage::PropertyValue(weight))
edge->SetProperty(prop.second, PropertyValue(weight)).HasValue()); .HasValue());
e.emplace(std::make_pair(from, to), *edge); e.emplace(std::make_pair(from, to), *edge);
}; };
@ -896,7 +901,7 @@ class QueryPlanExpandWeightedShortestPath : public testing::Test {
auto filter_lambda = last_op = std::make_shared<ExpandVariable>( auto filter_lambda = last_op = std::make_shared<ExpandVariable>(
last_op, n.sym_, node_sym, edge_list_sym, last_op, n.sym_, node_sym, edge_list_sym,
EdgeAtom::Type::WEIGHTED_SHORTEST_PATH, direction, EdgeAtom::Type::WEIGHTED_SHORTEST_PATH, direction,
std::vector<storage::EdgeType>{}, false, nullptr, std::vector<storage::EdgeTypeId>{}, false, nullptr,
max_depth ? LITERAL(max_depth.value()) : nullptr, max_depth ? LITERAL(max_depth.value()) : nullptr,
existing_node_input != nullptr, existing_node_input != nullptr,
ExpansionLambda{filter_edge, filter_node, where}, ExpansionLambda{filter_edge, filter_node, where},
@ -1099,11 +1104,12 @@ TEST_F(QueryPlanExpandWeightedShortestPath, UpperBound) {
} }
{ {
auto new_vertex = dba.InsertVertex(); auto new_vertex = dba.InsertVertex();
ASSERT_TRUE( ASSERT_TRUE(new_vertex.SetProperty(prop.second, storage::PropertyValue(5))
new_vertex.SetProperty(prop.second, PropertyValue(5)).HasValue()); .HasValue());
auto edge = dba.InsertEdge(&v[4], &new_vertex, edge_type); auto edge = dba.InsertEdge(&v[4], &new_vertex, edge_type);
ASSERT_TRUE(edge.HasValue()); ASSERT_TRUE(edge.HasValue());
ASSERT_TRUE(edge->SetProperty(prop.second, PropertyValue(2)).HasValue()); ASSERT_TRUE(
edge->SetProperty(prop.second, storage::PropertyValue(2)).HasValue());
dba.AdvanceCommand(); dba.AdvanceCommand();
auto results = ExpandWShortest(EdgeAtom::Direction::BOTH, 3, LITERAL(true)); auto results = ExpandWShortest(EdgeAtom::Direction::BOTH, 3, LITERAL(true));
@ -1124,11 +1130,13 @@ TEST_F(QueryPlanExpandWeightedShortestPath, UpperBound) {
TEST_F(QueryPlanExpandWeightedShortestPath, NonNumericWeight) { TEST_F(QueryPlanExpandWeightedShortestPath, NonNumericWeight) {
auto new_vertex = dba.InsertVertex(); auto new_vertex = dba.InsertVertex();
ASSERT_TRUE(new_vertex.SetProperty(prop.second, PropertyValue(5)).HasValue()); ASSERT_TRUE(new_vertex.SetProperty(prop.second, storage::PropertyValue(5))
.HasValue());
auto edge = dba.InsertEdge(&v[4], &new_vertex, edge_type); auto edge = dba.InsertEdge(&v[4], &new_vertex, edge_type);
ASSERT_TRUE(edge.HasValue()); ASSERT_TRUE(edge.HasValue());
ASSERT_TRUE( ASSERT_TRUE(
edge->SetProperty(prop.second, PropertyValue("not a number")).HasValue()); edge->SetProperty(prop.second, storage::PropertyValue("not a number"))
.HasValue());
dba.AdvanceCommand(); dba.AdvanceCommand();
EXPECT_THROW(ExpandWShortest(EdgeAtom::Direction::BOTH, 1000, LITERAL(true)), EXPECT_THROW(ExpandWShortest(EdgeAtom::Direction::BOTH, 1000, LITERAL(true)),
QueryRuntimeException); QueryRuntimeException);
@ -1136,10 +1144,11 @@ TEST_F(QueryPlanExpandWeightedShortestPath, NonNumericWeight) {
TEST_F(QueryPlanExpandWeightedShortestPath, NegativeWeight) { TEST_F(QueryPlanExpandWeightedShortestPath, NegativeWeight) {
auto new_vertex = dba.InsertVertex(); auto new_vertex = dba.InsertVertex();
ASSERT_TRUE(new_vertex.SetProperty(prop.second, PropertyValue(5)).HasValue()); ASSERT_TRUE(new_vertex.SetProperty(prop.second, storage::PropertyValue(5))
.HasValue());
auto edge = dba.InsertEdge(&v[4], &new_vertex, edge_type); auto edge = dba.InsertEdge(&v[4], &new_vertex, edge_type);
ASSERT_TRUE(edge.HasValue()); ASSERT_TRUE(edge.HasValue());
ASSERT_TRUE(edge->SetProperty(prop.second, PropertyValue(-10)) ASSERT_TRUE(edge->SetProperty(prop.second, storage::PropertyValue(-10))
.HasValue()); // negative weight .HasValue()); // negative weight
dba.AdvanceCommand(); dba.AdvanceCommand();
EXPECT_THROW(ExpandWShortest(EdgeAtom::Direction::BOTH, 1000, LITERAL(true)), EXPECT_THROW(ExpandWShortest(EdgeAtom::Direction::BOTH, 1000, LITERAL(true)),
@ -1163,12 +1172,12 @@ TEST(QueryPlan, ExpandOptional) {
auto prop = dba.NameToProperty("p"); auto prop = dba.NameToProperty("p");
auto edge_type = dba.NameToEdgeType("T"); auto edge_type = dba.NameToEdgeType("T");
auto v1 = dba.InsertVertex(); auto v1 = dba.InsertVertex();
ASSERT_TRUE(v1.SetProperty(prop, PropertyValue(1)).HasValue()); ASSERT_TRUE(v1.SetProperty(prop, storage::PropertyValue(1)).HasValue());
auto v2 = dba.InsertVertex(); auto v2 = dba.InsertVertex();
ASSERT_TRUE(v2.SetProperty(prop, PropertyValue(2)).HasValue()); ASSERT_TRUE(v2.SetProperty(prop, storage::PropertyValue(2)).HasValue());
ASSERT_TRUE(dba.InsertEdge(&v1, &v2, edge_type).HasValue()); ASSERT_TRUE(dba.InsertEdge(&v1, &v2, edge_type).HasValue());
auto v3 = dba.InsertVertex(); auto v3 = dba.InsertVertex();
ASSERT_TRUE(v3.SetProperty(prop, PropertyValue(2)).HasValue()); ASSERT_TRUE(v3.SetProperty(prop, storage::PropertyValue(2)).HasValue());
ASSERT_TRUE(dba.InsertEdge(&v1, &v3, edge_type).HasValue()); ASSERT_TRUE(dba.InsertEdge(&v1, &v3, edge_type).HasValue());
dba.AdvanceCommand(); dba.AdvanceCommand();
@ -1196,7 +1205,7 @@ TEST(QueryPlan, ExpandOptional) {
ASSERT_EQ(row[0].type(), TypedValue::Type::Vertex); ASSERT_EQ(row[0].type(), TypedValue::Type::Vertex);
auto &va = row[0].ValueVertex(); auto &va = row[0].ValueVertex();
auto va_p = *va.GetProperty(storage::View::OLD, prop); auto va_p = *va.GetProperty(storage::View::OLD, prop);
ASSERT_EQ(va_p.type(), PropertyValue::Type::Int); ASSERT_EQ(va_p.type(), storage::PropertyValue::Type::Int);
if (va_p.ValueInt() == 1) { if (va_p.ValueInt() == 1) {
v1_is_n_count++; v1_is_n_count++;
EXPECT_EQ(row[1].type(), TypedValue::Type::Edge); EXPECT_EQ(row[1].type(), TypedValue::Type::Edge);
@ -1298,7 +1307,7 @@ TEST(QueryPlan, OptionalMatchThenExpandToMissingNode) {
node->identifier_->MapTo(with_n_sym); node->identifier_->MapTo(with_n_sym);
auto expand = std::make_shared<plan::Expand>( auto expand = std::make_shared<plan::Expand>(
m.op_, m.sym_, with_n_sym, edge_sym, edge_direction, m.op_, m.sym_, with_n_sym, edge_sym, edge_direction,
std::vector<storage::EdgeType>{}, true, storage::View::OLD); std::vector<storage::EdgeTypeId>{}, true, storage::View::OLD);
// RETURN m // RETURN m
auto m_ne = NEXPR("m", IDENT("m")->MapTo(m.sym_)) auto m_ne = NEXPR("m", IDENT("m")->MapTo(m.sym_))
->MapTo(symbol_table.CreateSymbol("m", true)); ->MapTo(symbol_table.CreateSymbol("m", true));
@ -1331,9 +1340,10 @@ TEST(QueryPlan, ExpandExistingNode) {
EdgeAtom::Direction::OUT, {}, "n", with_existing, EdgeAtom::Direction::OUT, {}, "n", with_existing,
storage::View::OLD); storage::View::OLD);
if (with_existing) if (with_existing)
r_n.op_ = std::make_shared<Expand>( r_n.op_ = std::make_shared<Expand>(n.op_, n.sym_, n.sym_, r_n.edge_sym_,
n.op_, n.sym_, n.sym_, r_n.edge_sym_, r_n.edge_->direction_, r_n.edge_->direction_,
std::vector<storage::EdgeType>{}, with_existing, storage::View::OLD); std::vector<storage::EdgeTypeId>{},
with_existing, storage::View::OLD);
// make a named expression and a produce // make a named expression and a produce
auto output = auto output =
@ -1380,7 +1390,7 @@ TEST(QueryPlan, EdgeFilter) {
// where only one edge will qualify // where only one edge will qualify
// and there are all combinations of // and there are all combinations of
// (edge_type yes|no) * (property yes|absent|no) // (edge_type yes|no) * (property yes|absent|no)
std::vector<storage::EdgeType> edge_types; std::vector<storage::EdgeTypeId> edge_types;
for (int j = 0; j < 2; ++j) for (int j = 0; j < 2; ++j)
edge_types.push_back(dba.NameToEdgeType("et" + std::to_string(j))); edge_types.push_back(dba.NameToEdgeType("et" + std::to_string(j)));
std::vector<query::VertexAccessor> vertices; std::vector<query::VertexAccessor> vertices;
@ -1393,12 +1403,12 @@ TEST(QueryPlan, EdgeFilter) {
switch (i % 3) { switch (i % 3) {
case 0: case 0:
ASSERT_TRUE(edges.back() ASSERT_TRUE(edges.back()
.SetProperty(prop.second, PropertyValue(42)) .SetProperty(prop.second, storage::PropertyValue(42))
.HasValue()); .HasValue());
break; break;
case 1: case 1:
ASSERT_TRUE(edges.back() ASSERT_TRUE(edges.back()
.SetProperty(prop.second, PropertyValue(100)) .SetProperty(prop.second, storage::PropertyValue(100))
.HasValue()); .HasValue());
break; break;
default: default:
@ -1438,7 +1448,8 @@ TEST(QueryPlan, EdgeFilter) {
EXPECT_EQ(1, test_filter()); EXPECT_EQ(1, test_filter());
// test that edge filtering always filters on old state // test that edge filtering always filters on old state
for (auto &edge : edges) for (auto &edge : edges)
ASSERT_TRUE(edge.SetProperty(prop.second, PropertyValue(42)).HasValue()); ASSERT_TRUE(
edge.SetProperty(prop.second, storage::PropertyValue(42)).HasValue());
EXPECT_EQ(1, test_filter()); EXPECT_EQ(1, test_filter());
dba.AdvanceCommand(); dba.AdvanceCommand();
EXPECT_EQ(3, test_filter()); EXPECT_EQ(3, test_filter());
@ -1486,9 +1497,10 @@ TEST(QueryPlan, Filter) {
// add a 6 nodes with property 'prop', 2 have true as value // add a 6 nodes with property 'prop', 2 have true as value
auto property = PROPERTY_PAIR("property"); auto property = PROPERTY_PAIR("property");
for (int i = 0; i < 6; ++i) for (int i = 0; i < 6; ++i)
ASSERT_TRUE(dba.InsertVertex() ASSERT_TRUE(
.SetProperty(property.second, PropertyValue(i % 3 == 0)) dba.InsertVertex()
.HasValue()); .SetProperty(property.second, storage::PropertyValue(i % 3 == 0))
.HasValue());
dba.InsertVertex(); // prop not set, gives NULL dba.InsertVertex(); // prop not set, gives NULL
dba.AdvanceCommand(); dba.AdvanceCommand();
@ -1633,21 +1645,24 @@ TEST(QueryPlan, ScanAllByLabelProperty) {
auto label = db.NameToLabel("label"); auto label = db.NameToLabel("label");
auto prop = db.NameToProperty("prop"); auto prop = db.NameToProperty("prop");
// vertex property values that will be stored into the DB // vertex property values that will be stored into the DB
std::vector<PropertyValue> values{ std::vector<storage::PropertyValue> values{
PropertyValue(true), storage::PropertyValue(true),
PropertyValue(false), storage::PropertyValue(false),
PropertyValue("a"), storage::PropertyValue("a"),
PropertyValue("b"), storage::PropertyValue("b"),
PropertyValue("c"), storage::PropertyValue("c"),
PropertyValue(0), storage::PropertyValue(0),
PropertyValue(1), storage::PropertyValue(1),
PropertyValue(2), storage::PropertyValue(2),
PropertyValue(0.5), storage::PropertyValue(0.5),
PropertyValue(1.5), storage::PropertyValue(1.5),
PropertyValue(2.5), storage::PropertyValue(2.5),
PropertyValue(std::vector<PropertyValue>{PropertyValue(0)}), storage::PropertyValue(
PropertyValue(std::vector<PropertyValue>{PropertyValue(1)}), std::vector<storage::PropertyValue>{storage::PropertyValue(0)}),
PropertyValue(std::vector<PropertyValue>{PropertyValue(2)})}; storage::PropertyValue(
std::vector<storage::PropertyValue>{storage::PropertyValue(1)}),
storage::PropertyValue(
std::vector<storage::PropertyValue>{storage::PropertyValue(2)})};
{ {
auto storage_dba = db.Access(); auto storage_dba = db.Access();
query::DbAccessor dba(&storage_dba); query::DbAccessor dba(&storage_dba);
@ -1701,23 +1716,25 @@ TEST(QueryPlan, ScanAllByLabelProperty) {
check(TypedValue(1.5), Bound::Type::EXCLUSIVE, TypedValue(2.5), check(TypedValue(1.5), Bound::Type::EXCLUSIVE, TypedValue(2.5),
Bound::Type::INCLUSIVE, {TypedValue(2), TypedValue(2.5)}); Bound::Type::INCLUSIVE, {TypedValue(2), TypedValue(2.5)});
auto are_comparable = [](PropertyValue::Type a, PropertyValue::Type b) { auto are_comparable = [](storage::PropertyValue::Type a,
auto is_numeric = [](const PropertyValue::Type t) { storage::PropertyValue::Type b) {
return t == PropertyValue::Type::Int || t == PropertyValue::Type::Double; auto is_numeric = [](const storage::PropertyValue::Type t) {
return t == storage::PropertyValue::Type::Int ||
t == storage::PropertyValue::Type::Double;
}; };
return a == b || (is_numeric(a) && is_numeric(b)); return a == b || (is_numeric(a) && is_numeric(b));
}; };
auto is_orderable = [](const PropertyValue &t) { auto is_orderable = [](const storage::PropertyValue &t) {
return t.IsNull() || t.IsInt() || t.IsDouble() || t.IsString(); return t.IsNull() || t.IsInt() || t.IsDouble() || t.IsString();
}; };
// when a range contains different types, nothing should get returned // when a range contains different types, nothing should get returned
for (const auto &value_a : values) { for (const auto &value_a : values) {
for (const auto &value_b : values) { for (const auto &value_b : values) {
if (are_comparable(static_cast<PropertyValue>(value_a).type(), if (are_comparable(static_cast<storage::PropertyValue>(value_a).type(),
static_cast<PropertyValue>(value_b).type())) static_cast<storage::PropertyValue>(value_b).type()))
continue; continue;
if (is_orderable(value_a) && is_orderable(value_b)) { if (is_orderable(value_a) && is_orderable(value_b)) {
check(TypedValue(value_a), Bound::Type::INCLUSIVE, TypedValue(value_b), check(TypedValue(value_a), Bound::Type::INCLUSIVE, TypedValue(value_b),
@ -1756,11 +1773,13 @@ TEST(QueryPlan, ScanAllByLabelPropertyEqualityNoError) {
query::DbAccessor dba(&storage_dba); query::DbAccessor dba(&storage_dba);
auto number_vertex = dba.InsertVertex(); auto number_vertex = dba.InsertVertex();
ASSERT_TRUE(number_vertex.AddLabel(label).HasValue()); ASSERT_TRUE(number_vertex.AddLabel(label).HasValue());
ASSERT_TRUE(number_vertex.SetProperty(prop, PropertyValue(42)).HasValue()); ASSERT_TRUE(
number_vertex.SetProperty(prop, storage::PropertyValue(42)).HasValue());
auto string_vertex = dba.InsertVertex(); auto string_vertex = dba.InsertVertex();
ASSERT_TRUE(string_vertex.AddLabel(label).HasValue()); ASSERT_TRUE(string_vertex.AddLabel(label).HasValue());
ASSERT_TRUE( ASSERT_TRUE(
string_vertex.SetProperty(prop, PropertyValue("string")).HasValue()); string_vertex.SetProperty(prop, storage::PropertyValue("string"))
.HasValue());
ASSERT_FALSE(dba.Commit().HasError()); ASSERT_FALSE(dba.Commit().HasError());
} }
db.CreateIndex(label, prop); db.CreateIndex(label, prop);
@ -1798,7 +1817,8 @@ TEST(QueryPlan, ScanAllByLabelPropertyValueError) {
for (int i = 0; i < 2; ++i) { for (int i = 0; i < 2; ++i) {
auto vertex = dba.InsertVertex(); auto vertex = dba.InsertVertex();
ASSERT_TRUE(vertex.AddLabel(label).HasValue()); ASSERT_TRUE(vertex.AddLabel(label).HasValue());
ASSERT_TRUE(vertex.SetProperty(prop, PropertyValue(i)).HasValue()); ASSERT_TRUE(
vertex.SetProperty(prop, storage::PropertyValue(i)).HasValue());
} }
ASSERT_FALSE(dba.Commit().HasError()); ASSERT_FALSE(dba.Commit().HasError());
} }
@ -1829,7 +1849,8 @@ TEST(QueryPlan, ScanAllByLabelPropertyRangeError) {
for (int i = 0; i < 2; ++i) { for (int i = 0; i < 2; ++i) {
auto vertex = dba.InsertVertex(); auto vertex = dba.InsertVertex();
ASSERT_TRUE(vertex.AddLabel(label).HasValue()); ASSERT_TRUE(vertex.AddLabel(label).HasValue());
ASSERT_TRUE(vertex.SetProperty(prop, PropertyValue(i)).HasValue()); ASSERT_TRUE(
vertex.SetProperty(prop, storage::PropertyValue(i)).HasValue());
} }
ASSERT_FALSE(dba.Commit().HasError()); ASSERT_FALSE(dba.Commit().HasError());
} }
@ -1885,8 +1906,8 @@ TEST(QueryPlan, ScanAllByLabelPropertyEqualNull) {
ASSERT_TRUE(vertex.AddLabel(label).HasValue()); ASSERT_TRUE(vertex.AddLabel(label).HasValue());
auto vertex_with_prop = dba.InsertVertex(); auto vertex_with_prop = dba.InsertVertex();
ASSERT_TRUE(vertex_with_prop.AddLabel(label).HasValue()); ASSERT_TRUE(vertex_with_prop.AddLabel(label).HasValue());
ASSERT_TRUE( ASSERT_TRUE(vertex_with_prop.SetProperty(prop, storage::PropertyValue(42))
vertex_with_prop.SetProperty(prop, PropertyValue(42)).HasValue()); .HasValue());
ASSERT_FALSE(dba.Commit().HasError()); ASSERT_FALSE(dba.Commit().HasError());
} }
db.CreateIndex(label, prop); db.CreateIndex(label, prop);
@ -1922,8 +1943,8 @@ TEST(QueryPlan, ScanAllByLabelPropertyRangeNull) {
ASSERT_TRUE(vertex.AddLabel(label).HasValue()); ASSERT_TRUE(vertex.AddLabel(label).HasValue());
auto vertex_with_prop = dba.InsertVertex(); auto vertex_with_prop = dba.InsertVertex();
ASSERT_TRUE(vertex_with_prop.AddLabel(label).HasValue()); ASSERT_TRUE(vertex_with_prop.AddLabel(label).HasValue());
ASSERT_TRUE( ASSERT_TRUE(vertex_with_prop.SetProperty(prop, storage::PropertyValue(42))
vertex_with_prop.SetProperty(prop, PropertyValue(42)).HasValue()); .HasValue());
ASSERT_FALSE(dba.Commit().HasError()); ASSERT_FALSE(dba.Commit().HasError());
} }
db.CreateIndex(label, prop); db.CreateIndex(label, prop);
@ -1956,7 +1977,7 @@ TEST(QueryPlan, ScanAllByLabelPropertyNoValueInIndexContinuation) {
query::DbAccessor dba(&storage_dba); query::DbAccessor dba(&storage_dba);
auto v = dba.InsertVertex(); auto v = dba.InsertVertex();
ASSERT_TRUE(v.AddLabel(label).HasValue()); ASSERT_TRUE(v.AddLabel(label).HasValue());
ASSERT_TRUE(v.SetProperty(prop, PropertyValue(2)).HasValue()); ASSERT_TRUE(v.SetProperty(prop, storage::PropertyValue(2)).HasValue());
ASSERT_FALSE(dba.Commit().HasError()); ASSERT_FALSE(dba.Commit().HasError());
} }
db.CreateIndex(label, prop); db.CreateIndex(label, prop);
@ -1997,10 +2018,10 @@ TEST(QueryPlan, ScanAllEqualsScanAllByLabelProperty) {
query::DbAccessor dba(&storage_dba); query::DbAccessor dba(&storage_dba);
auto v = dba.InsertVertex(); auto v = dba.InsertVertex();
ASSERT_TRUE(v.AddLabel(label).HasValue()); ASSERT_TRUE(v.AddLabel(label).HasValue());
ASSERT_TRUE( ASSERT_TRUE(v.SetProperty(prop, storage::PropertyValue(i < vertex_prop_count
v.SetProperty(prop, PropertyValue(i < vertex_prop_count ? prop_value1 ? prop_value1
: prop_value2)) : prop_value2))
.HasValue()); .HasValue());
ASSERT_FALSE(dba.Commit().HasError()); ASSERT_FALSE(dba.Commit().HasError());
} }

View File

@ -10,8 +10,8 @@ TEST(QueryPlan, CreateNodeWithAttributes) {
storage::Storage db; storage::Storage db;
auto dba = db.Access(); auto dba = db.Access();
auto label = storage::Label::FromInt(42); auto label = storage::LabelId::FromInt(42);
auto property = storage::Property::FromInt(1); auto property = storage::PropertyId::FromInt(1);
query::AstStorage ast; query::AstStorage ast;
query::SymbolTable symbol_table; query::SymbolTable symbol_table;

View File

@ -39,14 +39,17 @@ TEST_F(ExpressionPrettyPrinterTest, Literals) {
EXPECT_EQ(ToString(LITERAL(false)), "false"); EXPECT_EQ(ToString(LITERAL(false)), "false");
// [1 null "hello"] // [1 null "hello"]
std::vector<PropertyValue> values{PropertyValue(1), PropertyValue(), std::vector<storage::PropertyValue> values{storage::PropertyValue(1),
PropertyValue("hello")}; storage::PropertyValue(),
EXPECT_EQ(ToString(LITERAL(PropertyValue(values))), "[1, null, \"hello\"]"); storage::PropertyValue("hello")};
EXPECT_EQ(ToString(LITERAL(storage::PropertyValue(values))),
"[1, null, \"hello\"]");
// {hello: 1, there: 2} // {hello: 1, there: 2}
std::map<std::string, PropertyValue> map{{"hello", PropertyValue(1)}, std::map<std::string, storage::PropertyValue> map{
{"there", PropertyValue(2)}}; {"hello", storage::PropertyValue(1)},
EXPECT_EQ(ToString(LITERAL(PropertyValue(map))), {"there", storage::PropertyValue(2)}};
EXPECT_EQ(ToString(LITERAL(storage::PropertyValue(map))),
"{\"hello\": 1, \"there\": 2}"); "{\"hello\": 1, \"there\": 2}");
} }
@ -61,7 +64,7 @@ TEST_F(ExpressionPrettyPrinterTest, Identifiers) {
TEST_F(ExpressionPrettyPrinterTest, Reducing) { TEST_F(ExpressionPrettyPrinterTest, Reducing) {
// all(x in list where x.prop = 42) // all(x in list where x.prop = 42)
auto prop = dba.NameToProperty("prop"); auto prop = dba.NameToProperty("prop");
EXPECT_EQ(ToString(ALL("x", LITERAL(std::vector<PropertyValue>{}), EXPECT_EQ(ToString(ALL("x", LITERAL(std::vector<storage::PropertyValue>{}),
WHERE(EQ(PROPERTY_LOOKUP("x", prop), LITERAL(42))))), WHERE(EQ(PROPERTY_LOOKUP("x", prop), LITERAL(42))))),
"(All (Identifier \"x\") [] (== (PropertyLookup " "(All (Identifier \"x\") [] (== (PropertyLookup "
"(Identifier \"x\") \"prop\") 42))"); "(Identifier \"x\") \"prop\") 42))");

View File

@ -2,7 +2,7 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include "query/frontend/semantic/required_privileges.hpp" #include "query/frontend/semantic/required_privileges.hpp"
#include "storage/common/types/types.hpp" #include "storage/v2/id_types.hpp"
#include "query_common.hpp" #include "query_common.hpp"

View File

@ -264,11 +264,11 @@ TEST(TestVariableStartPlanner, MatchVariableExpandReferenceNode) {
auto id = dba.NameToProperty("id"); auto id = dba.NameToProperty("id");
// Graph (v1 {id:1}) -[:r1]-> (v2 {id: 2}) -[:r2]-> (v3 {id: 3}) // Graph (v1 {id:1}) -[:r1]-> (v2 {id: 2}) -[:r2]-> (v3 {id: 3})
auto v1 = dba.InsertVertex(); auto v1 = dba.InsertVertex();
ASSERT_TRUE(v1.SetProperty(id, PropertyValue(1)).HasValue()); ASSERT_TRUE(v1.SetProperty(id, storage::PropertyValue(1)).HasValue());
auto v2 = dba.InsertVertex(); auto v2 = dba.InsertVertex();
ASSERT_TRUE(v2.SetProperty(id, PropertyValue(2)).HasValue()); ASSERT_TRUE(v2.SetProperty(id, storage::PropertyValue(2)).HasValue());
auto v3 = dba.InsertVertex(); auto v3 = dba.InsertVertex();
ASSERT_TRUE(v3.SetProperty(id, PropertyValue(3)).HasValue()); ASSERT_TRUE(v3.SetProperty(id, storage::PropertyValue(3)).HasValue());
auto r1 = *dba.InsertEdge(&v1, &v2, dba.NameToEdgeType("r1")); auto r1 = *dba.InsertEdge(&v1, &v2, dba.NameToEdgeType("r1"));
auto r2 = *dba.InsertEdge(&v2, &v3, dba.NameToEdgeType("r2")); auto r2 = *dba.InsertEdge(&v2, &v3, dba.NameToEdgeType("r2"));
dba.AdvanceCommand(); dba.AdvanceCommand();
@ -295,7 +295,7 @@ TEST(TestVariableStartPlanner, MatchVariableExpandBoth) {
auto id = dba.NameToProperty("id"); auto id = dba.NameToProperty("id");
// Graph (v1 {id:1}) -[:r1]-> (v2) -[:r2]-> (v3) // Graph (v1 {id:1}) -[:r1]-> (v2) -[:r2]-> (v3)
auto v1 = dba.InsertVertex(); auto v1 = dba.InsertVertex();
ASSERT_TRUE(v1.SetProperty(id, PropertyValue(1)).HasValue()); ASSERT_TRUE(v1.SetProperty(id, storage::PropertyValue(1)).HasValue());
auto v2 = dba.InsertVertex(); auto v2 = dba.InsertVertex();
auto v3 = dba.InsertVertex(); auto v3 = dba.InsertVertex();
auto r1 = *dba.InsertEdge(&v1, &v2, dba.NameToEdgeType("r1")); auto r1 = *dba.InsertEdge(&v1, &v2, dba.NameToEdgeType("r1"));
@ -325,11 +325,11 @@ TEST(TestVariableStartPlanner, MatchBfs) {
auto id = dba.NameToProperty("id"); auto id = dba.NameToProperty("id");
// Graph (v1 {id:1}) -[:r1]-> (v2 {id: 2}) -[:r2]-> (v3 {id: 3}) // Graph (v1 {id:1}) -[:r1]-> (v2 {id: 2}) -[:r2]-> (v3 {id: 3})
auto v1 = dba.InsertVertex(); auto v1 = dba.InsertVertex();
ASSERT_TRUE(v1.SetProperty(id, PropertyValue(1)).HasValue()); ASSERT_TRUE(v1.SetProperty(id, storage::PropertyValue(1)).HasValue());
auto v2 = dba.InsertVertex(); auto v2 = dba.InsertVertex();
ASSERT_TRUE(v2.SetProperty(id, PropertyValue(2)).HasValue()); ASSERT_TRUE(v2.SetProperty(id, storage::PropertyValue(2)).HasValue());
auto v3 = dba.InsertVertex(); auto v3 = dba.InsertVertex();
ASSERT_TRUE(v3.SetProperty(id, PropertyValue(3)).HasValue()); ASSERT_TRUE(v3.SetProperty(id, storage::PropertyValue(3)).HasValue());
auto r1 = *dba.InsertEdge(&v1, &v2, dba.NameToEdgeType("r1")); auto r1 = *dba.InsertEdge(&v1, &v2, dba.NameToEdgeType("r1"));
ASSERT_TRUE(dba.InsertEdge(&v2, &v3, dba.NameToEdgeType("r2")).HasValue()); ASSERT_TRUE(dba.InsertEdge(&v2, &v3, dba.NameToEdgeType("r2")).HasValue());
dba.AdvanceCommand(); dba.AdvanceCommand();

View File

@ -5,20 +5,21 @@
#include "slk_common.hpp" #include "slk_common.hpp"
TEST(SlkAdvanced, PropertyValueList) { TEST(SlkAdvanced, PropertyValueList) {
std::vector<PropertyValue> original{PropertyValue("hello world!"), std::vector<storage::PropertyValue> original{
PropertyValue(5), PropertyValue(1.123423), storage::PropertyValue("hello world!"), storage::PropertyValue(5),
PropertyValue(true), PropertyValue()}; storage::PropertyValue(1.123423), storage::PropertyValue(true),
ASSERT_EQ(original[0].type(), PropertyValue::Type::String); storage::PropertyValue()};
ASSERT_EQ(original[1].type(), PropertyValue::Type::Int); ASSERT_EQ(original[0].type(), storage::PropertyValue::Type::String);
ASSERT_EQ(original[2].type(), PropertyValue::Type::Double); ASSERT_EQ(original[1].type(), storage::PropertyValue::Type::Int);
ASSERT_EQ(original[3].type(), PropertyValue::Type::Bool); ASSERT_EQ(original[2].type(), storage::PropertyValue::Type::Double);
ASSERT_EQ(original[4].type(), PropertyValue::Type::Null); ASSERT_EQ(original[3].type(), storage::PropertyValue::Type::Bool);
ASSERT_EQ(original[4].type(), storage::PropertyValue::Type::Null);
slk::Loopback loopback; slk::Loopback loopback;
auto builder = loopback.GetBuilder(); auto builder = loopback.GetBuilder();
slk::Save(original, builder); slk::Save(original, builder);
std::vector<PropertyValue> decoded; std::vector<storage::PropertyValue> decoded;
auto reader = loopback.GetReader(); auto reader = loopback.GetReader();
slk::Load(&decoded, reader); slk::Load(&decoded, reader);
@ -26,23 +27,23 @@ TEST(SlkAdvanced, PropertyValueList) {
} }
TEST(SlkAdvanced, PropertyValueMap) { TEST(SlkAdvanced, PropertyValueMap) {
std::map<std::string, PropertyValue> original{ std::map<std::string, storage::PropertyValue> original{
{"hello", PropertyValue("world")}, {"hello", storage::PropertyValue("world")},
{"number", PropertyValue(5)}, {"number", storage::PropertyValue(5)},
{"real", PropertyValue(1.123423)}, {"real", storage::PropertyValue(1.123423)},
{"truth", PropertyValue(true)}, {"truth", storage::PropertyValue(true)},
{"nothing", PropertyValue()}}; {"nothing", storage::PropertyValue()}};
ASSERT_EQ(original["hello"].type(), PropertyValue::Type::String); ASSERT_EQ(original["hello"].type(), storage::PropertyValue::Type::String);
ASSERT_EQ(original["number"].type(), PropertyValue::Type::Int); ASSERT_EQ(original["number"].type(), storage::PropertyValue::Type::Int);
ASSERT_EQ(original["real"].type(), PropertyValue::Type::Double); ASSERT_EQ(original["real"].type(), storage::PropertyValue::Type::Double);
ASSERT_EQ(original["truth"].type(), PropertyValue::Type::Bool); ASSERT_EQ(original["truth"].type(), storage::PropertyValue::Type::Bool);
ASSERT_EQ(original["nothing"].type(), PropertyValue::Type::Null); ASSERT_EQ(original["nothing"].type(), storage::PropertyValue::Type::Null);
slk::Loopback loopback; slk::Loopback loopback;
auto builder = loopback.GetBuilder(); auto builder = loopback.GetBuilder();
slk::Save(original, builder); slk::Save(original, builder);
std::map<std::string, PropertyValue> decoded; std::map<std::string, storage::PropertyValue> decoded;
auto reader = loopback.GetReader(); auto reader = loopback.GetReader();
slk::Load(&decoded, reader); slk::Load(&decoded, reader);
@ -50,35 +51,37 @@ TEST(SlkAdvanced, PropertyValueMap) {
} }
TEST(SlkAdvanced, PropertyValueComplex) { TEST(SlkAdvanced, PropertyValueComplex) {
std::vector<PropertyValue> vec_v{PropertyValue("hello world!"), std::vector<storage::PropertyValue> vec_v{
PropertyValue(5), PropertyValue(1.123423), storage::PropertyValue("hello world!"), storage::PropertyValue(5),
PropertyValue(true), PropertyValue()}; storage::PropertyValue(1.123423), storage::PropertyValue(true),
ASSERT_EQ(vec_v[0].type(), PropertyValue::Type::String); storage::PropertyValue()};
ASSERT_EQ(vec_v[1].type(), PropertyValue::Type::Int); ASSERT_EQ(vec_v[0].type(), storage::PropertyValue::Type::String);
ASSERT_EQ(vec_v[2].type(), PropertyValue::Type::Double); ASSERT_EQ(vec_v[1].type(), storage::PropertyValue::Type::Int);
ASSERT_EQ(vec_v[3].type(), PropertyValue::Type::Bool); ASSERT_EQ(vec_v[2].type(), storage::PropertyValue::Type::Double);
ASSERT_EQ(vec_v[4].type(), PropertyValue::Type::Null); ASSERT_EQ(vec_v[3].type(), storage::PropertyValue::Type::Bool);
ASSERT_EQ(vec_v[4].type(), storage::PropertyValue::Type::Null);
std::map<std::string, PropertyValue> map_v{{"hello", PropertyValue("world")}, std::map<std::string, storage::PropertyValue> map_v{
{"number", PropertyValue(5)}, {"hello", storage::PropertyValue("world")},
{"real", PropertyValue(1.123423)}, {"number", storage::PropertyValue(5)},
{"truth", PropertyValue(true)}, {"real", storage::PropertyValue(1.123423)},
{"nothing", PropertyValue()}}; {"truth", storage::PropertyValue(true)},
ASSERT_EQ(map_v["hello"].type(), PropertyValue::Type::String); {"nothing", storage::PropertyValue()}};
ASSERT_EQ(map_v["number"].type(), PropertyValue::Type::Int); ASSERT_EQ(map_v["hello"].type(), storage::PropertyValue::Type::String);
ASSERT_EQ(map_v["real"].type(), PropertyValue::Type::Double); ASSERT_EQ(map_v["number"].type(), storage::PropertyValue::Type::Int);
ASSERT_EQ(map_v["truth"].type(), PropertyValue::Type::Bool); ASSERT_EQ(map_v["real"].type(), storage::PropertyValue::Type::Double);
ASSERT_EQ(map_v["nothing"].type(), PropertyValue::Type::Null); ASSERT_EQ(map_v["truth"].type(), storage::PropertyValue::Type::Bool);
ASSERT_EQ(map_v["nothing"].type(), storage::PropertyValue::Type::Null);
PropertyValue original( storage::PropertyValue original(std::vector<storage::PropertyValue>{
std::vector<PropertyValue>{PropertyValue(vec_v), PropertyValue(map_v)}); storage::PropertyValue(vec_v), storage::PropertyValue(map_v)});
ASSERT_EQ(original.type(), PropertyValue::Type::List); ASSERT_EQ(original.type(), storage::PropertyValue::Type::List);
slk::Loopback loopback; slk::Loopback loopback;
auto builder = loopback.GetBuilder(); auto builder = loopback.GetBuilder();
slk::Save(original, builder); slk::Save(original, builder);
PropertyValue decoded; storage::PropertyValue decoded;
auto reader = loopback.GetReader(); auto reader = loopback.GetReader();
slk::Load(&decoded, reader); slk::Load(&decoded, reader);

View File

@ -25,7 +25,7 @@ void EXPECT_PROP_EQ(const TypedValue &a, const TypedValue &b) {
EXPECT_PROP_TRUE(a == b); EXPECT_PROP_TRUE(a == b);
} }
void EXPECT_PROP_EQ(const PropertyValue &a, const TypedValue &b) { void EXPECT_PROP_EQ(const storage::PropertyValue &a, const TypedValue &b) {
EXPECT_PROP_EQ(TypedValue(a), b); EXPECT_PROP_EQ(TypedValue(a), b);
} }