Move text index data CRUD to VertexAccessor

This commit is contained in:
Ante Pušić 2024-01-09 21:09:38 +01:00
parent 5fb9324239
commit 3595a9c3b5
3 changed files with 36 additions and 69 deletions

View File

@ -1134,25 +1134,7 @@ 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
bool PropertyStore::SetProperty(PropertyId property, const PropertyValue &value, bool external,
std::optional<Gid> 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 <typename TContainer>
bool PropertyStore::DoInitProperties(const TContainer &properties, bool external, std::optional<Gid> 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<std::tuple<PropertyId, PropertyValue, PropertyValue>> PropertyStore::UpdateProperties(
std::map<PropertyId, PropertyValue> &properties, bool external, std::optional<Gid> gid) {
std::map<PropertyId, PropertyValue> &properties) {
auto old_properties = Properties();
ClearProperties();
@ -1364,24 +1342,21 @@ std::vector<std::tuple<PropertyId, PropertyValue, PropertyValue>> PropertyStore:
}
template bool PropertyStore::DoInitProperties<std::map<PropertyId, PropertyValue>>(
const std::map<PropertyId, PropertyValue> &, bool external = false, std::optional<Gid> gid = std::nullopt);
const std::map<PropertyId, PropertyValue> &);
template bool PropertyStore::DoInitProperties<std::vector<std::pair<PropertyId, PropertyValue>>>(
const std::vector<std::pair<PropertyId, PropertyValue>> &, bool external = false,
std::optional<Gid> gid = std::nullopt);
const std::vector<std::pair<PropertyId, PropertyValue>> &);
bool PropertyStore::InitProperties(const std::map<storage::PropertyId, storage::PropertyValue> &properties,
bool external, std::optional<Gid> gid) {
return DoInitProperties(properties, external, gid);
bool PropertyStore::InitProperties(const std::map<storage::PropertyId, storage::PropertyValue> &properties) {
return DoInitProperties(properties);
}
bool PropertyStore::InitProperties(std::vector<std::pair<storage::PropertyId, storage::PropertyValue>> properties,
bool external, std::optional<Gid> gid) {
bool PropertyStore::InitProperties(std::vector<std::pair<storage::PropertyId, storage::PropertyValue>> properties) {
std::sort(properties.begin(), properties.end());
return DoInitProperties(properties, external, gid);
return DoInitProperties(properties);
}
bool PropertyStore::ClearProperties(bool external, std::optional<Gid> gid) {
bool PropertyStore::ClearProperties() {
bool in_local_buffer = false;
uint64_t size;
uint8_t *data;

View File

@ -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> 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<storage::PropertyId, storage::PropertyValue> &properties, bool external = false,
std::optional<Gid> gid = std::nullopt);
bool InitProperties(const std::map<storage::PropertyId, storage::PropertyValue> &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<std::pair<storage::PropertyId, storage::PropertyValue>> properties,
bool external = false, std::optional<Gid> gid = std::nullopt);
bool InitProperties(std::vector<std::pair<storage::PropertyId, storage::PropertyValue>> 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<std::tuple<PropertyId, PropertyValue, PropertyValue>> UpdateProperties(
std::map<storage::PropertyId, storage::PropertyValue> &properties, bool external = false,
std::optional<Gid> gid = std::nullopt);
std::map<storage::PropertyId, storage::PropertyValue> &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> gid = std::nullopt);
bool ClearProperties();
/// Return property buffer as a string
std::string StringBuffer() const;
@ -120,7 +114,7 @@ class PropertyStore {
private:
template <typename TContainer>
bool DoInitProperties(const TContainer &properties, bool external = false, std::optional<Gid> gid = std::nullopt);
bool DoInitProperties(const TContainer &properties);
uint8_t buffer_[sizeof(uint64_t) + sizeof(uint8_t *)];
};

View File

@ -274,31 +274,29 @@ Result<PropertyValue> VertexAccessor::SetProperty(PropertyId property, const Pro
utils::AtomicMemoryBlock atomic_memory_block{
[transaction = transaction_, storage = storage_, vertex = vertex_, &value, &property, &current_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);