aboutsummaryrefslogtreecommitdiffstats
path: root/document
diff options
context:
space:
mode:
authorGeir Storli <geirst@verizonmedia.com>2019-02-01 14:23:10 +0000
committerGeir Storli <geirst@verizonmedia.com>2019-02-01 14:23:10 +0000
commit12cf8c1a86fe0d796de358d63691ce211edf25ce (patch)
treeb4bcf83e8cadae050d49002e6b0fb80f2fee29f9 /document
parent9df35eda38ec64c3e3ee5935eee65899d1e15840 (diff)
Apply TensorModifyUpdate to the associated tensor attribute in searchcore.
Diffstat (limited to 'document')
-rw-r--r--document/src/vespa/document/update/tensormodifyupdate.cpp23
-rw-r--r--document/src/vespa/document/update/tensormodifyupdate.h3
-rw-r--r--document/src/vespa/document/update/valueupdate.h3
3 files changed, 21 insertions, 8 deletions
diff --git a/document/src/vespa/document/update/tensormodifyupdate.cpp b/document/src/vespa/document/update/tensormodifyupdate.cpp
index 5529adaf5ce..a02379e4991 100644
--- a/document/src/vespa/document/update/tensormodifyupdate.cpp
+++ b/document/src/vespa/document/update/tensormodifyupdate.cpp
@@ -1,15 +1,15 @@
// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "tensormodifyupdate.h"
-#include <vespa/document/base/field.h>
#include <vespa/document/base/exceptions.h>
+#include <vespa/document/base/field.h>
#include <vespa/document/fieldvalue/document.h>
#include <vespa/document/fieldvalue/tensorfieldvalue.h>
-#include <vespa/document/util/serializableexceptions.h>
#include <vespa/document/serialization/vespadocumentdeserializer.h>
+#include <vespa/document/util/serializableexceptions.h>
#include <vespa/eval/eval/operation.h>
-#include <vespa/eval/tensor/tensor.h>
#include <vespa/eval/tensor/cell_values.h>
+#include <vespa/eval/tensor/tensor.h>
#include <vespa/vespalib/objects/nbostream.h>
#include <vespa/vespalib/stllike/asciistream.h>
#include <vespa/vespalib/util/stringfmt.h>
@@ -117,16 +117,25 @@ TensorModifyUpdate::checkCompatibility(const Field& field) const
}
}
+std::unique_ptr<Tensor>
+TensorModifyUpdate::applyTo(const Tensor &tensor) const
+{
+ auto &cellTensor = _tensor->getAsTensorPtr();
+ if (cellTensor) {
+ vespalib::tensor::CellValues cellValues(static_cast<const vespalib::tensor::SparseTensor &>(*cellTensor));
+ return tensor.modify(getJoinFunction(_operation), cellValues);
+ }
+ return std::unique_ptr<Tensor>();
+}
+
bool
TensorModifyUpdate::applyTo(FieldValue& value) const
{
if (value.inherits(TensorFieldValue::classId)) {
TensorFieldValue &tensorFieldValue = static_cast<TensorFieldValue &>(value);
auto &oldTensor = tensorFieldValue.getAsTensorPtr();
- auto &cellTensor = _tensor->getAsTensorPtr();
- if (cellTensor) {
- vespalib::tensor::CellValues cellValues(static_cast<const vespalib::tensor::SparseTensor &>(*cellTensor));
- auto newTensor = oldTensor->modify(getJoinFunction(_operation), cellValues);
+ auto newTensor = applyTo(*oldTensor);
+ if (newTensor) {
tensorFieldValue = std::move(newTensor);
}
} else {
diff --git a/document/src/vespa/document/update/tensormodifyupdate.h b/document/src/vespa/document/update/tensormodifyupdate.h
index fd89c9da47b..dcb9bcf0470 100644
--- a/document/src/vespa/document/update/tensormodifyupdate.h
+++ b/document/src/vespa/document/update/tensormodifyupdate.h
@@ -2,6 +2,8 @@
#include "valueupdate.h"
+namespace vespalib::tensor { class Tensor; }
+
namespace document {
class TensorFieldValue;
@@ -37,6 +39,7 @@ public:
Operation getOperation() const { return _operation; }
const TensorFieldValue &getTensor() const { return *_tensor; }
void checkCompatibility(const Field &field) const override;
+ std::unique_ptr<vespalib::tensor::Tensor> applyTo(const vespalib::tensor::Tensor &tensor) const;
bool applyTo(FieldValue &value) const override;
void printXml(XmlOutputStream &xos) const override;
void print(std::ostream &out, bool verbose, const std::string &indent) const override;
diff --git a/document/src/vespa/document/update/valueupdate.h b/document/src/vespa/document/update/valueupdate.h
index 963e1ad1d96..ceb711074f4 100644
--- a/document/src/vespa/document/update/valueupdate.h
+++ b/document/src/vespa/document/update/valueupdate.h
@@ -53,7 +53,8 @@ public:
Assign = IDENTIFIABLE_CLASSID(AssignValueUpdate),
Clear = IDENTIFIABLE_CLASSID(ClearValueUpdate),
Map = IDENTIFIABLE_CLASSID(MapValueUpdate),
- Remove = IDENTIFIABLE_CLASSID(RemoveValueUpdate)
+ Remove = IDENTIFIABLE_CLASSID(RemoveValueUpdate),
+ TensorModifyUpdate = IDENTIFIABLE_CLASSID(TensorModifyUpdate)
};
ValueUpdate()