aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2021-10-29 09:58:08 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2021-10-29 09:58:08 +0000
commite6ddc7c058ffb1a5f44af91f5f965057ed185fe4 (patch)
tree1e0978d25825626c658fa53f696757eee79f19b5 /searchlib
parentb88cf665727f476624ecea924101a83c7a4fe682 (diff)
Clean and simplify default value handling
Diffstat (limited to 'searchlib')
-rw-r--r--searchlib/src/tests/attribute/attribute_operation/attribute_operation_test.cpp5
-rw-r--r--searchlib/src/tests/attribute/attribute_test.cpp11
-rw-r--r--searchlib/src/vespa/searchlib/attribute/attributevector.h1
-rw-r--r--searchlib/src/vespa/searchlib/attribute/enumattribute.h2
-rw-r--r--searchlib/src/vespa/searchlib/attribute/floatbase.h3
-rw-r--r--searchlib/src/vespa/searchlib/attribute/floatbase.hpp11
-rw-r--r--searchlib/src/vespa/searchlib/attribute/integerbase.h5
-rw-r--r--searchlib/src/vespa/searchlib/attribute/integerbase.hpp11
-rw-r--r--searchlib/src/vespa/searchlib/attribute/not_implemented_attribute.cpp6
-rw-r--r--searchlib/src/vespa/searchlib/attribute/not_implemented_attribute.h1
-rw-r--r--searchlib/src/vespa/searchlib/attribute/singlenumericattribute.hpp2
-rw-r--r--searchlib/src/vespa/searchlib/attribute/stringbase.h1
12 files changed, 17 insertions, 42 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 a57469e2bd1..baecb54fbec 100644
--- a/searchlib/src/tests/attribute/attribute_operation/attribute_operation_test.cpp
+++ b/searchlib/src/tests/attribute/attribute_operation/attribute_operation_test.cpp
@@ -47,15 +47,18 @@ TEST("test illegal operations on float attribute") {
AttributeVector::SP
createAttribute(BasicType basicType, const vespalib::string &fieldName, bool fastSearch = false, bool immutable = false)
{
+ constexpr size_t NUM_DOCS = 20;
Config cfg(basicType, CollectionType::SINGLE);
cfg.setMutable(!immutable)
.setFastSearch(fastSearch);
auto av = search::AttributeFactory::createAttribute(fieldName, cfg);
- while (20 >= av->getNumDocs()) {
+ while (NUM_DOCS >= av->getNumDocs()) {
AttributeVector::DocId checkDocId(0u);
ASSERT_TRUE(av->addDoc(checkDocId));
+ ASSERT_EQUAL(immutable, av->isUndefined(checkDocId));
}
av->commit();
+ ASSERT_EQUAL(immutable, av->isUndefined(NUM_DOCS/2));
return av;
}
diff --git a/searchlib/src/tests/attribute/attribute_test.cpp b/searchlib/src/tests/attribute/attribute_test.cpp
index 6ee97595b79..bd84a6ca419 100644
--- a/searchlib/src/tests/attribute/attribute_test.cpp
+++ b/searchlib/src/tests/attribute/attribute_test.cpp
@@ -2061,12 +2061,12 @@ AttributeTest::testCompactLidSpace()
namespace {
uint32_t
-get_default_value_ref_count(AttributeVector &attr)
+get_default_value_ref_count(AttributeVector &attr, int32_t defaultValue)
{
auto *enum_store_base = attr.getEnumStoreBase();
auto &enum_store = dynamic_cast<EnumStoreT<int32_t> &>(*enum_store_base);
IAttributeVector::EnumHandle default_value_handle(0);
- if (enum_store.find_enum(attr.getDefaultValue(), default_value_handle)) {
+ if (enum_store.find_enum(defaultValue, default_value_handle)) {
vespalib::datastore::EntryRef default_value_ref(default_value_handle);
assert(default_value_ref.valid());
return enum_store.get_ref_count(default_value_ref);
@@ -2085,14 +2085,15 @@ AttributeTest::test_default_value_ref_count_is_updated_after_shrink_lid_space()
cfg.setFastSearch(true);
vespalib::string name = "shrink";
AttributePtr attr = AttributeFactory::createAttribute(name, cfg);
+ const auto & iattr = dynamic_cast<const search::IntegerAttributeTemplate<int32_t> &>(*attr);
attr->addReservedDoc();
attr->addDocs(10);
- EXPECT_EQUAL(11u, get_default_value_ref_count(*attr));
+ EXPECT_EQUAL(11u, get_default_value_ref_count(*attr, iattr.defaultValue()));
attr->compactLidSpace(6);
- EXPECT_EQUAL(11u, get_default_value_ref_count(*attr));
+ EXPECT_EQUAL(11u, get_default_value_ref_count(*attr, iattr.defaultValue()));
attr->shrinkLidSpace();
EXPECT_EQUAL(6u, attr->getNumDocs());
- EXPECT_EQUAL(6u, get_default_value_ref_count(*attr));
+ EXPECT_EQUAL(6u, get_default_value_ref_count(*attr, iattr.defaultValue()));
}
template <typename AttributeType>
diff --git a/searchlib/src/vespa/searchlib/attribute/attributevector.h b/searchlib/src/vespa/searchlib/attribute/attributevector.h
index f5a79c3637e..90d08fa681c 100644
--- a/searchlib/src/vespa/searchlib/attribute/attributevector.h
+++ b/searchlib/src/vespa/searchlib/attribute/attributevector.h
@@ -460,7 +460,6 @@ public:
*/
virtual uint32_t clearDoc(DocId doc) = 0;
- virtual largeint_t getDefaultValue() const = 0;
// Implements IAttributeVector
virtual uint32_t get(DocId doc, EnumHandle *v, uint32_t sz) const override = 0;
diff --git a/searchlib/src/vespa/searchlib/attribute/enumattribute.h b/searchlib/src/vespa/searchlib/attribute/enumattribute.h
index 2848d479eab..8136e654152 100644
--- a/searchlib/src/vespa/searchlib/attribute/enumattribute.h
+++ b/searchlib/src/vespa/searchlib/attribute/enumattribute.h
@@ -46,7 +46,7 @@ protected:
void load_enum_store(LoadedVector& loaded) override;
uint64_t getUniqueValueCount() const override;
- static EnumEntryType getDefaultEnumTypeValue() { return B::defaultValue(); }
+ EnumEntryType getDefaultEnumTypeValue() { return B::defaultValue(); }
/*
* Iterate through the change vector and find new unique values.
diff --git a/searchlib/src/vespa/searchlib/attribute/floatbase.h b/searchlib/src/vespa/searchlib/attribute/floatbase.h
index 09751c0b282..8db89535ebf 100644
--- a/searchlib/src/vespa/searchlib/attribute/floatbase.h
+++ b/searchlib/src/vespa/searchlib/attribute/floatbase.h
@@ -64,17 +64,16 @@ public:
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;
+ T defaultValue() const { return getConfig().isMutable() ? 0.0 : attribute::getUndefined<T>(); }
protected:
FloatingPointAttributeTemplate(const vespalib::string & name);
FloatingPointAttributeTemplate(const vespalib::string & name, const Config & c);
~FloatingPointAttributeTemplate() override;
- static T defaultValue() { return attribute::getUndefined<T>(); }
virtual bool findEnum(T v, EnumHandle & e) const = 0;
virtual void load_enum_store(LoadedVector&) {}
virtual void fillValues(LoadedVector &) {}
virtual void load_posting_lists(LoadedVector&) {}
- largeint_t getDefaultValue() const override { return static_cast<largeint_t>(-std::numeric_limits<T>::max()); }
const Change _defaultValue;
private:
bool findEnum(const char *value, EnumHandle &e) const override;
diff --git a/searchlib/src/vespa/searchlib/attribute/floatbase.hpp b/searchlib/src/vespa/searchlib/attribute/floatbase.hpp
index 93b0d521026..d3cf291849b 100644
--- a/searchlib/src/vespa/searchlib/attribute/floatbase.hpp
+++ b/searchlib/src/vespa/searchlib/attribute/floatbase.hpp
@@ -6,15 +6,6 @@
namespace search {
-namespace {
-
-template <typename T>
-double createDefaultValue(const attribute::Config & config) {
- return config.isMutable() ? 0.0 : attribute::getUndefined<T>();
-}
-
-}
-
template<typename T>
uint32_t
FloatingPointAttributeTemplate<T>::getRawValues(DocId, const multivalue::Value<T> * &) const {
@@ -35,7 +26,7 @@ FloatingPointAttributeTemplate<T>::FloatingPointAttributeTemplate(const vespalib
template<typename T>
FloatingPointAttributeTemplate<T>::FloatingPointAttributeTemplate(const vespalib::string & name, const Config & c)
: FloatingPointAttribute(name, c),
- _defaultValue(ChangeBase::UPDATE, 0, createDefaultValue<T>(c))
+ _defaultValue(ChangeBase::UPDATE, 0, defaultValue())
{
assert(c.basicType() == BasicType::fromType(T()));
}
diff --git a/searchlib/src/vespa/searchlib/attribute/integerbase.h b/searchlib/src/vespa/searchlib/attribute/integerbase.h
index c791adc8c53..50a3f314795 100644
--- a/searchlib/src/vespa/searchlib/attribute/integerbase.h
+++ b/searchlib/src/vespa/searchlib/attribute/integerbase.h
@@ -62,19 +62,18 @@ public:
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;
+ T defaultValue() const { return getConfig().isMutable() ? 0 : attribute::getUndefined<T>(); }
protected:
IntegerAttributeTemplate(const vespalib::string & name);
IntegerAttributeTemplate(const vespalib::string & name, const Config & c);
IntegerAttributeTemplate(const vespalib::string & name, const Config & c, const BasicType &realType);
~IntegerAttributeTemplate() override;
- static T defaultValue() { return attribute::getUndefined<T>(); }
virtual bool findEnum(T v, EnumHandle & e) const = 0;
virtual void load_enum_store(LoadedVector&) {}
virtual void fillValues(LoadedVector &) {}
virtual void load_posting_lists(LoadedVector&) {}
- largeint_t getDefaultValue() const override { return defaultValue(); }
- bool isUndefined(DocId doc) const override { return get(doc) == defaultValue(); }
+ bool isUndefined(DocId doc) const override { return get(doc) == attribute::getUndefined<T>(); }
const Change _defaultValue;
private:
bool findEnum(const char *value, EnumHandle &e) const override;
diff --git a/searchlib/src/vespa/searchlib/attribute/integerbase.hpp b/searchlib/src/vespa/searchlib/attribute/integerbase.hpp
index 2b16a541a54..5efca03e435 100644
--- a/searchlib/src/vespa/searchlib/attribute/integerbase.hpp
+++ b/searchlib/src/vespa/searchlib/attribute/integerbase.hpp
@@ -8,15 +8,6 @@ namespace search {
using largeint_t = attribute::IAttributeVector::largeint_t;
-namespace {
-
-template <typename T>
-largeint_t createDefaultValue(const attribute::Config & config) {
- return config.isMutable() ? 0 : attribute::getUndefined<T>();
-}
-
-}
-
template<typename T>
IntegerAttributeTemplate<T>::IntegerAttributeTemplate(const vespalib::string & name)
: IntegerAttributeTemplate(name, BasicType::fromType(T()))
@@ -25,7 +16,7 @@ IntegerAttributeTemplate<T>::IntegerAttributeTemplate(const vespalib::string & n
template<typename T>
IntegerAttributeTemplate<T>::IntegerAttributeTemplate(const vespalib::string & name, const Config & c)
: IntegerAttribute(name, c),
- _defaultValue(ChangeBase::UPDATE, 0, createDefaultValue<T>(c))
+ _defaultValue(ChangeBase::UPDATE, 0, defaultValue())
{
assert(c.basicType() == BasicType::fromType(T()));
}
diff --git a/searchlib/src/vespa/searchlib/attribute/not_implemented_attribute.cpp b/searchlib/src/vespa/searchlib/attribute/not_implemented_attribute.cpp
index f0043818367..521b6f8c825 100644
--- a/searchlib/src/vespa/searchlib/attribute/not_implemented_attribute.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/not_implemented_attribute.cpp
@@ -129,12 +129,6 @@ NotImplementedAttribute::clearDoc(DocId) {
return 0;
}
-int64_t
-NotImplementedAttribute::getDefaultValue() const {
- notImplemented();
- return 0;
-}
-
uint32_t
NotImplementedAttribute::getEnum(DocId) const {
notImplemented();
diff --git a/searchlib/src/vespa/searchlib/attribute/not_implemented_attribute.h b/searchlib/src/vespa/searchlib/attribute/not_implemented_attribute.h
index 995efc9a2f7..f3af6cdd1ae 100644
--- a/searchlib/src/vespa/searchlib/attribute/not_implemented_attribute.h
+++ b/searchlib/src/vespa/searchlib/attribute/not_implemented_attribute.h
@@ -31,7 +31,6 @@ struct NotImplementedAttribute : AttributeVector {
long onSerializeForAscendingSort(DocId, void *, long, const common::BlobConverter *) const override;
long onSerializeForDescendingSort(DocId, void *, long, const common::BlobConverter *) const override;
uint32_t clearDoc(DocId) override;
- int64_t getDefaultValue() const override;
uint32_t getEnum(DocId) const override;
bool addDoc(DocId &) override;
void onAddDocs(DocId lidLimit) override;
diff --git a/searchlib/src/vespa/searchlib/attribute/singlenumericattribute.hpp b/searchlib/src/vespa/searchlib/attribute/singlenumericattribute.hpp
index 4a2bc68e0bc..89c2a21231b 100644
--- a/searchlib/src/vespa/searchlib/attribute/singlenumericattribute.hpp
+++ b/searchlib/src/vespa/searchlib/attribute/singlenumericattribute.hpp
@@ -78,7 +78,7 @@ template <typename B>
bool
SingleValueNumericAttribute<B>::addDoc(DocId & doc) {
bool incGen = _data.isFull();
- _data.push_back(attribute::getUndefined<T>());
+ _data.push_back(B::defaultValue());
std::atomic_thread_fence(std::memory_order_release);
B::incNumDocs();
doc = B::getNumDocs() - 1;
diff --git a/searchlib/src/vespa/searchlib/attribute/stringbase.h b/searchlib/src/vespa/searchlib/attribute/stringbase.h
index d5a407d412e..3d3a2bc0b3d 100644
--- a/searchlib/src/vespa/searchlib/attribute/stringbase.h
+++ b/searchlib/src/vespa/searchlib/attribute/stringbase.h
@@ -78,7 +78,6 @@ public:
uint32_t get(DocId doc, WeightedInt * v, uint32_t sz) const override;
uint32_t get(DocId doc, WeightedFloat * v, uint32_t sz) const override;
uint32_t clearDoc(DocId doc) override;
- largeint_t getDefaultValue() const override { return 0; }
static size_t countZero(const char * bt, size_t sz);
static void generateOffsets(const char * bt, size_t sz, OffsetVector & offsets);
virtual const char * getFromEnum(EnumHandle e) const = 0;