diff options
author | Geir Storli <geirst@verizonmedia.com> | 2019-02-11 12:07:06 +0000 |
---|---|---|
committer | Geir Storli <geirst@verizonmedia.com> | 2019-02-11 12:07:06 +0000 |
commit | c7ef85ec98129d9b09750e64c0cd3b02f177dbe2 (patch) | |
tree | 68528d2453cacb31972bd1c51e4e0af0d2e6a247 /searchcore | |
parent | 5e20aa7c2d7c080b47d245c7544324c0a96bd35a (diff) |
Handle TensorAddUpdate in attribute updater.
Diffstat (limited to 'searchcore')
-rw-r--r-- | searchcore/src/tests/proton/common/attribute_updater/attribute_updater_test.cpp | 34 | ||||
-rw-r--r-- | searchcore/src/vespa/searchcore/proton/common/attribute_updater.cpp | 10 |
2 files changed, 32 insertions, 12 deletions
diff --git a/searchcore/src/tests/proton/common/attribute_updater/attribute_updater_test.cpp b/searchcore/src/tests/proton/common/attribute_updater/attribute_updater_test.cpp index 1620daa67c2..ba9b4292153 100644 --- a/searchcore/src/tests/proton/common/attribute_updater/attribute_updater_test.cpp +++ b/searchcore/src/tests/proton/common/attribute_updater/attribute_updater_test.cpp @@ -17,6 +17,7 @@ #include <vespa/document/update/documentupdate.h> #include <vespa/document/update/mapvalueupdate.h> #include <vespa/document/update/removevalueupdate.h> +#include <vespa/document/update/tensoraddupdate.h> #include <vespa/document/update/tensormodifyupdate.h> #include <vespa/eval/tensor/default_tensor_engine.h> #include <vespa/eval/tensor/tensor.h> @@ -25,6 +26,7 @@ #include <vespa/searchlib/attribute/attributevector.hpp> #include <vespa/searchlib/attribute/reference_attribute.h> #include <vespa/searchlib/tensor/dense_tensor_attribute.h> +#include <vespa/searchlib/tensor/generic_tensor_attribute.h> #include <vespa/vespalib/testkit/testapp.h> #include <vespa/log/log.h> @@ -42,6 +44,8 @@ using search::attribute::Reference; using search::attribute::ReferenceAttribute; using search::tensor::ITensorAttribute; using search::tensor::DenseTensorAttribute; +using search::tensor::GenericTensorAttribute; +using search::tensor::TensorAttribute; using vespalib::eval::ValueType; using vespalib::eval::TensorSpec; using vespalib::tensor::DefaultTensorEngine; @@ -373,12 +377,13 @@ TEST_F("require that weighted set attributes are updated", Fixture) } } -std::unique_ptr<DenseTensorAttribute> -makeDenseTensorAttribute(const vespalib::string &name, const vespalib::string &tensorType) +template <typename TensorAttributeType> +std::unique_ptr<TensorAttributeType> +makeTensorAttribute(const vespalib::string &name, const vespalib::string &tensorType) { Config cfg(BasicType::TENSOR, CollectionType::SINGLE); cfg.setTensorType(ValueType::from_spec(tensorType)); - auto result = std::make_unique<DenseTensorAttribute>(name, cfg); + auto result = std::make_unique<TensorAttributeType>(name, cfg); result->addReservedDoc(); result->addDocs(1); return result; @@ -400,7 +405,7 @@ makeTensorFieldValue(const TensorSpec &spec) } void -setTensor(DenseTensorAttribute &attribute, uint32_t lid, const TensorSpec &spec) +setTensor(TensorAttribute &attribute, uint32_t lid, const TensorSpec &spec) { auto tensor = makeTensor(spec); attribute.setTensor(lid, *tensor); @@ -410,13 +415,24 @@ setTensor(DenseTensorAttribute &attribute, uint32_t lid, const TensorSpec &spec) TEST_F("require that tensor modify update is applied", Fixture) { vespalib::string type = "tensor(x[2])"; - auto attribute = makeDenseTensorAttribute("dense_tensor", type); + auto attribute = makeTensorAttribute<DenseTensorAttribute>("dense_tensor", type); setTensor(*attribute, 1, TensorSpec(type).add({{"x", 0}}, 3).add({{"x", 1}}, 5)); - TensorModifyUpdate update(TensorModifyUpdate::Operation::REPLACE, - makeTensorFieldValue(TensorSpec("tensor(x{})").add({{"x",0}}, 7))); - f.applyValueUpdate(*attribute, 1, update); - EXPECT_EQUAL(TensorSpec(type).add({{"x",0}}, 7).add({{"x", 1}}, 5), attribute->getTensor(1)->toSpec()); + f.applyValueUpdate(*attribute, 1, + TensorModifyUpdate(TensorModifyUpdate::Operation::REPLACE, + makeTensorFieldValue(TensorSpec("tensor(x{})").add({{"x", 0}}, 7)))); + EXPECT_EQUAL(TensorSpec(type).add({{"x", 0}}, 7).add({{"x", 1}}, 5), attribute->getTensor(1)->toSpec()); +} + +TEST_F("require that tensor add update is applied", Fixture) +{ + vespalib::string type = "tensor(x{})"; + auto attribute = makeTensorAttribute<GenericTensorAttribute>("dense_tensor", type); + setTensor(*attribute, 1, TensorSpec(type).add({{"x", "a"}}, 2)); + + f.applyValueUpdate(*attribute, 1, + TensorAddUpdate(makeTensorFieldValue(TensorSpec(type).add({{"x", "a"}}, 3)))); + EXPECT_EQUAL(TensorSpec(type).add({{"x", "a"}}, 3), attribute->getTensor(1)->toSpec()); } } diff --git a/searchcore/src/vespa/searchcore/proton/common/attribute_updater.cpp b/searchcore/src/vespa/searchcore/proton/common/attribute_updater.cpp index 3ad838c595b..ca45088d977 100644 --- a/searchcore/src/vespa/searchcore/proton/common/attribute_updater.cpp +++ b/searchcore/src/vespa/searchcore/proton/common/attribute_updater.cpp @@ -1,7 +1,6 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "attribute_updater.h" -#include <vespa/eval/tensor/tensor.h> #include <vespa/document/base/forcelink.h> #include <vespa/document/fieldvalue/arrayfieldvalue.h> #include <vespa/document/fieldvalue/literalfieldvalue.h> @@ -15,7 +14,9 @@ #include <vespa/document/update/clearvalueupdate.h> #include <vespa/document/update/mapvalueupdate.h> #include <vespa/document/update/removevalueupdate.h> +#include <vespa/document/update/tensoraddupdate.h> #include <vespa/document/update/tensormodifyupdate.h> +#include <vespa/eval/tensor/tensor.h> #include <vespa/searchlib/attribute/attributevector.hpp> #include <vespa/searchlib/attribute/changevector.hpp> #include <vespa/searchlib/attribute/predicate_attribute.h> @@ -205,8 +206,9 @@ AttributeUpdater::handleUpdate(PredicateAttribute &vec, uint32_t lid, const Valu namespace { +template <typename TensorUpdateType> void -applyTensorModifyUpdate(TensorAttribute &vec, uint32_t lid, const TensorModifyUpdate &update) +applyTensorUpdate(TensorAttribute &vec, uint32_t lid, const TensorUpdateType &update) { auto oldTensor = vec.getTensor(lid); if (oldTensor) { @@ -233,7 +235,9 @@ AttributeUpdater::handleUpdate(TensorAttribute &vec, uint32_t lid, const ValueUp updateValue(vec, lid, assign.getValue()); } } else if (op == ValueUpdate::TensorModifyUpdate) { - applyTensorModifyUpdate(vec, lid, static_cast<const TensorModifyUpdate &>(upd)); + applyTensorUpdate(vec, lid, static_cast<const TensorModifyUpdate &>(upd)); + } else if (op == ValueUpdate::TensorAddUpdate) { + applyTensorUpdate(vec, lid, static_cast<const TensorAddUpdate &>(upd)); } else if (op == ValueUpdate::Clear) { vec.clearDoc(lid); } else { |