summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeir Storli <geirst@verizonmedia.com>2019-02-21 15:03:58 +0000
committerGeir Storli <geirst@verizonmedia.com>2019-02-21 15:03:58 +0000
commit91df22d8cfa4e099dde03f381a68bba5f395ebc9 (patch)
tree6695bc580e523e9d2d6a289420086fcb0b3a91b1
parent051dac70f4c54e0bef7d24c21be7751eb334c0b0 (diff)
Integrate TensorRemoveUpdate in attribute updater.
-rw-r--r--searchcore/src/tests/proton/common/attribute_updater/attribute_updater_test.cpp67
-rw-r--r--searchcore/src/vespa/searchcore/proton/common/attribute_updater.cpp3
2 files changed, 47 insertions, 23 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 afbb1c30f17..78cd9ce44b9 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
@@ -20,6 +20,7 @@
#include <vespa/document/update/removevalueupdate.h>
#include <vespa/document/update/tensor_add_update.h>
#include <vespa/document/update/tensor_modify_update.h>
+#include <vespa/document/update/tensor_remove_update.h>
#include <vespa/eval/tensor/default_tensor_engine.h>
#include <vespa/eval/tensor/tensor.h>
#include <vespa/searchcore/proton/common/attribute_updater.h>
@@ -28,8 +29,8 @@
#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/vespalib/stllike/hash_map.hpp>
+#include <vespa/vespalib/testkit/testapp.h>
#include <vespa/log/log.h>
LOG_SETUP("attribute_updater_test");
@@ -76,7 +77,8 @@ makeDocumentTypeRepo()
.addField("wsfloat", Wset(DataType::T_FLOAT))
.addField("wsstring", Wset(DataType::T_STRING))
.addField("ref", 333)
- .addField("dense_tensor", DataType::T_TENSOR),
+ .addField("dense_tensor", DataType::T_TENSOR)
+ .addField("sparse_tensor", DataType::T_TENSOR),
Struct("testdoc.body"))
.referenceType(333, 222);
return std::make_unique<DocumentTypeRepo>(builder.config());
@@ -416,35 +418,54 @@ makeTensorFieldValue(const TensorSpec &spec)
return result;
}
-void
-setTensor(TensorAttribute &attribute, uint32_t lid, const TensorSpec &spec)
-{
- auto tensor = makeTensor(spec);
- attribute.setTensor(lid, *tensor);
- attribute.commit();
-}
+template <typename TensorAttributeType>
+struct TensorFixture : public Fixture {
+ vespalib::string type;
+ std::unique_ptr<TensorAttributeType> attribute;
-TEST_F("require that tensor modify update is applied", Fixture)
-{
- vespalib::string type = "tensor(x[2])";
- auto attribute = makeTensorAttribute<DenseTensorAttribute>("dense_tensor", type);
- setTensor(*attribute, 1, TensorSpec(type).add({{"x", 0}}, 3).add({{"x", 1}}, 5));
+ TensorFixture(const vespalib::string &type_, const vespalib::string &name)
+ : type(type_),
+ attribute(makeTensorAttribute<TensorAttributeType>(name, type))
+ {
+ }
- f.applyValueUpdate(*attribute, 1,
+ void setTensor(const TensorSpec &spec) {
+ auto tensor = makeTensor(spec);
+ attribute->setTensor(1, *tensor);
+ attribute->commit();
+ }
+
+ void assertTensor(const TensorSpec &expSpec) {
+ EXPECT_EQUAL(expSpec, attribute->getTensor(1)->toSpec());
+ }
+};
+
+TEST_F("require that tensor modify update is applied",
+ TensorFixture<DenseTensorAttribute>("tensor(x[2])", "dense_tensor"))
+{
+ f.setTensor(TensorSpec(f.type).add({{"x", 0}}, 3).add({{"x", 1}}, 5));
+ f.applyValueUpdate(*f.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());
+ f.assertTensor(TensorSpec(f.type).add({{"x", 0}}, 7).add({{"x", 1}}, 5));
}
-TEST_F("require that tensor add update is applied", Fixture)
+TEST_F("require that tensor add update is applied",
+ TensorFixture<GenericTensorAttribute>("tensor(x{})", "sparse_tensor"))
{
- vespalib::string type = "tensor(x{})";
- auto attribute = makeTensorAttribute<GenericTensorAttribute>("dense_tensor", type);
- setTensor(*attribute, 1, TensorSpec(type).add({{"x", "a"}}, 2));
+ f.setTensor(TensorSpec(f.type).add({{"x", "a"}}, 2));
+ f.applyValueUpdate(*f.attribute, 1,
+ TensorAddUpdate(makeTensorFieldValue(TensorSpec(f.type).add({{"x", "a"}}, 3))));
+ f.assertTensor(TensorSpec(f.type).add({{"x", "a"}}, 3));
+}
- f.applyValueUpdate(*attribute, 1,
- TensorAddUpdate(makeTensorFieldValue(TensorSpec(type).add({{"x", "a"}}, 3))));
- EXPECT_EQUAL(TensorSpec(type).add({{"x", "a"}}, 3), attribute->getTensor(1)->toSpec());
+TEST_F("require that tensor remove update is applied",
+ TensorFixture<GenericTensorAttribute>("tensor(x{})", "sparse_tensor"))
+{
+ f.setTensor(TensorSpec(f.type).add({{"x", "a"}}, 2).add({{"x", "b"}}, 3));
+ f.applyValueUpdate(*f.attribute, 1,
+ TensorRemoveUpdate(makeTensorFieldValue(TensorSpec(f.type).add({{"x", "b"}}, 1))));
+ f.assertTensor(TensorSpec(f.type).add({{"x", "a"}}, 2));
}
}
diff --git a/searchcore/src/vespa/searchcore/proton/common/attribute_updater.cpp b/searchcore/src/vespa/searchcore/proton/common/attribute_updater.cpp
index 933857cffed..fcca1c2a737 100644
--- a/searchcore/src/vespa/searchcore/proton/common/attribute_updater.cpp
+++ b/searchcore/src/vespa/searchcore/proton/common/attribute_updater.cpp
@@ -16,6 +16,7 @@
#include <vespa/document/update/removevalueupdate.h>
#include <vespa/document/update/tensor_add_update.h>
#include <vespa/document/update/tensor_modify_update.h>
+#include <vespa/document/update/tensor_remove_update.h>
#include <vespa/eval/tensor/tensor.h>
#include <vespa/searchlib/attribute/attributevector.hpp>
#include <vespa/searchlib/attribute/changevector.hpp>
@@ -238,6 +239,8 @@ AttributeUpdater::handleUpdate(TensorAttribute &vec, uint32_t lid, const ValueUp
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::TensorRemoveUpdate) {
+ applyTensorUpdate(vec, lid, static_cast<const TensorRemoveUpdate &>(upd));
} else if (op == ValueUpdate::Clear) {
vec.clearDoc(lid);
} else {