summaryrefslogtreecommitdiffstats
path: root/searchlib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@oath.com>2018-08-27 10:50:31 +0200
committerHenning Baldersheim <balder@oath.com>2018-08-27 10:50:31 +0200
commit406bb7fca1f90f0ab97f6f6b4752ca3e235c08ce (patch)
treecadff66271030181354170ec0a63667e4ad20bd6 /searchlib
parent4b2f2f0195b4b3c4483d5539b8f50cdd83eb5bf6 (diff)
Only allow query time modification of attributes marked mutable.
Diffstat (limited to 'searchlib')
-rw-r--r--searchlib/src/tests/attribute/attribute_operation/attribute_operation_test.cpp12
-rw-r--r--searchlib/src/vespa/searchlib/attribute/attribute_operation.cpp4
2 files changed, 13 insertions, 3 deletions
diff --git a/searchlib/src/tests/attribute/attribute_operation/attribute_operation_test.cpp b/searchlib/src/tests/attribute/attribute_operation/attribute_operation_test.cpp
index 12bac6c6b20..bdd5682acb6 100644
--- a/searchlib/src/tests/attribute/attribute_operation/attribute_operation_test.cpp
+++ b/searchlib/src/tests/attribute/attribute_operation/attribute_operation_test.cpp
@@ -45,10 +45,11 @@ TEST("test illegal operations on float attribute") {
}
AttributeVector::SP
-createAttribute(BasicType basicType, const vespalib::string &fieldName, bool fastSearch = false)
+createAttribute(BasicType basicType, const vespalib::string &fieldName, bool fastSearch = false, bool immutable = false)
{
Config cfg(basicType, CollectionType::SINGLE);
- cfg.setFastSearch(fastSearch);
+ cfg.setMutable(!immutable)
+ .setFastSearch(fastSearch);
auto av = search::AttributeFactory::createAttribute(fieldName, cfg);
while (20 >= av->getNumDocs()) {
AttributeVector::DocId checkDocId(0u);
@@ -176,4 +177,11 @@ TEST("test that fastsearch attributes will fail to update") {
}
}
+TEST("test that immutable attributes will fail to update") {
+ auto attr = createAttribute(BasicType::INT64, "ai", true, false);
+ for (auto operation : {"++", "--", "+=7", "-=9", "*=3", "/=3", "%=3"}) {
+ TEST_DO(verify<int64_t>(BasicType::INT64, operation, *attr, 7, 7));
+ }
+}
+
TEST_MAIN() { TEST_RUN_ALL(); }
diff --git a/searchlib/src/vespa/searchlib/attribute/attribute_operation.cpp b/searchlib/src/vespa/searchlib/attribute/attribute_operation.cpp
index 5580fc25aef..0a81c5cb8b9 100644
--- a/searchlib/src/vespa/searchlib/attribute/attribute_operation.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/attribute_operation.cpp
@@ -94,7 +94,9 @@ struct UpdateFast {
op(operand)
{}
void operator()(uint32_t docid) { attr->set(docid, op(attr->getFast(docid))); }
- bool valid() const { return (attr != nullptr); }
+ bool valid() const {
+ return (attr != nullptr) &&
+ (dynamic_cast<const AttributeVector &>(*attr).getConfig().isMutable()); }
};
template <typename OP>