Remove mock from PropertyStore

This commit is contained in:
Ante Pušić 2024-01-05 00:19:40 +01:00
parent 3737fac8f8
commit 6c2b448fe9
2 changed files with 27 additions and 118 deletions

View File

@ -1022,19 +1022,18 @@ PropertyStore::~PropertyStore() {
} }
} }
PropertyValue PropertyStore::GetProperty(PropertyId property, const bool external, PropertyValue PropertyStore::GetProperty(PropertyId property) const {
ExternalStoreMockOld *external_store_mock) const { // if (external) {
if (external) { // int DUMMY_GRAPH_ELEMENT_ID = 1;
int DUMMY_GRAPH_ELEMENT_ID = 1;
auto key = property.ToString(); // auto key = property.ToString();
auto properties = external_store_mock->GetDocument(DUMMY_GRAPH_ELEMENT_ID)["properties"]; // auto properties = external_store_mock->GetDocument(DUMMY_GRAPH_ELEMENT_ID)["properties"];
if (!properties.contains(key)) { // if (!properties.contains(key)) {
return PropertyValue(); // return PropertyValue();
} // }
return PropertyValue(properties.at(key).get<int64_t>()); // return PropertyValue(properties.at(key).get<int64_t>());
} // }
uint64_t size; uint64_t size;
const uint8_t *data; const uint8_t *data;
@ -1134,24 +1133,23 @@ std::map<PropertyId, PropertyValue> PropertyStore::Properties() const {
} }
/// NOTE: The external_store_mock argument will be removed after replacing the mock with the mgcxx Tantivy API /// 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) {
SearchableExternalStoreMock *external_store_mock) { // if (external) {
if (external) { // // TODO @antepusic: assignment pending delete() in the mgcxx API
// 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;
if (!value.IsNull()) { // if (!value.IsNull()) {
property_map[property.ToString()] = value.ValueInt(); // property_map[property.ToString()] = value.ValueInt();
} // }
document["id"] = DUMMY_GRAPH_ELEMENT_ID; // document["id"] = DUMMY_GRAPH_ELEMENT_ID;
document["properties"] = property_map; // document["properties"] = property_map;
external_store_mock->AddDocument(DUMMY_GRAPH_ELEMENT_ID, document); // external_store_mock->AddDocument(DUMMY_GRAPH_ELEMENT_ID, document);
return true; // return true;
} // }
uint64_t property_size = 0; uint64_t property_size = 0;
if (!value.IsNull()) { if (!value.IsNull()) {

View File

@ -20,93 +20,6 @@
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 {
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<std::string, std::map<std::uint64_t, nlohmann::json>> 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<PropertyId> 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 { class PropertyStore {
static_assert(std::endian::native == std::endian::little, static_assert(std::endian::native == std::endian::little,
"PropertyStore supports only architectures using little-endian."); "PropertyStore supports only architectures using little-endian.");
@ -166,11 +79,9 @@ class PropertyStore {
/// 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 /// 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);
SearchableExternalStoreMock *external_store_mock = nullptr); // , const bool external = false,
// 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