Redo mock and PropertyStore

This commit is contained in:
Ante Pušić 2024-01-04 10:32:08 +01:00
parent 0baff463b1
commit d4059a89aa
2 changed files with 64 additions and 19 deletions

View File

@ -1,4 +1,4 @@
// Copyright 2023 Memgraph Ltd.
// Copyright 2024 Memgraph Ltd.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
@ -1023,7 +1023,7 @@ PropertyStore::~PropertyStore() {
}
PropertyValue PropertyStore::GetProperty(PropertyId property, const bool external,
ExternalStoreMock *external_store_mock) const {
ExternalStoreMockOld *external_store_mock) const {
if (external) {
int DUMMY_GRAPH_ELEMENT_ID = 1;
@ -1050,15 +1050,7 @@ PropertyValue PropertyStore::GetProperty(PropertyId property, const bool externa
return value;
}
bool PropertyStore::HasProperty(PropertyId property, const bool external,
ExternalStoreMock *external_store_mock) const {
if (external) {
int DUMMY_GRAPH_ELEMENT_ID = 1;
auto properties = external_store_mock->GetDocument(DUMMY_GRAPH_ELEMENT_ID)["properties"];
return properties.contains(property.ToString());
}
bool PropertyStore::HasProperty(PropertyId property) const {
uint64_t size;
const uint8_t *data;
std::tie(size, data) = GetSizeData(buffer_);
@ -1141,9 +1133,12 @@ std::map<PropertyId, PropertyValue> PropertyStore::Properties() const {
return props;
}
/// 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,
ExternalStoreMock *external_store_mock) {
SearchableExternalStoreMock *external_store_mock) {
if (external) {
// TODO @antepusic: assignment pending delete() in the mgcxx API
int DUMMY_GRAPH_ELEMENT_ID = 1;
nlohmann::json document;
nlohmann::json property_map;

View File

@ -1,4 +1,4 @@
// Copyright 2023 Memgraph Ltd.
// Copyright 2024 Memgraph Ltd.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
@ -20,13 +20,61 @@
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<std::string> search_fields;
std::string search_query;
std::vector<std::string> return_fields;
std::string aggregation_query;
};
struct SearchOutput {
std::vector<DocumentOutput> 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;
};
class ExternalStoreMock {
// TODO @antepusic: remove (superseded by SearchableExternalStoreMock)
class ExternalStoreMockOld {
private:
std::string INDEX = ""; // placeholder (Tantivy supports multiple indices)
std::map<std::string, std::map<std::uint64_t, nlohmann::json>> storage{}; // index_name: {document_id: document}
@ -83,13 +131,11 @@ class PropertyStore {
/// property doesn't exist a Null value is returned. The time complexity of
/// this function is O(n).
/// @throw std::bad_alloc
PropertyValue GetProperty(PropertyId property, const bool external = false,
ExternalStoreMock *external_store_mock = nullptr) const;
PropertyValue GetProperty(PropertyId property) const;
/// Checks whether the property `property` exists in the store. The time
/// complexity of this function is O(n).
bool HasProperty(PropertyId property, const bool external = false,
ExternalStoreMock *external_store_mock = nullptr) const;
bool HasProperty(PropertyId property) const;
/// Checks whether all properties in the set `properties` exist in the store. The time
/// complexity of this function is O(n^2).
@ -119,8 +165,12 @@ class PropertyStore {
/// returned if assignment took place. The time complexity of this function is
/// 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,
ExternalStoreMock *external_store_mock = nullptr);
SearchableExternalStoreMock *external_store_mock = nullptr);
bool SetProperty(PropertyId property, const PropertyValue &value, nlohmann::json metadata,
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