diff options
author | Henning Baldersheim <balder@oath.com> | 2018-08-22 13:33:27 +0200 |
---|---|---|
committer | Henning Baldersheim <balder@oath.com> | 2018-08-22 13:33:27 +0200 |
commit | 5d7aaba3b0e0d0060b5ddce7ee41949936ba4209 (patch) | |
tree | ed923149a6b7cfd8599556f322aaf1844e88e6d2 | |
parent | dd0acdf6f06f43e5a673be9e703deb5f9b570d4d (diff) |
Test non-updateable attributes.
4 files changed, 42 insertions, 21 deletions
diff --git a/searchcore/src/tests/proton/matching/attribute_operation_test.cpp b/searchcore/src/tests/proton/matching/attribute_operation_test.cpp index 8aafc518487..f9334e31dbf 100644 --- a/searchcore/src/tests/proton/matching/attribute_operation_test.cpp +++ b/searchcore/src/tests/proton/matching/attribute_operation_test.cpp @@ -44,9 +44,10 @@ TEST("test illegal operations on float attribute") { } AttributeVector::SP -createAttribute(BasicType basicType, const vespalib::string &fieldName) +createAttribute(BasicType basicType, const vespalib::string &fieldName, bool fastSearch = false) { Config cfg(basicType, CollectionType::SINGLE); + cfg.setFastSearch(fastSearch); auto av = search::AttributeFactory::createAttribute(fieldName, cfg); while (20 >= av->getNumDocs()) { AttributeVector::DocId checkDocId(0u); @@ -57,13 +58,15 @@ createAttribute(BasicType basicType, const vespalib::string &fieldName) } template <typename T, typename A> -void verify(vespalib::stringref operation, AttributeVector & attr, T initial, T expected) { +void verify(BasicType type, vespalib::stringref operation, AttributeVector & attr, T initial, T expected) { + (void) expected; auto & attrT = dynamic_cast<A &>(attr); for (uint32_t docid(0); docid < attr.getNumDocs(); docid++) { - attrT.set(docid, initial); + attrT.update(docid, initial); } + attr.commit(); std::vector<uint32_t> docs = {1,7,9,10,17,19}; - auto op = AttributeOperation::create(attr.getBasicType(), operation, docs); + auto op = AttributeOperation::create(type, operation, docs); EXPECT_TRUE(op); op->operator()(attr); for (uint32_t docid(0); docid < attr.getNumDocs(); docid++) { @@ -76,22 +79,32 @@ void verify(vespalib::stringref operation, AttributeVector & attr, T initial, T } } -template <typename T> +template <typename T, typename A> void verify(vespalib::stringref operation, AttributeVector & attr, T initial, T expected) { + verify<T, A>(attr.getBasicType(), operation, attr, initial, expected); +} + +template <typename T> +void verify(BasicType typeClaimed, vespalib::stringref operation, AttributeVector & attr, T initial, T expected) { BasicType::Type type = attr.getBasicType(); if (type == BasicType::INT64) { - verify<int64_t, search::SingleValueNumericAttribute<search::IntegerAttributeTemplate<int64_t>>>(operation, attr, initial, expected); + verify<int64_t, search::IntegerAttributeTemplate<int64_t>>(typeClaimed, operation, attr, initial, expected); } else if (type == BasicType::INT32) { - verify<int32_t, search::SingleValueNumericAttribute<search::IntegerAttributeTemplate<int32_t>>>(operation, attr, initial, expected); + verify<int32_t, search::IntegerAttributeTemplate<int32_t>>(typeClaimed, operation, attr, initial, expected); } else if (type == BasicType::DOUBLE) { - verify<double , search::SingleValueNumericAttribute<search::FloatingPointAttributeTemplate<double >>>(operation, attr, initial, expected); + verify<double , search::FloatingPointAttributeTemplate<double >>(typeClaimed, operation, attr, initial, expected); } else if (type == BasicType::FLOAT) { - verify<float , search::SingleValueNumericAttribute<search::FloatingPointAttributeTemplate<float >>>(operation, attr, initial, expected); + verify<float , search::FloatingPointAttributeTemplate<float >>(typeClaimed, operation, attr, initial, expected); } else { ASSERT_TRUE(false); } } +template <typename T> +void verify(vespalib::stringref operation, AttributeVector & attr, T initial, T expected) { + verify<T>(attr.getBasicType(), operation, attr, initial, expected); +} + TEST("test all integer operations") { auto attr = createAttribute(BasicType::INT64, "ai"); const std::vector<std::pair<const char *, int64_t>> expectedOperation = { @@ -112,4 +125,18 @@ TEST("test all float operations") { } } +TEST("test that even slightly mismatching type will fail to update") { + auto attr = createAttribute(BasicType::INT32, "ai"); + for (auto operation : {"++", "--", "+=7", "-=9", "*=3", "/=3", "%=3"}) { + TEST_DO(verify<int64_t>(BasicType::INT64, operation, *attr, 7, 7)); + } +} + +TEST("test that fastsearch attributes will fail to update") { + auto attr = createAttribute(BasicType::INT64, "ai", true); + 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/floatbase.h b/searchlib/src/vespa/searchlib/attribute/floatbase.h index 955b2b252af..10bd2648aca 100644 --- a/searchlib/src/vespa/searchlib/attribute/floatbase.h +++ b/searchlib/src/vespa/searchlib/attribute/floatbase.h @@ -66,7 +66,8 @@ public: typedef SequentialReadModifyWriteInterface<LoadedNumericValueT> LoadedVector; virtual uint32_t getRawValues(DocId doc, const multivalue::Value<T> * & values) const; virtual uint32_t getRawValues(DocId doc, const multivalue::WeightedValue<T> * & values) const; - + virtual T get(DocId doc) const = 0; + virtual T getFromEnum(EnumHandle e) const = 0; protected: FloatingPointAttributeTemplate(const vespalib::string & name); FloatingPointAttributeTemplate(const vespalib::string & name, const Config & c); @@ -83,8 +84,6 @@ private: bool findEnum(const char *value, EnumHandle &e) const override; std::vector<EnumHandle> findFoldedEnums(const char *value) const override; bool isUndefined(DocId doc) const override; - virtual T get(DocId doc) const = 0; - virtual T getFromEnum(EnumHandle e) const = 0; double getFloatFromEnum(EnumHandle e) const override; long onSerializeForAscendingSort(DocId doc, void * serTo, long available, const common::BlobConverter * bc) const override; diff --git a/searchlib/src/vespa/searchlib/attribute/integerbase.h b/searchlib/src/vespa/searchlib/attribute/integerbase.h index 5dec40fd4da..c3299d9fdf7 100644 --- a/searchlib/src/vespa/searchlib/attribute/integerbase.h +++ b/searchlib/src/vespa/searchlib/attribute/integerbase.h @@ -65,7 +65,8 @@ public: typedef SequentialReadModifyWriteInterface<LoadedNumericValueT> LoadedVector; virtual uint32_t getRawValues(DocId doc, const multivalue::Value<T> * & values) const; virtual uint32_t getRawValues(DocId doc, const multivalue::WeightedValue<T> * & values) const; - + virtual T get(DocId doc) const = 0; + virtual T getFromEnum(EnumHandle e) const = 0; protected: IntegerAttributeTemplate(const vespalib::string & name) : IntegerAttribute(name, BasicType::fromType(T())), @@ -100,8 +101,6 @@ private: bool findEnum(const char *value, EnumHandle &e) const override; std::vector<EnumHandle> findFoldedEnums(const char *value) const override; - virtual T get(DocId doc) const = 0; - virtual T getFromEnum(EnumHandle e) const = 0; largeint_t getIntFromEnum(EnumHandle e) const override; long onSerializeForAscendingSort(DocId doc, void * serTo, long available, const common::BlobConverter * bc) const override; long onSerializeForDescendingSort(DocId doc, void * serTo, long available, const common::BlobConverter * bc) const override; diff --git a/searchlib/src/vespa/searchlib/expression/expressionnode.h b/searchlib/src/vespa/searchlib/expression/expressionnode.h index 12e0897be08..da8a9e2c3ee 100644 --- a/searchlib/src/vespa/searchlib/expression/expressionnode.h +++ b/searchlib/src/vespa/searchlib/expression/expressionnode.h @@ -5,11 +5,9 @@ #include <vespa/vespalib/objects/identifiable.hpp> #include <vespa/vespalib/objects/visit.h> -namespace search { +namespace search::attribute { class IAttributeContext; } -namespace attribute { class IAttributeContext; } - -namespace expression { +namespace search::expression { typedef uint32_t DocId; @@ -55,5 +53,3 @@ private: typedef ExpressionNode::CP * ExpressionNodeArray; } -} - |