diff --git a/include/import/csv_import.hpp b/include/import/csv_import.hpp index de14c8541..b72be4526 100644 --- a/include/import/csv_import.hpp +++ b/include/import/csv_import.hpp @@ -281,25 +281,29 @@ private: } else if (equal_str(type, "double[]")) { std::unique_ptr<Filler> f( make_array_filler<TG, double, ArrayDouble>( - *this, property_key<TG>(name, Flags::ArrayDouble), to_double)); + *this, property_key<TG>(name, Flags::ArrayDouble), + to_double)); return make_option(std::move(f)); } else if (equal_str(type, "int[]")) { std::unique_ptr<Filler> f( make_array_filler<TG, int32_t, ArrayInt32>( - *this, property_key<TG>(name, Flags::ArrayInt32), to_int32)); + *this, property_key<TG>(name, Flags::ArrayInt32), + to_int32)); return make_option(std::move(f)); } else if (equal_str(type, "long[]")) { std::unique_ptr<Filler> f( make_array_filler<TG, int64_t, ArrayInt64>( - *this, property_key<TG>(name, Flags::ArrayInt64), to_int64)); + *this, property_key<TG>(name, Flags::ArrayInt64), + to_int64)); return make_option(std::move(f)); } else if (equal_str(type, "string[]")) { std::unique_ptr<Filler> f( - make_array_filler<TG, string, ArrayString>( - *this, property_key<TG>(name, Flags::ArrayString), to_string)); + make_array_filler<TG, std::string, ArrayString>( + *this, property_key<TG>(name, Flags::ArrayString), + to_string)); return make_option(std::move(f)); } else { diff --git a/include/import/element_skeleton.hpp b/include/import/element_skeleton.hpp index b18f87f0e..3b93b0875 100644 --- a/include/import/element_skeleton.hpp +++ b/include/import/element_skeleton.hpp @@ -44,6 +44,8 @@ public: VertexAccessor add_vertex() { + assert(properties_e.empty()); + auto va = db.vertex_insert(); for (auto l : labels) { @@ -67,11 +69,13 @@ public: if (!to_va.is_present()) { return make_option(std::string("To field must be seted")); } + if (!type.is_present()) { + return make_option(std::string("Type field must be seted")); + } + assert(properties_v.empty()); auto ve = db.edge_insert(from_va.get(), to_va.get()); - if (type.is_present()) { - ve.edge_type(*type.get()); - } + ve.edge_type(*type.get()); for (auto prop : properties_e) { ve.set(std::move(prop)); diff --git a/include/storage/edges.hpp b/include/storage/edges.hpp index b9fccad94..de6b6ef99 100644 --- a/include/storage/edges.hpp +++ b/include/storage/edges.hpp @@ -34,10 +34,14 @@ public: EdgePropertyFamily &property_family_find_or_create(const std::string &name); private: - store_t edges; // TODO: Because familys wont be removed this could be done with more // efficent // data structure. prop_familys_t prop_familys; + + // NOTE: this must be before prop_familys field to be destroyed before them. + // Because there are property_family references in vertices. + store_t edges; + AtomicCounter<uint64_t> counter; }; diff --git a/include/storage/model/properties/array.hpp b/include/storage/model/properties/array.hpp index 9c7bdf996..263f0b032 100644 --- a/include/storage/model/properties/array.hpp +++ b/include/storage/model/properties/array.hpp @@ -56,7 +56,9 @@ public: return true; } - operator const Arr &() const { return value(); }; + // NOTE: OTHER METHODS WILL AUTOMATICALLY USE THIS IN CERTAIN SITUATIONS TO + // MOVE ARR OUT OF SHARED_PTR WHICH IS BAD + // operator const Arr &() const { return value(); }; private: std::shared_ptr<Arr> data; diff --git a/include/storage/model/properties/flags.hpp b/include/storage/model/properties/flags.hpp index 84cc5548d..0b29336a0 100644 --- a/include/storage/model/properties/flags.hpp +++ b/include/storage/model/properties/flags.hpp @@ -59,13 +59,13 @@ enum class Flags : unsigned ArrayFloat = (Float << 13) | Array, ArrayDouble = (Double << 13) | Array, - type_mask = 0xFFF + type_mask = 0xFFFFFF }; // Mask to turn flags into type. It passes all bits except 0x2 and 0x4 which // correspond // to True and False. -const unsigned flags_equal_mask = 0xFF9; +const unsigned flags_equal_mask = 0xFF3FF9; class Type : public TotalOrdering<Type> { @@ -75,10 +75,13 @@ public: Flags o = Flags(value); assert(o == Flags::Null || o == Flags::Bool || o == Flags::String || o == Flags::Int32 || o == Flags::Int64 || o == Flags::Float || - o == Flags::Double || o == Flags::Array); + o == Flags::Double || o == Flags::ArrayBool || + o == Flags::ArrayString || o == Flags::ArrayInt32 || + o == Flags::ArrayInt64 || o == Flags::ArrayFloat || + o == Flags::ArrayDouble); } - const std::string to_str() + const std::string to_str() const { switch (flags()) { case Flags::Null: @@ -95,8 +98,19 @@ public: return "float"; case Flags::Double: return "double"; - case Flags::Array: - return "array"; + case Flags::ArrayBool: + return "array_bool"; + case Flags::ArrayString: + return "array_string"; + case Flags::ArrayInt64: + return "array_int64"; + case Flags::ArrayInt32: + return "array_int32"; + case Flags::ArrayFloat: + return "array_float"; + case Flags::ArrayDouble: + return "array_double"; + default: assert(false); return "err_unknown_type_" + std::to_string(value); @@ -107,6 +121,11 @@ public: Type get_type() const { return *this; } + bool is_array() const + { + return (value & underlying_cast(Flags::Array)) != 0; + } + template <class T> bool is() const { diff --git a/include/storage/model/properties/property_family.hpp b/include/storage/model/properties/property_family.hpp index c5ab0fc7a..4206318a0 100644 --- a/include/storage/model/properties/property_family.hpp +++ b/include/storage/model/properties/property_family.hpp @@ -93,6 +93,11 @@ public: const PropertyFamily &get_family() const { return type->family; } + const std::string to_str() const + { + return std::string(family_name()); + } + private: const PropertyType *type; }; diff --git a/include/storage/model/properties/property_holder.hpp b/include/storage/model/properties/property_holder.hpp index 2355eeba4..c8a342061 100644 --- a/include/storage/model/properties/property_holder.hpp +++ b/include/storage/model/properties/property_holder.hpp @@ -98,6 +98,7 @@ public: default: assert(false); } + assert(key.get_type().flags() == Flags::Int64 || this->int64_v != 0); } PropertyHolder(PropertyHolder &&other) : key(other.key) @@ -118,6 +119,7 @@ public: default: assert(false); } + assert(key.get_type().flags() == Flags::Int64 || this->int64_v != 0); } ~PropertyHolder() @@ -133,6 +135,7 @@ public: { this->~PropertyHolder(); new (this) PropertyHolder(other); + assert(key.get_type().flags() == Flags::Int64 || this->int64_v != 0); return *this; } @@ -140,6 +143,7 @@ public: { this->~PropertyHolder(); new (this) PropertyHolder(std::move(other)); + assert(key.get_type().flags() == Flags::Int64 || this->int64_v != 0); return *this; } diff --git a/include/storage/model/properties/string.hpp b/include/storage/model/properties/string.hpp index fce1d127c..9772b71cc 100644 --- a/include/storage/model/properties/string.hpp +++ b/include/storage/model/properties/string.hpp @@ -26,7 +26,9 @@ public: bool operator==(const std::string &other) const; - operator const std::string &() const; + // NOTE: OTHER METHODS WILL AUTOMATICALLY USE THIS IN CERTAIN SITUATIONS + // TO MOVE STD::STRING OUT OF SHARED_PTR WHICH IS BAD. + // operator const std::string &() const; private: std::string data; diff --git a/include/storage/model/properties/traversers/jsonwriter.hpp b/include/storage/model/properties/traversers/jsonwriter.hpp index 21d990567..69e4273e5 100644 --- a/include/storage/model/properties/traversers/jsonwriter.hpp +++ b/include/storage/model/properties/traversers/jsonwriter.hpp @@ -36,7 +36,7 @@ public: void handle(const Bool &b) { buffer << (b ? "true" : "false"); } - void handle(const String &s) { buffer << '"' << s << '"'; } + void handle(const String &s) { buffer << '"' << s.value() << '"'; } void handle(const Int32 &int32) { buffer << std::to_string(int32.value()); } diff --git a/include/storage/vertices.hpp b/include/storage/vertices.hpp index 2e414a41a..5ca2a7289 100644 --- a/include/storage/vertices.hpp +++ b/include/storage/vertices.hpp @@ -39,10 +39,14 @@ public: prop_familys_t::Accessor property_family_access(); private: - vertices_t vertices; // TODO: Because families wont be removed this could be done with more // efficent // data structure. prop_familys_t prop_familys; + + // NOTE: this must be before prop_familys field to be destroyed before them. + // Because there are property_family references in vertices. + vertices_t vertices; + AtomicCounter<uint64_t> counter; }; diff --git a/src/storage/model/properties/string.cpp b/src/storage/model/properties/string.cpp index 117e6608b..d1c7c8373 100644 --- a/src/storage/model/properties/string.cpp +++ b/src/storage/model/properties/string.cpp @@ -2,8 +2,6 @@ const Type String::type = Type(Flags::String); -String::operator const std::string &() const { return value(); } - bool String::operator==(const String &other) const { return value() == other.value();