Redo mock and PropertyStore
This commit is contained in:
parent
0baff463b1
commit
d4059a89aa
@ -1,4 +1,4 @@
|
|||||||
// Copyright 2023 Memgraph Ltd.
|
// Copyright 2024 Memgraph Ltd.
|
||||||
//
|
//
|
||||||
// Use of this software is governed by the Business Source License
|
// 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
|
// 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,
|
PropertyValue PropertyStore::GetProperty(PropertyId property, const bool external,
|
||||||
ExternalStoreMock *external_store_mock) const {
|
ExternalStoreMockOld *external_store_mock) const {
|
||||||
if (external) {
|
if (external) {
|
||||||
int DUMMY_GRAPH_ELEMENT_ID = 1;
|
int DUMMY_GRAPH_ELEMENT_ID = 1;
|
||||||
|
|
||||||
@ -1050,15 +1050,7 @@ PropertyValue PropertyStore::GetProperty(PropertyId property, const bool externa
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PropertyStore::HasProperty(PropertyId property, const bool external,
|
bool PropertyStore::HasProperty(PropertyId property) const {
|
||||||
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());
|
|
||||||
}
|
|
||||||
|
|
||||||
uint64_t size;
|
uint64_t size;
|
||||||
const uint8_t *data;
|
const uint8_t *data;
|
||||||
std::tie(size, data) = GetSizeData(buffer_);
|
std::tie(size, data) = GetSizeData(buffer_);
|
||||||
@ -1141,9 +1133,12 @@ std::map<PropertyId, PropertyValue> PropertyStore::Properties() const {
|
|||||||
return props;
|
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,
|
bool PropertyStore::SetProperty(PropertyId property, const PropertyValue &value, const bool external,
|
||||||
ExternalStoreMock *external_store_mock) {
|
SearchableExternalStoreMock *external_store_mock) {
|
||||||
if (external) {
|
if (external) {
|
||||||
|
// TODO @antepusic: assignment pending delete() in the mgcxx API
|
||||||
|
|
||||||
int DUMMY_GRAPH_ELEMENT_ID = 1;
|
int DUMMY_GRAPH_ELEMENT_ID = 1;
|
||||||
nlohmann::json document;
|
nlohmann::json document;
|
||||||
nlohmann::json property_map;
|
nlohmann::json property_map;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Copyright 2023 Memgraph Ltd.
|
// Copyright 2024 Memgraph Ltd.
|
||||||
//
|
//
|
||||||
// Use of this software is governed by the Business Source License
|
// 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
|
// 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 {
|
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 {
|
struct SearchResult {
|
||||||
std::uint64_t id;
|
std::uint64_t id;
|
||||||
nlohmann::json document;
|
nlohmann::json document;
|
||||||
double score;
|
double score;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ExternalStoreMock {
|
// TODO @antepusic: remove (superseded by SearchableExternalStoreMock)
|
||||||
|
class ExternalStoreMockOld {
|
||||||
private:
|
private:
|
||||||
std::string INDEX = ""; // placeholder (Tantivy supports multiple indices)
|
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}
|
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
|
/// property doesn't exist a Null value is returned. The time complexity of
|
||||||
/// this function is O(n).
|
/// this function is O(n).
|
||||||
/// @throw std::bad_alloc
|
/// @throw std::bad_alloc
|
||||||
PropertyValue GetProperty(PropertyId property, const bool external = false,
|
PropertyValue GetProperty(PropertyId property) const;
|
||||||
ExternalStoreMock *external_store_mock = nullptr) const;
|
|
||||||
|
|
||||||
/// Checks whether the property `property` exists in the store. The time
|
/// Checks whether the property `property` exists in the store. The time
|
||||||
/// complexity of this function is O(n).
|
/// complexity of this function is O(n).
|
||||||
bool HasProperty(PropertyId property, const bool external = false,
|
bool HasProperty(PropertyId property) const;
|
||||||
ExternalStoreMock *external_store_mock = nullptr) const;
|
|
||||||
|
|
||||||
/// Checks whether all properties in the set `properties` exist in the store. The time
|
/// Checks whether all properties in the set `properties` exist in the store. The time
|
||||||
/// complexity of this function is O(n^2).
|
/// 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
|
/// returned if assignment took place. The time complexity of this function is
|
||||||
/// O(n).
|
/// O(n).
|
||||||
/// @throw std::bad_alloc
|
/// @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,
|
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
|
/// 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
|
/// returned if there is any existing property in property store and insertion couldn't take place. The time
|
||||||
|
Loading…
Reference in New Issue
Block a user