add SetBatchProperties functionality in storage::VertexAccessor
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// Copyright 2022 Memgraph Ltd.
|
||||
// Copyright 2023 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
|
||||
@@ -125,6 +125,11 @@ class VertexAccessor final {
|
||||
return impl_.SetProperty(key, value);
|
||||
}
|
||||
|
||||
storage::Result<std::vector<storage::PropertyValue>> SetProperties(
|
||||
std::map<storage::PropertyId, storage::PropertyValue> &properties) {
|
||||
return impl_.SetBatchProperties(properties);
|
||||
}
|
||||
|
||||
storage::Result<storage::PropertyValue> RemoveProperty(storage::PropertyId key) {
|
||||
return SetProperty(key, storage::PropertyValue());
|
||||
}
|
||||
|
||||
@@ -213,10 +213,14 @@ VertexAccessor &CreateLocalVertex(const NodeCreationInfo &node_info, Frame *fram
|
||||
// when we update PropertyValue with custom allocator.
|
||||
|
||||
// auto start = std::chrono::steady_clock::now();
|
||||
|
||||
std::map<storage::PropertyId, storage::PropertyValue> properties;
|
||||
if (const auto *node_info_properties = std::get_if<PropertiesMapList>(&node_info.properties)) {
|
||||
for (const auto &[key, value_expression] : *node_info_properties) {
|
||||
PropsSetChecked(&new_node, key, value_expression->Accept(evaluator));
|
||||
properties.emplace(key, value_expression->Accept(evaluator));
|
||||
// PropsSetChecked(&new_node, key, );
|
||||
}
|
||||
new_node.SetProperties(properties);
|
||||
} else {
|
||||
auto property_map = evaluator.Visit(*std::get<ParameterLookup *>(node_info.properties));
|
||||
for (const auto &[key, value] : property_map.ValueMap()) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2022 Memgraph Ltd.
|
||||
// Copyright 2023 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
|
||||
@@ -971,6 +971,8 @@ PropertyValue PropertyStore::GetProperty(PropertyId property) const {
|
||||
return value;
|
||||
}
|
||||
|
||||
PropertyValue PropertyStore::GetEmptyProperty() const { return PropertyValue(); }
|
||||
|
||||
bool PropertyStore::HasProperty(PropertyId property) const {
|
||||
uint64_t size;
|
||||
const uint8_t *data;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2022 Memgraph Ltd.
|
||||
// Copyright 2023 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
|
||||
@@ -42,6 +42,8 @@ class PropertyStore {
|
||||
/// complexity of this function is O(n).
|
||||
bool HasProperty(PropertyId property) const;
|
||||
|
||||
PropertyValue GetEmptyProperty() const;
|
||||
|
||||
/// Checks whether the property `property` is equal to the specified value
|
||||
/// `value`. This function doesn't perform any memory allocations while
|
||||
/// performing the equality check. The time complexity of this function is
|
||||
|
||||
@@ -245,6 +245,30 @@ Result<PropertyValue> VertexAccessor::SetProperty(PropertyId property, const Pro
|
||||
return std::move(current_value);
|
||||
}
|
||||
|
||||
Result<std::vector<storage::PropertyValue>> VertexAccessor::SetBatchProperties(
|
||||
std::map<storage::PropertyId, storage::PropertyValue> &properties) {
|
||||
// Be careful when calling this function
|
||||
// It will set properties in batch, without checking if property already exists
|
||||
|
||||
utils::MemoryTracker::OutOfMemoryExceptionEnabler oom_exception;
|
||||
std::lock_guard<utils::SpinLock> guard(vertex_->lock);
|
||||
|
||||
if (!PrepareForWrite(transaction_, vertex_)) return Error::SERIALIZATION_ERROR;
|
||||
|
||||
if (vertex_->deleted) return Error::DELETED_OBJECT;
|
||||
|
||||
std::vector<storage::PropertyValue> new_values;
|
||||
for (const auto &[property, value] : properties) {
|
||||
auto current_value = vertex_->properties.GetEmptyProperty();
|
||||
CreateAndLinkDelta(transaction_, vertex_, Delta::SetPropertyTag(), property, current_value);
|
||||
vertex_->properties.SetProperty(property, value);
|
||||
UpdateOnSetProperty(indices_, property, value, vertex_, *transaction_);
|
||||
new_values.emplace_back(current_value);
|
||||
}
|
||||
|
||||
return new_values;
|
||||
}
|
||||
|
||||
Result<std::map<PropertyId, PropertyValue>> VertexAccessor::ClearProperties() {
|
||||
std::lock_guard<utils::SpinLock> guard(vertex_->lock);
|
||||
|
||||
|
||||
@@ -68,6 +68,9 @@ class VertexAccessor final {
|
||||
/// @throw std::bad_alloc
|
||||
Result<PropertyValue> SetProperty(PropertyId property, const PropertyValue &value);
|
||||
|
||||
Result<std::vector<storage::PropertyValue>> SetBatchProperties(
|
||||
std::map<storage::PropertyId, storage::PropertyValue> &properties);
|
||||
|
||||
/// Remove all properties and return the values of the removed properties.
|
||||
/// @throw std::bad_alloc
|
||||
Result<std::map<PropertyId, PropertyValue>> ClearProperties();
|
||||
|
||||
Reference in New Issue
Block a user