From 3595a9c3b5e816f3bc3b1e32f81f533ada9b67e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ante=20Pu=C5=A1i=C4=87?= Date: Tue, 9 Jan 2024 21:09:38 +0100 Subject: [PATCH] Move text index data CRUD to VertexAccessor --- src/storage/v2/property_store.cpp | 45 +++++++----------------------- src/storage/v2/property_store.hpp | 18 ++++-------- src/storage/v2/vertex_accessor.cpp | 42 +++++++++++++--------------- 3 files changed, 36 insertions(+), 69 deletions(-) diff --git a/src/storage/v2/property_store.cpp b/src/storage/v2/property_store.cpp index 8cf730a83..d22b3cc30 100644 --- a/src/storage/v2/property_store.cpp +++ b/src/storage/v2/property_store.cpp @@ -1134,25 +1134,7 @@ std::map PropertyStore::Properties() const { } /// NOTE: The external_store_mock argument will be removed after replacing the mock with the mgcxx Tantivy API -bool PropertyStore::SetProperty(PropertyId property, const PropertyValue &value, bool external, - std::optional gid) { - // if (external) { - // // TODO @antepusic: assignment pending delete() in the mgcxx API - - // int DUMMY_GRAPH_ELEMENT_ID = 1; - // nlohmann::json document; - // nlohmann::json property_map; - - // if (!value.IsNull()) { - // property_map[property.ToString()] = value.ValueInt(); - // } - - // document["id"] = DUMMY_GRAPH_ELEMENT_ID; - // document["properties"] = property_map; - // external_store_mock->AddDocument(DUMMY_GRAPH_ELEMENT_ID, document); - // return true; - // } - +bool PropertyStore::SetProperty(PropertyId property, const PropertyValue &value) { uint64_t property_size = 0; if (!value.IsNull()) { Writer writer; @@ -1276,11 +1258,7 @@ bool PropertyStore::SetProperty(PropertyId property, const PropertyValue &value, } template -bool PropertyStore::DoInitProperties(const TContainer &properties, bool external, std::optional gid) { - if (external) { - // mgcxx_mock::text_search::Mock::add() - } - +bool PropertyStore::DoInitProperties(const TContainer &properties) { uint64_t size = 0; uint8_t *data = nullptr; std::tie(size, data) = GetSizeData(buffer_); @@ -1339,7 +1317,7 @@ bool PropertyStore::DoInitProperties(const TContainer &properties, bool external } std::vector> PropertyStore::UpdateProperties( - std::map &properties, bool external, std::optional gid) { + std::map &properties) { auto old_properties = Properties(); ClearProperties(); @@ -1364,24 +1342,21 @@ std::vector> PropertyStore: } template bool PropertyStore::DoInitProperties>( - const std::map &, bool external = false, std::optional gid = std::nullopt); + const std::map &); template bool PropertyStore::DoInitProperties>>( - const std::vector> &, bool external = false, - std::optional gid = std::nullopt); + const std::vector> &); -bool PropertyStore::InitProperties(const std::map &properties, - bool external, std::optional gid) { - return DoInitProperties(properties, external, gid); +bool PropertyStore::InitProperties(const std::map &properties) { + return DoInitProperties(properties); } -bool PropertyStore::InitProperties(std::vector> properties, - bool external, std::optional gid) { +bool PropertyStore::InitProperties(std::vector> properties) { std::sort(properties.begin(), properties.end()); - return DoInitProperties(properties, external, gid); + return DoInitProperties(properties); } -bool PropertyStore::ClearProperties(bool external, std::optional gid) { +bool PropertyStore::ClearProperties() { bool in_local_buffer = false; uint64_t size; uint8_t *data; diff --git a/src/storage/v2/property_store.hpp b/src/storage/v2/property_store.hpp index 85a122f7c..810240ce7 100644 --- a/src/storage/v2/property_store.hpp +++ b/src/storage/v2/property_store.hpp @@ -78,24 +78,19 @@ class PropertyStore { /// returned if assignment took place. The time complexity of this function is /// O(n). /// @throw std::bad_alloc - bool SetProperty(PropertyId property, const PropertyValue &value, bool external = false, - std::optional gid = std::nullopt); - // , const bool external = false, - // SearchableExternalStoreMock *external_store_mock = nullptr); + bool SetProperty(PropertyId property, const PropertyValue &value); /// Init property values and return `true` if insertion took place. `false` is /// returned if there is any existing property in property store and insertion couldn't take place. The time /// complexity of this function is O(n). /// @throw std::bad_alloc - bool InitProperties(const std::map &properties, bool external = false, - std::optional gid = std::nullopt); + bool InitProperties(const std::map &properties); /// Init property values and return `true` if insertion took place. `false` is /// returned if there is any existing property in property store and insertion couldn't take place. The time /// complexity of this function is O(n*log(n)): /// @throw std::bad_alloc - bool InitProperties(std::vector> properties, - bool external = false, std::optional gid = std::nullopt); + bool InitProperties(std::vector> properties); /// Update property values in property store with sent properties. Returns vector of changed /// properties. Each tuple inside vector consists of PropertyId of inserted property, together with old @@ -103,14 +98,13 @@ class PropertyStore { /// The time complexity of this function is O(n*log(n)): /// @throw std::bad_alloc std::vector> UpdateProperties( - std::map &properties, bool external = false, - std::optional gid = std::nullopt); + std::map &properties); /// Remove all properties and return `true` if any removal took place. /// `false` is returned if there were no properties to remove. The time /// complexity of this function is O(1). /// @throw std::bad_alloc - bool ClearProperties(bool external = false, std::optional gid = std::nullopt); + bool ClearProperties(); /// Return property buffer as a string std::string StringBuffer() const; @@ -120,7 +114,7 @@ class PropertyStore { private: template - bool DoInitProperties(const TContainer &properties, bool external = false, std::optional gid = std::nullopt); + bool DoInitProperties(const TContainer &properties); uint8_t buffer_[sizeof(uint64_t) + sizeof(uint8_t *)]; }; diff --git a/src/storage/v2/vertex_accessor.cpp b/src/storage/v2/vertex_accessor.cpp index afc785c8e..02eea0ed8 100644 --- a/src/storage/v2/vertex_accessor.cpp +++ b/src/storage/v2/vertex_accessor.cpp @@ -274,31 +274,29 @@ Result VertexAccessor::SetProperty(PropertyId property, const Pro utils::AtomicMemoryBlock atomic_memory_block{ [transaction = transaction_, storage = storage_, vertex = vertex_, &value, &property, ¤t_value]() { CreateAndLinkDelta(transaction, vertex, Delta::SetPropertyTag(), property, current_value); - // // Option 1 (current) - // if (std::ranges::any_of(vertex->labels, - // [storage](auto &label) { return storage->indices_.text_index_->IndexExists(label); - // })) { - // vertex->properties.SetProperty(property, value, true, vertex->gid); - // } else { - // vertex->properties.SetProperty(property, value); - // } + if (flags::run_time::GetTextSearchEnabled()) { + // if (!storage->indices_.text_index_->IndexExists(storage->NameToLabel(name))) continue; + // TODO antepusic: check which text indices apply + // for (const auto index : GetApplicableTextIndices(vertex)) { + // + // } + for (auto label : vertex->labels) { + auto &context = storage->indices_.text_index_->index_.at("myIndex"); - // // Option 2 (proposed) - // if (flags::run_time::GetTextSearchEnabled()) { - // for (auto label : vertex->labels) { - // if (!storage->indices_.text_index_->IndexExists(label)) continue; + // Calling the text search tool is done here and not inside a PropertyStore method + // make SearchInput - // auto &context = storage->indices_.text_index_->index_.at(label); + auto search_input = mgcxx_mock::text_search::SearchInput{}; - // // Calling the text search tool is done here and not inside a PropertyStore method - // // make SearchInput - // auto search_result = mgcxx_mock::text_search::Mock::search(context, search_this_node_document); - // mgcxx_mock::text_search::Mock::delete_document(context, search_this_node_document); - // // parse result to JSON, set property in JSON and convert to string - // mgcxx_mock::text_search::Mock::add(context, DocumentInput{result_with_property_set.asString()}); - // } - // } - // vertex->properties.SetProperty(property, value); + auto search_result = mgcxx_mock::text_search::Mock::search(context, search_input); + mgcxx_mock::text_search::Mock::delete_document(context, search_input, true); + // parse result to JSON, set property in JSON and convert to string + auto new_properties = search_result.docs[0].data; + auto new_properties_document = mgcxx_mock::text_search::DocumentInput{.data = new_properties}; + mgcxx_mock::text_search::Mock::add(context, new_properties_document, true); + } + } + vertex->properties.SetProperty(property, value); }}; std::invoke(atomic_memory_block);