summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeir Storli <geirst@verizonmedia.com>2019-02-11 12:58:13 +0100
committerGitHub <noreply@github.com>2019-02-11 12:58:13 +0100
commit1f3d5bb43009736f3a1478cebecdc6e933ee7ea2 (patch)
treeb1252b9309949a542eca69fed7298acb2d504a85
parenta88534e3a2a89d9176d1c7b3b2b1f43b8ea21276 (diff)
parentd793a195fdaf338829bf768f94fec3111f7f8a20 (diff)
Merge pull request #8465 from vespa-engine/toregge/wire-in-tensor-add-update-logic
Implement applyTo method for TensorAddUpdate.
-rw-r--r--document/src/tests/documentupdatetestcase.cpp24
-rw-r--r--document/src/vespa/document/update/tensoraddupdate.cpp14
-rw-r--r--document/src/vespa/document/update/tensormodifyupdate.cpp25
3 files changed, 54 insertions, 9 deletions
diff --git a/document/src/tests/documentupdatetestcase.cpp b/document/src/tests/documentupdatetestcase.cpp
index c7660e5d527..32d23349dc0 100644
--- a/document/src/tests/documentupdatetestcase.cpp
+++ b/document/src/tests/documentupdatetestcase.cpp
@@ -178,6 +178,12 @@ std::unique_ptr<Tensor> createExpectedUpdatedTensorWith2Cells() {
{{{"x", "9"}, {"y", "9"}}, 11} }, {"x", "y"});
}
+std::unique_ptr<Tensor> createExpectedAddUpdatedTensorWith3Cells() {
+ return createTensor({ {{{"x", "8"}, {"y", "8"}}, 2},
+ {{{"x", "8"}, {"y", "9"}}, 2},
+ {{{"x", "9"}, {"y", "9"}}, 11} }, {"x", "y"});
+}
+
FieldValue::UP createTensorFieldValueWith2Cells() {
auto fv(std::make_unique<TensorFieldValue>());
*fv = createTensorWith2Cells();
@@ -973,14 +979,21 @@ DocumentUpdateTest::testTensorAddUpdate()
updated.setValue(updated.getField("tensor"), *oldTensor);
CPPUNIT_ASSERT(*doc != updated);
testValueUpdate(*createTensorAddUpdate(), *DataType::TENSOR);
+ std::string expTensorAddUpdateString("TensorAddUpdate("
+ "{TensorFieldValue: "
+ "{\"dimensions\":[\"x\",\"y\"],"
+ "\"cells\":["
+ "{\"address\":{\"x\":\"8\",\"y\":\"9\"},\"value\":2},"
+ "{\"address\":{\"x\":\"8\",\"y\":\"8\"},\"value\":2}"
+ "]}})");
+ CPPUNIT_ASSERT_EQUAL(expTensorAddUpdateString, createTensorAddUpdate()->toString());
DocumentUpdate upd(docMan.getTypeRepo(), *doc->getDataType(), doc->getId());
upd.addUpdate(FieldUpdate(upd.getType().getField("tensor")).addUpdate(*createTensorAddUpdate()));
upd.applyTo(updated);
FieldValue::UP fval(updated.getValue("tensor"));
CPPUNIT_ASSERT(fval);
auto &tensor = asTensor(*fval);
- // Note: Placeholder value for now
- auto expectedUpdatedTensor = createTensorWith2Cells();
+ auto expectedUpdatedTensor = createExpectedAddUpdatedTensorWith3Cells();
CPPUNIT_ASSERT(tensor.equals(*expectedUpdatedTensor));
}
@@ -994,6 +1007,13 @@ DocumentUpdateTest::testTensorModifyUpdate()
updated.setValue(updated.getField("tensor"), *oldTensor);
CPPUNIT_ASSERT(*doc != updated);
testValueUpdate(*createTensorModifyUpdate(), *DataType::TENSOR);
+ std::string expTensorModifyUpdateString("TensorModifyUpdate(replace,"
+ "{TensorFieldValue: "
+ "{\"dimensions\":[\"x\",\"y\"],"
+ "\"cells\":["
+ "{\"address\":{\"x\":\"8\",\"y\":\"9\"},\"value\":2}"
+ "]}})");
+ CPPUNIT_ASSERT_EQUAL(expTensorModifyUpdateString, createTensorModifyUpdate()->toString());
DocumentUpdate upd(docMan.getTypeRepo(), *doc->getDataType(), doc->getId());
upd.addUpdate(FieldUpdate(upd.getType().getField("tensor")).addUpdate(*createTensorModifyUpdate()));
upd.applyTo(updated);
diff --git a/document/src/vespa/document/update/tensoraddupdate.cpp b/document/src/vespa/document/update/tensoraddupdate.cpp
index eb708d9f651..714eee28ff3 100644
--- a/document/src/vespa/document/update/tensoraddupdate.cpp
+++ b/document/src/vespa/document/update/tensoraddupdate.cpp
@@ -81,7 +81,11 @@ TensorAddUpdate::checkCompatibility(const Field& field) const
std::unique_ptr<Tensor>
TensorAddUpdate::applyTo(const Tensor &tensor) const
{
- return tensor.clone();
+ auto &addTensor = _tensor->getAsTensorPtr();
+ if (addTensor) {
+ return tensor.add(*addTensor);
+ }
+ return std::unique_ptr<Tensor>();
}
bool
@@ -112,9 +116,11 @@ TensorAddUpdate::printXml(XmlOutputStream& xos) const
void
TensorAddUpdate::print(std::ostream& out, bool verbose, const std::string& indent) const
{
- (void) verbose;
- (void) indent;
- out << "{TensorAddUpdate::print not yet implemented}";
+ out << indent << "TensorAddUpdate(";
+ if (_tensor) {
+ _tensor->print(out, verbose, indent);
+ }
+ out << ")";
}
void
diff --git a/document/src/vespa/document/update/tensormodifyupdate.cpp b/document/src/vespa/document/update/tensormodifyupdate.cpp
index a02379e4991..8cee367cae0 100644
--- a/document/src/vespa/document/update/tensormodifyupdate.cpp
+++ b/document/src/vespa/document/update/tensormodifyupdate.cpp
@@ -50,6 +50,23 @@ getJoinFunction(TensorModifyUpdate::Operation operation)
}
}
+vespalib::string
+getJoinFunctionName(TensorModifyUpdate::Operation operation)
+{
+ using Operation = TensorModifyUpdate::Operation;
+
+ switch (operation) {
+ case Operation::REPLACE:
+ return "replace";
+ case Operation::ADD:
+ return "add";
+ case Operation::MUL:
+ return "multiply";
+ default:
+ throw IllegalArgumentException("Bad operation", VESPA_STRLOC);
+ }
+}
+
}
IMPLEMENT_IDENTIFIABLE(TensorModifyUpdate, ValueUpdate);
@@ -156,9 +173,11 @@ TensorModifyUpdate::printXml(XmlOutputStream& xos) const
void
TensorModifyUpdate::print(std::ostream& out, bool verbose, const std::string& indent) const
{
- (void) verbose;
- (void) indent;
- out << "{TensorModifyUpdate::print not yet implemented}";
+ out << indent << "TensorModifyUpdate(" << getJoinFunctionName(_operation) << ",";
+ if (_tensor) {
+ _tensor->print(out, verbose, indent);
+ }
+ out << ")";
}
void