From 5d235b51f3160cae8e3f3234f4928272125cdc45 Mon Sep 17 00:00:00 2001 From: Kruno Tomola Fabro Date: Mon, 5 Sep 2016 10:02:48 +0100 Subject: [PATCH] tmp commit tmp commit tmp commit v2 Finished reimplementation of propertys. They now can be placed in a holder with different source of type information. Tmp commit --- CMakeLists.txt | 7 +- include/barrier/barrier.hpp | 33 +-- include/barrier/common.hpp | 2 + include/barrier/trans.hpp | 2 +- .../bolt/v1/serialization/bolt_serializer.hpp | 42 ++- .../bolt/v1/serialization/record_stream.hpp | 48 ++-- include/import/csv_import.hpp | 32 +-- include/import/element_skeleton.hpp | 50 +--- include/import/fillings/array.hpp | 2 +- include/import/fillings/bool.hpp | 2 +- include/import/fillings/double.hpp | 2 +- include/import/fillings/float.hpp | 2 +- include/import/fillings/id.hpp | 4 +- include/import/fillings/int32.hpp | 2 +- include/import/fillings/int64.hpp | 2 +- include/import/fillings/string.hpp | 2 +- include/query_engine/hardcode/queries.hpp | 128 ++++----- include/query_engine/query_stripped.hpp | 2 +- include/query_engine/query_stripper.hpp | 11 +- include/query_engine/traverser/code.hpp | 92 +++---- include/query_engine/util.hpp | 21 +- include/storage/model/properties/all.hpp | 1 + include/storage/model/properties/array.hpp | 100 +++---- include/storage/model/properties/bool.hpp | 35 ++- include/storage/model/properties/double.hpp | 13 +- include/storage/model/properties/flags.hpp | 23 +- include/storage/model/properties/float.hpp | 15 +- include/storage/model/properties/handler.hpp | 35 --- include/storage/model/properties/int32.hpp | 14 +- include/storage/model/properties/int64.hpp | 11 +- include/storage/model/properties/null.hpp | 30 +- include/storage/model/properties/number.hpp | 32 +-- .../storage/model/properties/properties.hpp | 60 ++-- include/storage/model/properties/property.hpp | 43 +-- .../model/properties/property_family.hpp | 21 +- .../model/properties/property_holder.hpp | 256 ++++++++++++++++++ .../model/properties/stored_property.hpp | 24 ++ include/storage/model/properties/string.hpp | 32 ++- .../properties/traversers/consolewriter.hpp | 53 ++-- .../properties/traversers/jsonwriter.hpp | 57 ++-- include/storage/record_accessor.hpp | 19 +- include/utils/exceptions/basic_exception.hpp | 26 +- include/utils/void.hpp | 3 + poc/astar.cpp | 12 +- poc/profile.hpp | 8 +- src/barrier/barrier.cpp | 91 +++++-- .../bolt/v1/serialization/bolt_serializer.cpp | 4 +- src/communication/bolt/v1/session.cpp | 28 +- src/database/db_transaction.cpp | 2 +- src/query_engine/util.cpp | 18 +- src/storage/model/properties/array.cpp | 68 +---- src/storage/model/properties/bool.cpp | 41 +-- src/storage/model/properties/double.cpp | 3 + src/storage/model/properties/float.cpp | 3 + src/storage/model/properties/int32.cpp | 3 + src/storage/model/properties/int64.cpp | 3 + src/storage/model/properties/null.cpp | 23 +- src/storage/model/properties/properties.cpp | 68 ++--- src/storage/model/properties/property.cpp | 13 - .../model/properties/stored_property.cpp | 11 + src/storage/model/properties/string.cpp | 29 +- tests/integration/cleaning.cpp | 3 +- tests/integration/queries.cpp | 3 +- tests/manual/queries.cpp | 4 +- tests/manual/query_hasher.cpp | 8 +- 65 files changed, 1002 insertions(+), 835 deletions(-) delete mode 100644 include/storage/model/properties/handler.hpp create mode 100644 include/storage/model/properties/property_holder.hpp create mode 100644 include/storage/model/properties/stored_property.hpp create mode 100644 src/storage/model/properties/double.cpp create mode 100644 src/storage/model/properties/float.cpp create mode 100644 src/storage/model/properties/int32.cpp create mode 100644 src/storage/model/properties/int64.cpp delete mode 100644 src/storage/model/properties/property.cpp create mode 100644 src/storage/model/properties/stored_property.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 588fb6817..ae990505b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -211,7 +211,6 @@ FILE(COPY ${include_dir}/storage/model/properties/properties.hpp DESTINATION ${b FILE(COPY ${include_dir}/storage/model/properties/property.hpp DESTINATION ${build_include_dir}/storage/model/properties) FILE(COPY ${include_dir}/storage/model/properties/traversers/consolewriter.hpp DESTINATION ${build_include_dir}/storage/model/properties/traversers) FILE(COPY ${include_dir}/storage/model/properties/traversers/jsonwriter.hpp DESTINATION ${build_include_dir}/storage/model/properties/traversers) -FILE(COPY ${include_dir}/storage/model/properties/handler.hpp DESTINATION ${build_include_dir}/storage/model/properties) FILE(COPY ${include_dir}/storage/model/properties/all.hpp DESTINATION ${build_include_dir}/storage/model/properties) FILE(COPY ${include_dir}/storage/model/properties/bool.hpp DESTINATION ${build_include_dir}/storage/model/properties) FILE(COPY ${include_dir}/storage/model/properties/float.hpp DESTINATION ${build_include_dir}/storage/model/properties) @@ -438,12 +437,16 @@ set(memgraph_src_files ${src_dir}/storage/label/label_store.cpp ${src_dir}/storage/edge_type/edge_type.cpp ${src_dir}/storage/edge_type/edge_type_store.cpp - ${src_dir}/storage/model/properties/property.cpp ${src_dir}/storage/model/properties/null.cpp ${src_dir}/storage/model/properties/bool.cpp + ${src_dir}/storage/model/properties/int32.cpp + ${src_dir}/storage/model/properties/int64.cpp + ${src_dir}/storage/model/properties/float.cpp + ${src_dir}/storage/model/properties/double.cpp ${src_dir}/storage/model/properties/string.cpp ${src_dir}/storage/model/properties/array.cpp ${src_dir}/storage/model/properties/properties.cpp + ${src_dir}/storage/model/properties/stored_property.cpp ${src_dir}/storage/model/properties/property_family.cpp ${src_dir}/storage/indexes/index_base.cpp ${src_dir}/storage/indexes/index_record.cpp diff --git a/include/barrier/barrier.hpp b/include/barrier/barrier.hpp index 74b645a67..b0bf0e8e9 100644 --- a/include/barrier/barrier.hpp +++ b/include/barrier/barrier.hpp @@ -147,17 +147,14 @@ public: void remove() const; - const Property &at(VertexPropertyFamily &key) const; + const StoredProperty &at(VertexPropertyFamily &key) const; - const Property &at(VertexPropertyKey &key) const; + const StoredProperty &at(VertexPropertyKey &key) const; template - OptionPtr at(VertexPropertyType &key) const; + OptionPtr at(VertexPropertyType &key) const; - template - void set(VertexPropertyType &key, Args &&... args); - - void set(VertexPropertyKey &key, Property::sptr value); + void set(VertexPropertyKey &key, Property &&value); void clear(VertexPropertyKey &key); @@ -206,17 +203,14 @@ public: void remove() const; - const Property &at(EdgePropertyFamily &key) const; + const StoredProperty &at(EdgePropertyFamily &key) const; - const Property &at(EdgePropertyKey &key) const; + const StoredProperty &at(EdgePropertyKey &key) const; template - OptionPtr at(EdgePropertyType &key) const; + OptionPtr at(EdgePropertyType &key) const; - template - void set(EdgePropertyType &key, Args &&... args); - - void set(EdgePropertyKey &key, Property::sptr value); + void set(EdgePropertyKey &key, Property &&value); void clear(EdgePropertyKey &key); @@ -474,15 +468,22 @@ public: void write(const VertexAccessor &vertex); void write(const EdgeAccessor &edge); - void write(const Property &prop); + void write(const StoredProperty &prop); + void write(const StoredProperty &prop); void write_null(); + void write(const Null &v); void write(const Bool &prop); void write(const Float &prop); void write(const Double &prop); void write(const Int32 &prop); void write(const Int64 &prop); - void write(const std::string &value); void write(const String &prop); + void write(const ArrayBool &); + void write(const ArrayInt32 &); + void write(const ArrayInt64 &); + void write(const ArrayFloat &); + void write(const ArrayDouble &); + void write(const ArrayString &); void write_success(); void write_success_empty(); diff --git a/include/barrier/common.hpp b/include/barrier/common.hpp index 1873988f7..366077364 100644 --- a/include/barrier/common.hpp +++ b/include/barrier/common.hpp @@ -9,6 +9,8 @@ // barrier.cpp #include "mvcc/id.hpp" #include "storage/model/properties/all.hpp" +#include "storage/model/properties/property.hpp" +#include "storage/model/properties/stored_property.hpp" #include "utils/border.hpp" #include "utils/iterator/iterator.hpp" #include "utils/option_ptr.hpp" diff --git a/include/barrier/trans.hpp b/include/barrier/trans.hpp index 0552138e5..0b57ff927 100644 --- a/include/barrier/trans.hpp +++ b/include/barrier/trans.hpp @@ -161,7 +161,7 @@ namespace barrier // TRANSFORM_REF(, ::); // template TRANSFORM_REF_TEMPLATED(,::); -// ***************** TRANSFORMS of reference +// ***************** TRANSFORMS of reference and pointers DUP(Label, TRANSFORM_REF); DUP(EdgeType, TRANSFORM_REF); DUP(VertexPropertyFamily, TRANSFORM_REF); diff --git a/include/communication/bolt/v1/serialization/bolt_serializer.hpp b/include/communication/bolt/v1/serialization/bolt_serializer.hpp index 6abab5245..884702462 100644 --- a/include/communication/bolt/v1/serialization/bolt_serializer.hpp +++ b/include/communication/bolt/v1/serialization/bolt_serializer.hpp @@ -6,10 +6,10 @@ #include "storage/edge_accessor.hpp" #include "storage/vertex_accessor.hpp" +#include "storage/edge_type/edge_type.hpp" +#include "storage/label/label.hpp" #include "storage/model/properties/all.hpp" #include "storage/model/properties/properties.hpp" -#include "storage/label/label.hpp" -#include "storage/edge_type/edge_type.hpp" #include "storage/vertex_record.hpp" namespace bolt @@ -59,8 +59,8 @@ public: encoder.write_map_header(props.size()); for (auto &prop : props) { - write(prop.first.family_name()); - write(*prop.second); + write(prop.key.family_name()); + prop.accept(*this); } } @@ -77,25 +77,41 @@ public: */ void write(const EdgeAccessor &edge); - void write(const Property &prop) { accept(prop, *this); } - void write_null() { encoder.write_null(); } + void write(const Null &v) { encoder.write_null(); } + void write(const Bool &prop) { encoder.write_bool(prop.value()); } - void write(const Float &prop) { encoder.write_double(prop.value); } + void write(const Float &prop) { encoder.write_double(prop.value()); } - void write(const Double &prop) { encoder.write_double(prop.value); } + void write(const Double &prop) { encoder.write_double(prop.value()); } - void write(const Int32 &prop) { encoder.write_integer(prop.value); } + void write(const Int32 &prop) { encoder.write_integer(prop.value()); } - void write(const Int64 &prop) { encoder.write_integer(prop.value); } + void write(const Int64 &prop) { encoder.write_integer(prop.value()); } - void write(const std::string &value) { encoder.write_string(value); } + void write(const String &value) { encoder.write_string(value.value()); } - void write(const String &prop) { encoder.write_string(prop.value); } + // Not yet implemented + void write(const ArrayBool &) { assert(false); } - void write_failure(const std::map& data) + // Not yet implemented + void write(const ArrayInt32 &) { assert(false); } + + // Not yet implemented + void write(const ArrayInt64 &) { assert(false); } + + // Not yet implemented + void write(const ArrayFloat &) { assert(false); } + + // Not yet implemented + void write(const ArrayDouble &) { assert(false); } + + // Not yet implemented + void write(const ArrayString &) { assert(false); } + + void write_failure(const std::map &data) { encoder.message_failure(); encoder.write_map_header(data.size()); diff --git a/include/communication/bolt/v1/serialization/record_stream.hpp b/include/communication/bolt/v1/serialization/record_stream.hpp index 45b23683f..a09eda0db 100644 --- a/include/communication/bolt/v1/serialization/record_stream.hpp +++ b/include/communication/bolt/v1/serialization/record_stream.hpp @@ -59,7 +59,7 @@ public: chunk(); } - void write_field(const std::string& field) + void write_field(const std::string &field) { bolt_encoder.message_success(); bolt_encoder.write_map_header(1); @@ -74,16 +74,13 @@ public: bolt_encoder.write_list_header(size); } - void write_record() - { - bolt_encoder.message_record(); - } + void write_record() { bolt_encoder.message_record(); } // writes metadata at the end of the message // TODO: write whole implementation (currently, only type is supported) // { "stats": { "nodes created": 1, "properties set": 1}, // "type": "r" | "rw" | ... - void write_meta(const std::string& type) + void write_meta(const std::string &type) { bolt_encoder.message_success(); bolt_encoder.write_map_header(1); @@ -92,33 +89,41 @@ public: chunk(); } - void write_failure(const std::map& data) + void write_failure(const std::map &data) { serializer.write_failure(data); - chunk(); + chunk(); } // -- BOLT SPECIFIC METHODS ----------------------------------------------- void write(const VertexAccessor &vertex) { serializer.write(vertex); } void write(const EdgeAccessor &edge) { serializer.write(edge); } - void write(const Property &prop) { serializer.write(prop); } - void write(const Bool& prop) { serializer.write(prop); } - void write(const Float& prop) { serializer.write(prop); } - void write(const Int32& prop) { serializer.write(prop); } - void write(const Int64& prop) { serializer.write(prop); } - void write(const Double& prop) { serializer.write(prop); } - void write(const String& prop) { serializer.write(prop); } - - void send() + void write(const StoredProperty &prop) { - chunked_buffer.flush(); + prop.accept(serializer); } - - void chunk() + void write(const StoredProperty &prop) { - chunked_encoder.write_chunk(); + prop.accept(serializer); } + void write(const Null &prop) { serializer.write(prop); } + void write(const Bool &prop) { serializer.write(prop); } + void write(const Float &prop) { serializer.write(prop); } + void write(const Int32 &prop) { serializer.write(prop); } + void write(const Int64 &prop) { serializer.write(prop); } + void write(const Double &prop) { serializer.write(prop); } + void write(const String &prop) { serializer.write(prop); } + void write(const ArrayBool &prop) { serializer.write(prop); } + void write(const ArrayInt32 &prop) { serializer.write(prop); } + void write(const ArrayInt64 &prop) { serializer.write(prop); } + void write(const ArrayFloat &prop) { serializer.write(prop); } + void write(const ArrayDouble &prop) { serializer.write(prop); } + void write(const ArrayString &prop) { serializer.write(prop); } + + void send() { chunked_buffer.flush(); } + + void chunk() { chunked_encoder.write_chunk(); } void _write_test() { @@ -152,6 +157,5 @@ private: chunked_encoder_t chunked_encoder{chunked_buffer}; bolt_encoder_t bolt_encoder{chunked_encoder}; bolt_serializer_t serializer{bolt_encoder}; - }; } diff --git a/include/import/csv_import.hpp b/include/import/csv_import.hpp index 00bffe32c..de14c8541 100644 --- a/include/import/csv_import.hpp +++ b/include/import/csv_import.hpp @@ -169,7 +169,7 @@ private: template typename PropertyFamily::PropertyType::PropertyFamilyKey - prop_key(const char *name, Flags type) + property_key(const char *name, Flags type) { assert(false); } @@ -209,7 +209,7 @@ private: std::unique_ptr f( name[0] == '\0' ? new IdFiller() : new IdFiller(make_option( - prop_key(name, Flags::Int64)))); + property_key(name, Flags::Int64)))); return make_option(std::move(f)); } else if (equal_str(type, "start_id") || equal_str(type, "from_id") || @@ -240,66 +240,66 @@ private: // return make_filler_property(vertex, name, // Flags::Bool); std::unique_ptr f( - new BoolFiller(prop_key(name, Flags::Bool))); + new BoolFiller(property_key(name, Flags::Bool))); return make_option(std::move(f)); } else if (equal_str(type, "double")) { std::unique_ptr f( - new DoubleFiller(prop_key(name, Flags::Double))); + new DoubleFiller(property_key(name, Flags::Double))); return make_option(std::move(f)); } else if (equal_str(type, "float")) { std::unique_ptr f( - new FloatFiller(prop_key(name, Flags::Float))); + new FloatFiller(property_key(name, Flags::Float))); return make_option(std::move(f)); } else if (equal_str(type, "int")) { std::unique_ptr f( - new Int32Filler(prop_key(name, Flags::Int32))); + new Int32Filler(property_key(name, Flags::Int32))); return make_option(std::move(f)); } else if (equal_str(type, "long")) { std::unique_ptr f( - new Int64Filler(prop_key(name, Flags::Int64))); + new Int64Filler(property_key(name, Flags::Int64))); return make_option(std::move(f)); } else if (equal_str(type, "string")) { std::unique_ptr f( - new StringFiller(prop_key(name, Flags::String))); + new StringFiller(property_key(name, Flags::String))); return make_option(std::move(f)); } else if (equal_str(type, "bool[]")) { std::unique_ptr f(make_array_filler( - *this, prop_key(name, Flags::ArrayBool), to_bool)); + *this, property_key(name, Flags::ArrayBool), to_bool)); return make_option(std::move(f)); } else if (equal_str(type, "float[]")) { std::unique_ptr f(make_array_filler( - *this, prop_key(name, Flags::ArrayFloat), to_float)); + *this, property_key(name, Flags::ArrayFloat), to_float)); return make_option(std::move(f)); } else if (equal_str(type, "double[]")) { std::unique_ptr f( make_array_filler( - *this, prop_key(name, Flags::ArrayDouble), to_double)); + *this, property_key(name, Flags::ArrayDouble), to_double)); return make_option(std::move(f)); } else if (equal_str(type, "int[]")) { std::unique_ptr f( make_array_filler( - *this, prop_key(name, Flags::ArrayInt32), to_int32)); + *this, property_key(name, Flags::ArrayInt32), to_int32)); return make_option(std::move(f)); } else if (equal_str(type, "long[]")) { std::unique_ptr f( make_array_filler( - *this, prop_key(name, Flags::ArrayInt64), to_int64)); + *this, property_key(name, Flags::ArrayInt64), to_int64)); return make_option(std::move(f)); } else if (equal_str(type, "string[]")) { std::unique_ptr f( make_array_filler( - *this, prop_key(name, Flags::ArrayString), to_string)); + *this, property_key(name, Flags::ArrayString), to_string)); return make_option(std::move(f)); } else { @@ -326,14 +326,14 @@ private: template <> PropertyFamily::PropertyType::PropertyFamilyKey -CSVImporter::prop_key(const char *name, Flags type) +CSVImporter::property_key(const char *name, Flags type) { return db.vertex_property_key(name, Type(type)); } template <> PropertyFamily::PropertyType::PropertyFamilyKey -CSVImporter::prop_key(const char *name, Flags type) +CSVImporter::property_key(const char *name, Flags type) { return db.edge_property_key(name, Type(type)); } diff --git a/include/import/element_skeleton.hpp b/include/import/element_skeleton.hpp index 52c005a62..b18f87f0e 100644 --- a/include/import/element_skeleton.hpp +++ b/include/import/element_skeleton.hpp @@ -10,43 +10,17 @@ class ElementSkeleton { - class Prop - { - - public: - Prop(VertexPropertyFamily::PropertyType::PropertyFamilyKey key, - Option> &&prop) - : key_v(key), prop(std::move(prop)) - { - } - - Prop(EdgePropertyFamily::PropertyType::PropertyFamilyKey key, - Option> &&prop) - : key_e(key), prop(std::move(prop)) - { - } - - union - { - VertexPropertyFamily::PropertyType::PropertyFamilyKey key_v; - EdgePropertyFamily::PropertyType::PropertyFamilyKey key_e; - }; - Option> prop; - }; - public: ElementSkeleton(DbAccessor &db) : db(db){}; - void add_property(VertexPropertyFamily::PropertyType::PropertyFamilyKey key, - std::shared_ptr &&prop) + void add_property(StoredProperty &&prop) { - properties.push_back(Prop(key, make_option(std::move(prop)))); + properties_v.push_back(std::move(prop)); } - void add_property(EdgePropertyFamily::PropertyType::PropertyFamilyKey key, - std::shared_ptr &&prop) + void add_property(StoredProperty &&prop) { - properties.push_back(Prop(key, make_option(std::move(prop)))); + properties_e.push_back(std::move(prop)); } void set_element_id(size_t id) @@ -77,9 +51,8 @@ public: va.add_label(*l); } - for (auto prop : properties) { - assert(prop.prop.is_present()); - va.set(prop.key_v, prop.prop.take()); + for (auto prop : properties_v) { + va.set(std::move(prop)); } return va; @@ -100,9 +73,8 @@ public: ve.edge_type(*type.get()); } - for (auto prop : properties) { - assert(prop.prop.is_present()); - ve.set(prop.key_e, prop.prop.take()); + for (auto prop : properties_e) { + ve.set(std::move(prop)); } return make_option(); @@ -115,7 +87,8 @@ public: from_va = make_option(); type = make_option(); labels.clear(); - properties.clear(); + properties_v.clear(); + properties_e.clear(); } // Returns import local id. @@ -138,5 +111,6 @@ private: Option from_va; Option type; std::vector