From 6c2b448fe955009b3dae1fcb30b463f3b7a575b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ante=20Pu=C5=A1i=C4=87?= Date: Fri, 5 Jan 2024 00:19:40 +0100 Subject: [PATCH] Remove mock from PropertyStore --- src/storage/v2/property_store.cpp | 50 ++++++++-------- src/storage/v2/property_store.hpp | 95 +------------------------------ 2 files changed, 27 insertions(+), 118 deletions(-) diff --git a/src/storage/v2/property_store.cpp b/src/storage/v2/property_store.cpp index 736f1988d..26cc74dc2 100644 --- a/src/storage/v2/property_store.cpp +++ b/src/storage/v2/property_store.cpp @@ -1022,19 +1022,18 @@ PropertyStore::~PropertyStore() { } } -PropertyValue PropertyStore::GetProperty(PropertyId property, const bool external, - ExternalStoreMockOld *external_store_mock) const { - if (external) { - int DUMMY_GRAPH_ELEMENT_ID = 1; +PropertyValue PropertyStore::GetProperty(PropertyId property) const { + // if (external) { + // int DUMMY_GRAPH_ELEMENT_ID = 1; - auto key = property.ToString(); - auto properties = external_store_mock->GetDocument(DUMMY_GRAPH_ELEMENT_ID)["properties"]; - if (!properties.contains(key)) { - return PropertyValue(); - } + // auto key = property.ToString(); + // auto properties = external_store_mock->GetDocument(DUMMY_GRAPH_ELEMENT_ID)["properties"]; + // if (!properties.contains(key)) { + // return PropertyValue(); + // } - return PropertyValue(properties.at(key).get()); - } + // return PropertyValue(properties.at(key).get()); + // } uint64_t size; const uint8_t *data; @@ -1134,24 +1133,23 @@ 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, const bool external, - SearchableExternalStoreMock *external_store_mock) { - if (external) { - // TODO @antepusic: assignment pending delete() in the mgcxx API +bool PropertyStore::SetProperty(PropertyId property, const PropertyValue &value) { + // if (external) { + // // TODO @antepusic: assignment pending delete() in the mgcxx API - int DUMMY_GRAPH_ELEMENT_ID = 1; - nlohmann::json document; - nlohmann::json property_map; + // int DUMMY_GRAPH_ELEMENT_ID = 1; + // nlohmann::json document; + // nlohmann::json property_map; - if (!value.IsNull()) { - property_map[property.ToString()] = value.ValueInt(); - } + // 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; - } + // document["id"] = DUMMY_GRAPH_ELEMENT_ID; + // document["properties"] = property_map; + // external_store_mock->AddDocument(DUMMY_GRAPH_ELEMENT_ID, document); + // return true; + // } uint64_t property_size = 0; if (!value.IsNull()) { diff --git a/src/storage/v2/property_store.hpp b/src/storage/v2/property_store.hpp index 5ab2530e4..ba6f9423b 100644 --- a/src/storage/v2/property_store.hpp +++ b/src/storage/v2/property_store.hpp @@ -20,93 +20,6 @@ namespace memgraph::storage { -struct Context { - std::string tantivyContext; // the actual type of tantivyContext is outside the mgcxx API -}; - -struct IndexConfig { - std::string mappings; -}; - -struct DocumentInput { - std::string data; -}; - -struct DocumentOutput { - std::string data; -}; - -struct SearchInput { - std::vector search_fields; - std::string search_query; - std::vector return_fields; - std::string aggregation_query; -}; - -struct SearchOutput { - std::vector docs; -}; - -class SearchableExternalStoreMock { - public: - void init(std::string _log_level) {} - - Context create_index(std::string path, IndexConfig config) { return Context(); } - - void add(Context context, DocumentInput input, bool skip_commit) {} - - void commit(Context context) {} - - void rollback(Context context) {} - - SearchOutput search(Context context, SearchInput input) { return SearchOutput(); } - - DocumentOutput aggregate(Context context, SearchInput input) { return DocumentOutput(); } - - void drop_index(std::string path) {} -}; - -// TODO @antepusic: remove (superseded by SearchOutput) -struct SearchResult { - std::uint64_t id; - nlohmann::json document; - double score; -}; - -// TODO @antepusic: remove (superseded by SearchableExternalStoreMock) -class ExternalStoreMockOld { - private: - std::string INDEX = ""; // placeholder (Tantivy supports multiple indices) - std::map> storage{}; // index_name: {document_id: document} - - public: - enum class Consistency : uint8_t { DEFAULT }; - - void CreateAllPropsIndex(std::string index_name, LabelId label, std::string tokenizer = "DUMMY_TOKENIZER", - Consistency consistency = Consistency::DEFAULT); - - void CreateIndex(std::string index_name, LabelId label, std::vector properties, - std::string tokenizer = "DUMMY_TOKENIZER", Consistency consistency = Consistency::DEFAULT); - - void DropIndex(std::string index_name) { storage.erase(index_name); } - - /// @brief Add document with given ID - /// @param id Id of graph element - /// @param document Document storing the properties - void AddDocument(std::uint64_t id, nlohmann::json document) { storage[INDEX][id] = document; } - - nlohmann::json GetDocument(std::uint64_t id) { return storage[INDEX][id]; } - - void DeleteDocument(std::uint64_t id) { storage[INDEX].erase(id); } - - // storage::IndicesInfo ListAllTextIndices(); TODO make IndicesInfo visible here - - SearchResult Search(std::string index_name, std::string search_query) { - auto mock_result = storage[index_name].begin(); - return SearchResult{.id = mock_result->first, .document = mock_result->second, .score = 1.0}; - } -}; - class PropertyStore { static_assert(std::endian::native == std::endian::little, "PropertyStore supports only architectures using little-endian."); @@ -166,11 +79,9 @@ class PropertyStore { /// O(n). /// @throw std::bad_alloc /// NOTE: The external_store_mock argument will be removed after replacing the mock with the mgcxx Tantivy API - bool SetProperty(PropertyId property, const PropertyValue &value, const bool external = false, - SearchableExternalStoreMock *external_store_mock = nullptr); - - bool SetProperty(PropertyId property, const PropertyValue &value, nlohmann::json metadata, - SearchableExternalStoreMock *external_store_mock = nullptr); + bool SetProperty(PropertyId property, const PropertyValue &value); + // , const bool external = false, + // SearchableExternalStoreMock *external_store_mock = nullptr); /// 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