aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeir Storli <geirst@oath.com>2018-04-19 07:43:05 +0000
committerGeir Storli <geirst@oath.com>2018-04-19 08:20:27 +0000
commitf185736daff2d538a3a93aafe3f963768301d751 (patch)
treefbe7a94c77f070b9462f9fa7918d28850f892018
parent12b9a15869be76e062ed17307fb91fe8eaac4b48 (diff)
Change ImportedAttributeVector to no longer implement IAttributeVector API.
All read access happens through short lived ImportedAttributeVectorReadGuard.
-rw-r--r--searchcore/src/vespa/searchcore/proton/attribute/imported_attributes_context.h2
-rw-r--r--searchlib/src/tests/attribute/imported_attribute_vector/imported_attribute_vector_test.cpp51
-rw-r--r--searchlib/src/tests/attribute/imported_search_context/imported_search_context_test.cpp6
-rw-r--r--searchlib/src/tests/features/imported_dot_product/imported_dot_product_test.cpp7
-rw-r--r--searchlib/src/vespa/searchlib/attribute/imported_attribute_vector.cpp128
-rw-r--r--searchlib/src/vespa/searchlib/attribute/imported_attribute_vector.h48
-rw-r--r--searchlib/src/vespa/searchlib/attribute/imported_attribute_vector_read_guard.cpp100
-rw-r--r--searchlib/src/vespa/searchlib/attribute/imported_attribute_vector_read_guard.h36
-rw-r--r--searchlib/src/vespa/searchlib/features/dotproductfeature.cpp4
-rw-r--r--searchlib/src/vespa/searchlib/features/internal_max_reduce_prod_join_feature.cpp4
-rw-r--r--searchlib/src/vespa/searchlib/tensor/imported_tensor_attribute_vector.cpp5
-rw-r--r--searchlib/src/vespa/searchlib/tensor/imported_tensor_attribute_vector.h2
-rw-r--r--searchlib/src/vespa/searchlib/tensor/imported_tensor_attribute_vector_read_guard.cpp13
-rw-r--r--searchlib/src/vespa/searchlib/tensor/imported_tensor_attribute_vector_read_guard.h10
-rw-r--r--searchlib/src/vespa/searchlib/test/imported_attribute_fixture.h6
15 files changed, 160 insertions, 262 deletions
diff --git a/searchcore/src/vespa/searchcore/proton/attribute/imported_attributes_context.h b/searchcore/src/vespa/searchcore/proton/attribute/imported_attributes_context.h
index 5daed203446..a0d785d8cc7 100644
--- a/searchcore/src/vespa/searchcore/proton/attribute/imported_attributes_context.h
+++ b/searchcore/src/vespa/searchcore/proton/attribute/imported_attributes_context.h
@@ -29,7 +29,7 @@ private:
using IAttributeVector = search::attribute::IAttributeVector;
using ImportedAttributeVector = search::attribute::ImportedAttributeVector;
- using AttributeCache = std::unordered_map<vespalib::string, std::unique_ptr<ImportedAttributeVector>, vespalib::hash<vespalib::string>>;
+ using AttributeCache = std::unordered_map<vespalib::string, std::unique_ptr<IAttributeVector>, vespalib::hash<vespalib::string>>;
using LockGuard = std::lock_guard<std::mutex>;
const ImportedAttributesRepo &_repo;
diff --git a/searchlib/src/tests/attribute/imported_attribute_vector/imported_attribute_vector_test.cpp b/searchlib/src/tests/attribute/imported_attribute_vector/imported_attribute_vector_test.cpp
index 114d0492c1a..4493808bbcf 100644
--- a/searchlib/src/tests/attribute/imported_attribute_vector/imported_attribute_vector_test.cpp
+++ b/searchlib/src/tests/attribute/imported_attribute_vector/imported_attribute_vector_test.cpp
@@ -9,19 +9,20 @@
#include <vespa/eval/tensor/tensor.h>
#include <vespa/eval/tensor/default_tensor.h>
+using search::attribute::IAttributeVector;
+using search::tensor::ITensorAttribute;
+using search::tensor::TensorAttribute;
using vespalib::eval::ValueType;
+using vespalib::tensor::DenseTensorCells;
using vespalib::tensor::Tensor;
using vespalib::tensor::TensorCells;
-using vespalib::tensor::DenseTensorCells;
using vespalib::tensor::TensorDimensions;
using vespalib::tensor::TensorFactory;
-using search::tensor::TensorAttribute;
-using search::tensor::ITensorAttribute;
namespace search {
namespace attribute {
-
+// TODO: remove template argument (read guard is always used now)
template <bool useReadGuard = false>
struct FixtureBase : public ImportedAttributeFixture
{
@@ -30,13 +31,6 @@ struct FixtureBase : public ImportedAttributeFixture
{
}
- std::shared_ptr<ImportedAttributeVector> get_imported_attr() {
- if (useReadGuard) {
- return imported_attr->makeReadGuard(false);
- } else {
- return imported_attr;
- }
- }
};
using Fixture = FixtureBase<false>;
@@ -52,28 +46,29 @@ TEST_F("Accessors return expected attributes", Fixture) {
TEST_F("getName() is equal to name given during construction", Fixture) {
auto attr = f.create_attribute_vector_from_members("coolvector");
EXPECT_EQUAL("coolvector", attr->getName());
+ EXPECT_EQUAL("coolvector", attr->makeReadGuard(false)->getName());
}
TEST_F("getNumDocs() returns number of documents in reference attribute vector", Fixture) {
add_n_docs_with_undefined_values(*f.reference_attr, 42);
- EXPECT_EQUAL(42u, f.imported_attr->getNumDocs());
+ EXPECT_EQUAL(42u, f.get_imported_attr()->getNumDocs());
}
TEST_F("hasEnum() is false for non-enum target attribute vector", Fixture) {
- EXPECT_FALSE(f.imported_attr->hasEnum());
+ EXPECT_FALSE(f.get_imported_attr()->hasEnum());
}
TEST_F("Collection type is inherited from target attribute", Fixture) {
- EXPECT_EQUAL(CollectionType::SINGLE, f.imported_attr->getCollectionType());
+ EXPECT_EQUAL(CollectionType::SINGLE, f.get_imported_attr()->getCollectionType());
f.reset_with_new_target_attr(create_array_attribute<IntegerAttribute>(BasicType::INT32));
- EXPECT_EQUAL(CollectionType::ARRAY, f.imported_attr->getCollectionType());
+ EXPECT_EQUAL(CollectionType::ARRAY, f.get_imported_attr()->getCollectionType());
}
TEST_F("getBasicType() returns target vector basic type", Fixture) {
f.reset_with_new_target_attr(create_single_attribute<IntegerAttribute>(BasicType::INT64));
- EXPECT_EQUAL(BasicType::INT64, f.imported_attr->getBasicType());
+ EXPECT_EQUAL(BasicType::INT64, f.get_imported_attr()->getBasicType());
f.reset_with_new_target_attr(create_single_attribute<FloatingPointAttribute>(BasicType::DOUBLE));
- EXPECT_EQUAL(BasicType::DOUBLE, f.imported_attr->getBasicType());
+ EXPECT_EQUAL(BasicType::DOUBLE, f.get_imported_attr()->getBasicType());
}
TEST_F("makeReadGuard(false) acquires guards on both target and reference attributes", Fixture) {
@@ -171,16 +166,16 @@ TEST("getValueCount() is 0 for non-mapped single value attribute") {
}
TEST_F("getMaxValueCount() is 1 for single value attribute vectors", Fixture) {
- EXPECT_EQUAL(1u, f.imported_attr->getMaxValueCount());
+ EXPECT_EQUAL(1u, f.get_imported_attr()->getMaxValueCount());
}
TEST_F("getFixedWidth() is inherited from target attribute vector", Fixture) {
EXPECT_EQUAL(f.target_attr->getFixedWidth(),
- f.imported_attr->getFixedWidth());
+ f.get_imported_attr()->getFixedWidth());
}
TEST_F("asDocumentWeightAttribute() returns nullptr", Fixture) {
- EXPECT_TRUE(f.imported_attr->asDocumentWeightAttribute() == nullptr);
+ EXPECT_TRUE(f.get_imported_attr()->asDocumentWeightAttribute() == nullptr);
}
TEST_F("Multi-valued integer attribute values can be retrieved via reference", Fixture) {
@@ -230,8 +225,8 @@ TEST_F("Singled-valued floating point attribute values can be retrieved via refe
{{DocId(2), dummy_gid(3), DocId(3), 10.5f},
{DocId(4), dummy_gid(8), DocId(8), 3.14f}});
- EXPECT_EQUAL(10.5f, f.imported_attr->getFloat(DocId(2)));
- EXPECT_EQUAL(3.14f, f.imported_attr->getFloat(DocId(4)));
+ EXPECT_EQUAL(10.5f, f.get_imported_attr()->getFloat(DocId(2)));
+ EXPECT_EQUAL(3.14f, f.get_imported_attr()->getFloat(DocId(4)));
}
TEST_F("Multi-valued floating point attribute values can be retrieved via reference", Fixture) {
@@ -309,7 +304,7 @@ TEST_F("findEnum() returns target vector enum via reference", SingleStringAttrFi
EnumHandle expected_handle{};
ASSERT_TRUE(f.target_attr->findEnum("foo", expected_handle));
EnumHandle actual_handle{};
- ASSERT_TRUE(f.imported_attr->findEnum("foo", actual_handle));
+ ASSERT_TRUE(f.get_imported_attr()->findEnum("foo", actual_handle));
EXPECT_EQUAL(expected_handle, actual_handle);
}
@@ -328,17 +323,17 @@ TEST_F("Single-value getStringFromEnum() returns string enum is mapped to", Sing
}
TEST_F("hasEnum() is true for enum target attribute vector", SingleStringAttrFixture) {
- EXPECT_TRUE(f.imported_attr->hasEnum());
+ EXPECT_TRUE(f.get_imported_attr()->hasEnum());
}
TEST_F("createSearchContext() returns an imported search context", SingleStringAttrFixture) {
- auto ctx = f.imported_attr->createSearchContext(word_term("bar"), SearchContextParams());
+ auto ctx = f.get_imported_attr()->createSearchContext(word_term("bar"), SearchContextParams());
ASSERT_TRUE(ctx.get() != nullptr);
fef::TermFieldMatchData match;
// Iterator specifics are tested in imported_search_context_test, so just make sure
// we get the expected iterator functionality. In this case, a non-strict iterator.
auto iter = ctx->createIterator(&match, false);
- iter->initRange(1, f.imported_attr->getNumDocs());
+ iter->initRange(1, f.get_imported_attr()->getNumDocs());
EXPECT_FALSE(iter->seek(DocId(1)));
EXPECT_FALSE(iter->seek(DocId(2)));
EXPECT_FALSE(iter->seek(DocId(3)));
@@ -386,11 +381,11 @@ TEST_F("Multi-value getStringFromEnum() returns string enum is mapped to", Multi
}
TEST_F("getValueCount() is equal to stored values for mapped multi value attribute", MultiStringAttrFixture) {
- EXPECT_EQUAL(f.doc7_values.size(), f.imported_attr->getValueCount(DocId(4)));
+ EXPECT_EQUAL(f.doc7_values.size(), f.get_imported_attr()->getValueCount(DocId(4)));
}
TEST_F("getMaxValueCount() is greater than 1 for multi value attribute vectors", MultiStringAttrFixture) {
- EXPECT_GREATER(f.imported_attr->getMaxValueCount(), 1u);
+ EXPECT_GREATER(f.get_imported_attr()->getMaxValueCount(), 1u);
}
struct WeightedMultiStringAttrFixture : Fixture {
diff --git a/searchlib/src/tests/attribute/imported_search_context/imported_search_context_test.cpp b/searchlib/src/tests/attribute/imported_search_context/imported_search_context_test.cpp
index 4ab0ed878cf..2f302e50470 100644
--- a/searchlib/src/tests/attribute/imported_search_context/imported_search_context_test.cpp
+++ b/searchlib/src/tests/attribute/imported_search_context/imported_search_context_test.cpp
@@ -45,7 +45,7 @@ struct Fixture : ImportedAttributeFixture {
}
void assertSearch(const std::vector<uint32_t> &expDocIds, SearchIterator &iter) {
- EXPECT_EQUAL(SimpleResult(expDocIds), SimpleResult().searchStrict(iter, imported_attr->getNumDocs()));
+ EXPECT_EQUAL(SimpleResult(expDocIds), SimpleResult().searchStrict(iter, get_imported_attr()->getNumDocs()));
}
};
@@ -376,7 +376,7 @@ makeSearchCacheEntry(const std::vector<uint32_t> docIds, uint32_t docIdLimit)
TEST_F("Bit vector from search cache is used if found", SearchCacheFixture)
{
f.imported_attr->getSearchCache()->insert("5678",
- makeSearchCacheEntry({2, 6}, f.imported_attr->getNumDocs()));
+ makeSearchCacheEntry({2, 6}, f.get_imported_attr()->getNumDocs()));
auto ctx = f.create_context(word_term("5678"));
ctx->fetchPostings(true);
TermFieldMatchData match;
@@ -404,7 +404,7 @@ TEST_F("Entry is inserted into search cache if bit vector posting list is used",
EXPECT_EQUAL(1u, f.imported_attr->getSearchCache()->size());
auto cacheEntry = f.imported_attr->getSearchCache()->find("5678");
- EXPECT_EQUAL(cacheEntry->docIdLimit, f.imported_attr->getNumDocs());
+ EXPECT_EQUAL(cacheEntry->docIdLimit, f.get_imported_attr()->getNumDocs());
TEST_DO(assertBitVector({3, 5}, *cacheEntry->bitVector));
EXPECT_EQUAL(1u, f.document_meta_store->get_read_guard_cnt);
}
diff --git a/searchlib/src/tests/features/imported_dot_product/imported_dot_product_test.cpp b/searchlib/src/tests/features/imported_dot_product/imported_dot_product_test.cpp
index a42577d8b51..13225836bd1 100644
--- a/searchlib/src/tests/features/imported_dot_product/imported_dot_product_test.cpp
+++ b/searchlib/src/tests/features/imported_dot_product/imported_dot_product_test.cpp
@@ -45,9 +45,10 @@ struct FixtureBase : ImportedAttributeFixture {
if (pre_parsed) {
feature.getQueryEnv().getObjectStore().add("dotProduct.vector.object", std::move(pre_parsed));
}
- feature.getIndexEnv().getAttributeMap().add(imported_attr);
+ std::shared_ptr<IAttributeVector> readable_imported_attr = imported_attr->makeReadGuard(false);
+ feature.getIndexEnv().getAttributeMap().add(readable_imported_attr);
schema::CollectionType collection_type(
- (imported_attr->getCollectionType() == attribute::CollectionType::ARRAY)
+ (readable_imported_attr->getCollectionType() == attribute::CollectionType::ARRAY)
? schema::CollectionType::ARRAY : schema::CollectionType::WEIGHTEDSET);
feature.getIndexEnv().getBuilder().addField(
FieldType::ATTRIBUTE, collection_type, imported_attr->getName());
@@ -108,7 +109,7 @@ struct ArrayFixture : FixtureBase {
ParameterList params({Parameter(ParameterType::ATTRIBUTE, imported_attr->getName()),
Parameter(ParameterType::STRING, "fancyvector")});
- feature.getIndexEnv().getAttributeMap().add(imported_attr);
+ feature.getIndexEnv().getAttributeMap().add(imported_attr->makeReadGuard(false));
feature.getIndexEnv().getBuilder().addField(
FieldType::ATTRIBUTE, schema::CollectionType::ARRAY, imported_attr->getName());
diff --git a/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector.cpp b/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector.cpp
index a085e21d6ae..dd089446065 100644
--- a/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector.cpp
@@ -3,12 +3,9 @@
#include "imported_attribute_vector.h"
#include "imported_attribute_vector_read_guard.h"
#include "imported_search_context.h"
-#include "bitvector_search_cache.h"
-#include <vespa/searchlib/query/queryterm.h>
#include <vespa/vespalib/util/exceptions.h>
-namespace search {
-namespace attribute {
+namespace search::attribute {
ImportedAttributeVector::ImportedAttributeVector(
vespalib::stringref name,
@@ -41,112 +38,10 @@ ImportedAttributeVector::ImportedAttributeVector(vespalib::stringref name,
ImportedAttributeVector::~ImportedAttributeVector() {
}
-std::unique_ptr<ImportedAttributeVector>
+std::unique_ptr<IAttributeVector>
ImportedAttributeVector::makeReadGuard(bool stableEnumGuard) const
{
- return std::make_unique<ImportedAttributeVectorReadGuard>
- (getName(), getReferenceAttribute(), getTargetAttribute(), getDocumentMetaStore(), getSearchCache(), stableEnumGuard);
-}
-
-const vespalib::string& search::attribute::ImportedAttributeVector::getName() const {
- return _name;
-}
-
-uint32_t ImportedAttributeVector::getNumDocs() const {
- return _reference_attribute->getNumDocs();
-}
-
-uint32_t ImportedAttributeVector::getValueCount(uint32_t doc) const {
- return _target_attribute->getValueCount(_reference_attribute->getReferencedLid(doc));
-}
-
-uint32_t ImportedAttributeVector::getMaxValueCount() const {
- return _target_attribute->getMaxValueCount();
-}
-
-IAttributeVector::largeint_t ImportedAttributeVector::getInt(DocId doc) const {
- return _target_attribute->getInt(_reference_attribute->getReferencedLid(doc));
-}
-
-double ImportedAttributeVector::getFloat(DocId doc) const {
- return _target_attribute->getFloat(_reference_attribute->getReferencedLid(doc));
-}
-
-const char *ImportedAttributeVector::getString(DocId doc, char *buffer, size_t sz) const {
- return _target_attribute->getString(_reference_attribute->getReferencedLid(doc), buffer, sz);
-}
-
-IAttributeVector::EnumHandle ImportedAttributeVector::getEnum(DocId doc) const {
- return _target_attribute->getEnum(_reference_attribute->getReferencedLid(doc));
-}
-
-uint32_t ImportedAttributeVector::get(DocId docId, largeint_t *buffer, uint32_t sz) const {
- return _target_attribute->get(_reference_attribute->getReferencedLid(docId), buffer, sz);
-}
-
-uint32_t ImportedAttributeVector::get(DocId docId, double *buffer, uint32_t sz) const {
- return _target_attribute->get(_reference_attribute->getReferencedLid(docId), buffer, sz);
-}
-
-uint32_t ImportedAttributeVector::get(DocId docId, const char **buffer, uint32_t sz) const {
- return _target_attribute->get(_reference_attribute->getReferencedLid(docId), buffer, sz);
-}
-
-uint32_t ImportedAttributeVector::get(DocId docId, EnumHandle *buffer, uint32_t sz) const {
- return _target_attribute->get(_reference_attribute->getReferencedLid(docId), buffer, sz);
-}
-
-uint32_t ImportedAttributeVector::get(DocId docId, WeightedInt *buffer, uint32_t sz) const {
- return _target_attribute->get(_reference_attribute->getReferencedLid(docId), buffer, sz);
-}
-
-uint32_t ImportedAttributeVector::get(DocId docId, WeightedFloat *buffer, uint32_t sz) const {
- return _target_attribute->get(_reference_attribute->getReferencedLid(docId), buffer, sz);
-}
-
-uint32_t ImportedAttributeVector::get(DocId docId, WeightedString *buffer, uint32_t sz) const {
- return _target_attribute->get(_reference_attribute->getReferencedLid(docId), buffer, sz);
-}
-
-uint32_t ImportedAttributeVector::get(DocId docId, WeightedConstChar *buffer, uint32_t sz) const {
- return _target_attribute->get(_reference_attribute->getReferencedLid(docId), buffer, sz);
-}
-
-uint32_t ImportedAttributeVector::get(DocId docId, WeightedEnum *buffer, uint32_t sz) const {
- return _target_attribute->get(_reference_attribute->getReferencedLid(docId), buffer, sz);
-}
-
-bool ImportedAttributeVector::findEnum(const char *value, EnumHandle &e) const {
- return _target_attribute->findEnum(value, e);
-}
-
-const char * ImportedAttributeVector::getStringFromEnum(EnumHandle e) const {
- return _target_attribute->getStringFromEnum(e);
-}
-
-std::unique_ptr<ISearchContext> ImportedAttributeVector::createSearchContext(std::unique_ptr<QueryTermSimple> term,
- const SearchContextParams &params) const {
- return std::make_unique<ImportedSearchContext>(std::move(term), params, *this);
-}
-
-const IDocumentWeightAttribute *ImportedAttributeVector::asDocumentWeightAttribute() const {
- return nullptr;
-}
-
-BasicType::Type ImportedAttributeVector::getBasicType() const {
- return _target_attribute->getBasicType();
-}
-
-size_t ImportedAttributeVector::getFixedWidth() const {
- return _target_attribute->getFixedWidth();
-}
-
-CollectionType::Type ImportedAttributeVector::getCollectionType() const {
- return _target_attribute->getCollectionType();
-}
-
-bool ImportedAttributeVector::hasEnum() const {
- return _target_attribute->hasEnum();
+ return std::make_unique<ImportedAttributeVectorReadGuard>(*this, stableEnumGuard);
}
void ImportedAttributeVector::clearSearchCache() {
@@ -155,21 +50,4 @@ void ImportedAttributeVector::clearSearchCache() {
}
}
-long ImportedAttributeVector::onSerializeForAscendingSort(DocId doc,
- void *serTo,
- long available,
- const common::BlobConverter *bc) const {
- return _target_attribute->serializeForAscendingSort(
- _reference_attribute->getReferencedLid(doc), serTo, available, bc);
-}
-
-long ImportedAttributeVector::onSerializeForDescendingSort(DocId doc,
- void *serTo,
- long available,
- const common::BlobConverter *bc) const {
- return _target_attribute->serializeForDescendingSort(
- _reference_attribute->getReferencedLid(doc), serTo, available, bc);
-}
-
-}
}
diff --git a/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector.h b/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector.h
index 324ce4ec12b..731b0bbbd19 100644
--- a/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector.h
+++ b/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector.h
@@ -3,7 +3,6 @@
#pragma once
#include "reference_attribute.h"
-#include <vespa/searchcommon/attribute/iattributevector.h>
#include <vespa/vespalib/stllike/string.h>
#include <memory>
@@ -27,7 +26,7 @@ class BitVectorSearchCache;
* Any accessor on the imported attribute for a local LID yields the same result as
* if the same accessor were invoked with the target LID on the target attribute vector.
*/
-class ImportedAttributeVector : public IAttributeVector {
+class ImportedAttributeVector {
public:
using SP = std::shared_ptr<ImportedAttributeVector>;
ImportedAttributeVector(vespalib::stringref name,
@@ -40,34 +39,7 @@ public:
std::shared_ptr<AttributeVector> target_attribute,
std::shared_ptr<IDocumentMetaStoreContext> document_meta_store,
std::shared_ptr<BitVectorSearchCache> search_cache);
- ~ImportedAttributeVector();
-
- const vespalib::string & getName() const override;
- uint32_t getNumDocs() const override;
- uint32_t getValueCount(uint32_t doc) const override;
- uint32_t getMaxValueCount() const override;
- largeint_t getInt(DocId doc) const override;
- double getFloat(DocId doc) const override;
- const char * getString(DocId doc, char * buffer, size_t sz) const override;
- EnumHandle getEnum(DocId doc) const override;
- uint32_t get(DocId docId, largeint_t * buffer, uint32_t sz) const override;
- uint32_t get(DocId docId, double * buffer, uint32_t sz) const override;
- uint32_t get(DocId docId, const char ** buffer, uint32_t sz) const override;
- uint32_t get(DocId docId, EnumHandle * buffer, uint32_t sz) const override;
- uint32_t get(DocId docId, WeightedInt * buffer, uint32_t sz) const override;
- uint32_t get(DocId docId, WeightedFloat * buffer, uint32_t sz) const override;
- uint32_t get(DocId docId, WeightedString * buffer, uint32_t sz) const override;
- uint32_t get(DocId docId, WeightedConstChar * buffer, uint32_t sz) const override;
- uint32_t get(DocId docId, WeightedEnum * buffer, uint32_t sz) const override;
- bool findEnum(const char * value, EnumHandle & e) const override;
- const char * getStringFromEnum(EnumHandle e) const override;
- std::unique_ptr<ISearchContext> createSearchContext(std::unique_ptr<QueryTermSimple> term,
- const SearchContextParams &params) const override;
- const IDocumentWeightAttribute *asDocumentWeightAttribute() const override;
- BasicType::Type getBasicType() const override;
- size_t getFixedWidth() const override;
- CollectionType::Type getCollectionType() const override;
- bool hasEnum() const override;
+ virtual ~ImportedAttributeVector();
const std::shared_ptr<ReferenceAttribute>& getReferenceAttribute() const noexcept {
return _reference_attribute;
@@ -82,18 +54,16 @@ public:
return _search_cache;
}
void clearSearchCache();
+ const vespalib::string &getName() const {
+ return _name;
+ }
/*
* Create an imported attribute with a snapshot of lid to lid mapping.
*/
- virtual std::unique_ptr<ImportedAttributeVector> makeReadGuard(bool stableEnumGuard) const;
-protected:
- 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;
-
+ virtual std::unique_ptr<IAttributeVector> makeReadGuard(bool stableEnumGuard) const;
+protected:
vespalib::string _name;
std::shared_ptr<ReferenceAttribute> _reference_attribute;
std::shared_ptr<AttributeVector> _target_attribute;
@@ -101,5 +71,5 @@ protected:
std::shared_ptr<BitVectorSearchCache> _search_cache;
};
-} // attribute
-} // search
+}
+}
diff --git a/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector_read_guard.cpp b/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector_read_guard.cpp
index c954c34aee8..da5287b6068 100644
--- a/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector_read_guard.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector_read_guard.cpp
@@ -1,101 +1,145 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "imported_attribute_vector_read_guard.h"
+#include "imported_search_context.h"
#include <vespa/searchlib/common/i_gid_to_lid_mapper.h>
#include <vespa/searchlib/common/i_gid_to_lid_mapper_factory.h>
+#include <vespa/searchlib/query/queryterm.h>
namespace search {
namespace attribute {
ImportedAttributeVectorReadGuard::ImportedAttributeVectorReadGuard(
- vespalib::stringref name,
- std::shared_ptr<ReferenceAttribute> reference_attribute,
- std::shared_ptr<AttributeVector> target_attribute,
- std::shared_ptr<IDocumentMetaStoreContext> document_meta_store,
- std::shared_ptr<BitVectorSearchCache> search_cache,
+ const ImportedAttributeVector &imported_attribute,
bool stableEnumGuard)
- : ImportedAttributeVector(name, std::move(reference_attribute), std::move(target_attribute),
- std::move(document_meta_store), std::move(search_cache)),
+ : _imported_attribute(imported_attribute),
_referencedLids(),
- _reference_attribute_guard(_reference_attribute),
- _target_attribute_guard(stableEnumGuard ? std::shared_ptr<AttributeVector>() : _target_attribute),
- _target_attribute_enum_guard(stableEnumGuard ? _target_attribute : std::shared_ptr<AttributeVector>()),
- _mapper(_reference_attribute->getGidToLidMapperFactory()->getMapper())
+ _reference_attribute_guard(imported_attribute.getReferenceAttribute()),
+ _target_attribute_guard(stableEnumGuard ? std::shared_ptr<AttributeVector>() : imported_attribute.getTargetAttribute()),
+ _target_attribute_enum_guard(stableEnumGuard ? imported_attribute.getTargetAttribute(): std::shared_ptr<AttributeVector>()),
+ _reference_attribute(*imported_attribute.getReferenceAttribute()),
+ _target_attribute(*imported_attribute.getTargetAttribute()),
+ _mapper(_reference_attribute.getGidToLidMapperFactory()->getMapper())
{
- _referencedLids = _reference_attribute->getReferencedLids();
+ _referencedLids = _reference_attribute.getReferencedLids();
}
ImportedAttributeVectorReadGuard::~ImportedAttributeVectorReadGuard() {
}
+const vespalib::string& ImportedAttributeVectorReadGuard::getName() const {
+ return _imported_attribute.getName();
+}
+
+uint32_t ImportedAttributeVectorReadGuard::getNumDocs() const {
+ return _reference_attribute.getNumDocs();
+}
+
uint32_t ImportedAttributeVectorReadGuard::getValueCount(uint32_t doc) const {
- return _target_attribute->getValueCount(getReferencedLid(doc));
+ return _target_attribute.getValueCount(getReferencedLid(doc));
+}
+
+uint32_t ImportedAttributeVectorReadGuard::getMaxValueCount() const {
+ return _target_attribute.getMaxValueCount();
}
IAttributeVector::largeint_t ImportedAttributeVectorReadGuard::getInt(DocId doc) const {
- return _target_attribute->getInt(getReferencedLid(doc));
+ return _target_attribute.getInt(getReferencedLid(doc));
}
double ImportedAttributeVectorReadGuard::getFloat(DocId doc) const {
- return _target_attribute->getFloat(getReferencedLid(doc));
+ return _target_attribute.getFloat(getReferencedLid(doc));
}
const char *ImportedAttributeVectorReadGuard::getString(DocId doc, char *buffer, size_t sz) const {
- return _target_attribute->getString(getReferencedLid(doc), buffer, sz);
+ return _target_attribute.getString(getReferencedLid(doc), buffer, sz);
}
IAttributeVector::EnumHandle ImportedAttributeVectorReadGuard::getEnum(DocId doc) const {
- return _target_attribute->getEnum(getReferencedLid(doc));
+ return _target_attribute.getEnum(getReferencedLid(doc));
}
uint32_t ImportedAttributeVectorReadGuard::get(DocId docId, largeint_t *buffer, uint32_t sz) const {
- return _target_attribute->get(getReferencedLid(docId), buffer, sz);
+ return _target_attribute.get(getReferencedLid(docId), buffer, sz);
}
uint32_t ImportedAttributeVectorReadGuard::get(DocId docId, double *buffer, uint32_t sz) const {
- return _target_attribute->get(getReferencedLid(docId), buffer, sz);
+ return _target_attribute.get(getReferencedLid(docId), buffer, sz);
}
uint32_t ImportedAttributeVectorReadGuard::get(DocId docId, const char **buffer, uint32_t sz) const {
- return _target_attribute->get(getReferencedLid(docId), buffer, sz);
+ return _target_attribute.get(getReferencedLid(docId), buffer, sz);
}
uint32_t ImportedAttributeVectorReadGuard::get(DocId docId, EnumHandle *buffer, uint32_t sz) const {
- return _target_attribute->get(getReferencedLid(docId), buffer, sz);
+ return _target_attribute.get(getReferencedLid(docId), buffer, sz);
}
uint32_t ImportedAttributeVectorReadGuard::get(DocId docId, WeightedInt *buffer, uint32_t sz) const {
- return _target_attribute->get(getReferencedLid(docId), buffer, sz);
+ return _target_attribute.get(getReferencedLid(docId), buffer, sz);
}
uint32_t ImportedAttributeVectorReadGuard::get(DocId docId, WeightedFloat *buffer, uint32_t sz) const {
- return _target_attribute->get(getReferencedLid(docId), buffer, sz);
+ return _target_attribute.get(getReferencedLid(docId), buffer, sz);
}
uint32_t ImportedAttributeVectorReadGuard::get(DocId docId, WeightedString *buffer, uint32_t sz) const {
- return _target_attribute->get(getReferencedLid(docId), buffer, sz);
+ return _target_attribute.get(getReferencedLid(docId), buffer, sz);
}
uint32_t ImportedAttributeVectorReadGuard::get(DocId docId, WeightedConstChar *buffer, uint32_t sz) const {
- return _target_attribute->get(getReferencedLid(docId), buffer, sz);
+ return _target_attribute.get(getReferencedLid(docId), buffer, sz);
}
uint32_t ImportedAttributeVectorReadGuard::get(DocId docId, WeightedEnum *buffer, uint32_t sz) const {
- return _target_attribute->get(getReferencedLid(docId), buffer, sz);
+ return _target_attribute.get(getReferencedLid(docId), buffer, sz);
+}
+
+bool ImportedAttributeVectorReadGuard::findEnum(const char *value, EnumHandle &e) const {
+ return _target_attribute.findEnum(value, e);
+}
+
+const char * ImportedAttributeVectorReadGuard::getStringFromEnum(EnumHandle e) const {
+ return _target_attribute.getStringFromEnum(e);
+}
+
+std::unique_ptr<ISearchContext> ImportedAttributeVectorReadGuard::createSearchContext(std::unique_ptr<QueryTermSimple> term,
+ const SearchContextParams &params) const {
+ return std::make_unique<ImportedSearchContext>(std::move(term), params, _imported_attribute);
+}
+
+const IDocumentWeightAttribute *ImportedAttributeVectorReadGuard::asDocumentWeightAttribute() const {
+ return nullptr;
+}
+
+BasicType::Type ImportedAttributeVectorReadGuard::getBasicType() const {
+ return _target_attribute.getBasicType();
+}
+
+size_t ImportedAttributeVectorReadGuard::getFixedWidth() const {
+ return _target_attribute.getFixedWidth();
+}
+
+CollectionType::Type ImportedAttributeVectorReadGuard::getCollectionType() const {
+ return _target_attribute.getCollectionType();
+}
+
+bool ImportedAttributeVectorReadGuard::hasEnum() const {
+ return _target_attribute.hasEnum();
}
long ImportedAttributeVectorReadGuard::onSerializeForAscendingSort(DocId doc,
void *serTo,
long available,
const common::BlobConverter *bc) const {
- return _target_attribute->serializeForAscendingSort(getReferencedLid(doc), serTo, available, bc);
+ return _target_attribute.serializeForAscendingSort(getReferencedLid(doc), serTo, available, bc);
}
long ImportedAttributeVectorReadGuard::onSerializeForDescendingSort(DocId doc,
void *serTo,
long available,
const common::BlobConverter *bc) const {
- return _target_attribute->serializeForDescendingSort(getReferencedLid(doc), serTo, available, bc);
+ return _target_attribute.serializeForDescendingSort(getReferencedLid(doc), serTo, available, bc);
}
}
diff --git a/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector_read_guard.h b/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector_read_guard.h
index a0c24e3b8eb..ad0d55cf29e 100644
--- a/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector_read_guard.h
+++ b/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector_read_guard.h
@@ -4,6 +4,7 @@
#include "imported_attribute_vector.h"
#include "attributeguard.h"
+#include <vespa/searchcommon/attribute/iattributevector.h>
namespace search { class IGidToLidMapper; }
@@ -17,14 +18,18 @@ class BitVectorSearchCache;
* Extra information for direct lid to referenced lid mapping with
* boundary check is setup during construction.
*/
-class ImportedAttributeVectorReadGuard : public ImportedAttributeVector
+class ImportedAttributeVectorReadGuard : public IAttributeVector
{
+private:
using ReferencedLids = vespalib::ConstArrayRef<uint32_t>;
- ReferencedLids _referencedLids;
- AttributeGuard _reference_attribute_guard;
- AttributeGuard _target_attribute_guard;
- AttributeEnumGuard _target_attribute_enum_guard;
- std::unique_ptr<IGidToLidMapper> _mapper;
+ const ImportedAttributeVector &_imported_attribute;
+ ReferencedLids _referencedLids;
+ AttributeGuard _reference_attribute_guard;
+ AttributeGuard _target_attribute_guard;
+ AttributeEnumGuard _target_attribute_enum_guard;
+ const ReferenceAttribute &_reference_attribute;
+ const AttributeVector &_target_attribute;
+ std::unique_ptr<IGidToLidMapper> _mapper;
protected:
uint32_t getReferencedLid(uint32_t lid) const {
@@ -32,15 +37,14 @@ protected:
}
public:
- ImportedAttributeVectorReadGuard(vespalib::stringref name,
- std::shared_ptr<ReferenceAttribute> reference_attribute,
- std::shared_ptr<AttributeVector> target_attribute,
- std::shared_ptr<IDocumentMetaStoreContext> document_meta_store,
- std::shared_ptr<BitVectorSearchCache> search_cache,
+ ImportedAttributeVectorReadGuard(const ImportedAttributeVector &imported_attribute,
bool stableEnumGuard);
~ImportedAttributeVectorReadGuard();
+ virtual const vespalib::string &getName() const override;
+ virtual uint32_t getNumDocs() const override;
virtual uint32_t getValueCount(uint32_t doc) const override;
+ virtual uint32_t getMaxValueCount() const override;
virtual largeint_t getInt(DocId doc) const override;
virtual double getFloat(DocId doc) const override;
virtual const char *getString(DocId doc, char *buffer, size_t sz) const override;
@@ -54,6 +58,16 @@ public:
virtual uint32_t get(DocId docId, WeightedString *buffer, uint32_t sz) const override;
virtual uint32_t get(DocId docId, WeightedConstChar *buffer, uint32_t sz) const override;
virtual uint32_t get(DocId docId, WeightedEnum *buffer, uint32_t sz) const override;
+ virtual bool findEnum(const char * value, EnumHandle & e) const override;
+ virtual const char * getStringFromEnum(EnumHandle e) const override;
+ virtual std::unique_ptr<ISearchContext> createSearchContext(std::unique_ptr<QueryTermSimple> term,
+ const SearchContextParams &params) const override;
+ virtual const IDocumentWeightAttribute *asDocumentWeightAttribute() const override;
+ virtual BasicType::Type getBasicType() const override;
+ virtual size_t getFixedWidth() const override;
+ virtual CollectionType::Type getCollectionType() const override;
+ virtual bool hasEnum() const override;
+
protected:
virtual long onSerializeForAscendingSort(DocId doc, void * serTo, long available,
const common::BlobConverter * bc) const override;
diff --git a/searchlib/src/vespa/searchlib/features/dotproductfeature.cpp b/searchlib/src/vespa/searchlib/features/dotproductfeature.cpp
index 89e7e53e2f2..be909d7a7e6 100644
--- a/searchlib/src/vespa/searchlib/features/dotproductfeature.cpp
+++ b/searchlib/src/vespa/searchlib/features/dotproductfeature.cpp
@@ -6,7 +6,7 @@
#include "array_parser.hpp"
#include <vespa/searchlib/fef/properties.h>
#include <vespa/searchlib/attribute/integerbase.h>
-#include <vespa/searchlib/attribute/imported_attribute_vector.h>
+#include <vespa/searchlib/attribute/imported_attribute_vector_read_guard.h>
#include <vespa/searchlib/attribute/floatbase.h>
#include <vespa/searchlib/attribute/multinumericattribute.h>
#include <type_traits>
@@ -356,7 +356,7 @@ template class ArrayParam<double>;
namespace {
bool isImportedAttribute(const IAttributeVector& attribute) noexcept {
- return dynamic_cast<const ImportedAttributeVector*>(&attribute) != nullptr;
+ return dynamic_cast<const ImportedAttributeVectorReadGuard*>(&attribute) != nullptr;
}
using dotproduct::ArrayParam;
diff --git a/searchlib/src/vespa/searchlib/features/internal_max_reduce_prod_join_feature.cpp b/searchlib/src/vespa/searchlib/features/internal_max_reduce_prod_join_feature.cpp
index 92120b925eb..b9a9d96ff66 100644
--- a/searchlib/src/vespa/searchlib/features/internal_max_reduce_prod_join_feature.cpp
+++ b/searchlib/src/vespa/searchlib/features/internal_max_reduce_prod_join_feature.cpp
@@ -6,7 +6,7 @@
#include <vespa/log/log.h>
#include <vespa/searchlib/attribute/attribute.h>
-#include <vespa/searchlib/attribute/imported_attribute_vector.h>
+#include <vespa/searchlib/attribute/imported_attribute_vector_read_guard.h>
#include <vespa/searchlib/attribute/multinumericattribute.h>
#include <vespa/searchlib/features/dotproductfeature.h>
#include <vespa/searchlib/fef/properties.h>
@@ -144,7 +144,7 @@ InternalMaxReduceProdJoinBlueprint::setup(const IIndexEnvironment &env, const Pa
}
bool isImportedAttribute(const IAttributeVector &attribute) noexcept {
- return dynamic_cast<const ImportedAttributeVector*>(&attribute) != nullptr;
+ return dynamic_cast<const ImportedAttributeVectorReadGuard*>(&attribute) != nullptr;
}
template<typename A>
diff --git a/searchlib/src/vespa/searchlib/tensor/imported_tensor_attribute_vector.cpp b/searchlib/src/vespa/searchlib/tensor/imported_tensor_attribute_vector.cpp
index 066978f4e50..aeaa153ef1c 100644
--- a/searchlib/src/vespa/searchlib/tensor/imported_tensor_attribute_vector.cpp
+++ b/searchlib/src/vespa/searchlib/tensor/imported_tensor_attribute_vector.cpp
@@ -38,11 +38,10 @@ ImportedTensorAttributeVector::~ImportedTensorAttributeVector()
{
}
-std::unique_ptr<attribute::ImportedAttributeVector>
+std::unique_ptr<attribute::IAttributeVector>
ImportedTensorAttributeVector::makeReadGuard(bool stableEnumGuard) const
{
- return std::make_unique<ImportedTensorAttributeVectorReadGuard>
- (getName(), getReferenceAttribute(), getTargetAttribute(), getDocumentMetaStore(), getSearchCache(), stableEnumGuard);
+ return std::make_unique<ImportedTensorAttributeVectorReadGuard>(*this, stableEnumGuard);
}
std::unique_ptr<Tensor>
diff --git a/searchlib/src/vespa/searchlib/tensor/imported_tensor_attribute_vector.h b/searchlib/src/vespa/searchlib/tensor/imported_tensor_attribute_vector.h
index 86a434cc7ae..c94b0469e93 100644
--- a/searchlib/src/vespa/searchlib/tensor/imported_tensor_attribute_vector.h
+++ b/searchlib/src/vespa/searchlib/tensor/imported_tensor_attribute_vector.h
@@ -29,7 +29,7 @@ public:
std::shared_ptr<BitVectorSearchCache> search_cache);
~ImportedTensorAttributeVector();
- virtual std::unique_ptr<attribute::ImportedAttributeVector> makeReadGuard(bool stableEnumGuard) const override;
+ virtual std::unique_ptr<attribute::IAttributeVector> makeReadGuard(bool stableEnumGuard) const override;
virtual std::unique_ptr<Tensor> getTensor(uint32_t docId) const override;
virtual std::unique_ptr<Tensor> getEmptyTensor() const override;
virtual void getTensor(uint32_t docId, vespalib::tensor::MutableDenseTensorView &tensor) const override;
diff --git a/searchlib/src/vespa/searchlib/tensor/imported_tensor_attribute_vector_read_guard.cpp b/searchlib/src/vespa/searchlib/tensor/imported_tensor_attribute_vector_read_guard.cpp
index 0678428d2c2..a927f4fac6d 100644
--- a/searchlib/src/vespa/searchlib/tensor/imported_tensor_attribute_vector_read_guard.cpp
+++ b/searchlib/src/vespa/searchlib/tensor/imported_tensor_attribute_vector_read_guard.cpp
@@ -7,18 +7,11 @@ namespace search::tensor {
using vespalib::tensor::Tensor;
-ImportedTensorAttributeVectorReadGuard::ImportedTensorAttributeVectorReadGuard(vespalib::stringref name,
- std::shared_ptr<ReferenceAttribute> reference_attribute,
- std::shared_ptr<AttributeVector> target_attribute,
- std::shared_ptr<IDocumentMetaStoreContext> document_meta_store,
- std::shared_ptr<BitVectorSearchCache> search_cache,
+ImportedTensorAttributeVectorReadGuard::ImportedTensorAttributeVectorReadGuard(const attribute::ImportedAttributeVector &imported_attribute,
bool stableEnumGuard)
- : ImportedAttributeVectorReadGuard(name, std::move(reference_attribute),
- std::move(target_attribute),
- std::move(document_meta_store),
- std::move(search_cache),
+ : ImportedAttributeVectorReadGuard(imported_attribute,
stableEnumGuard),
- _target_tensor_attribute(dynamic_cast<const ITensorAttribute &>(*_target_attribute))
+ _target_tensor_attribute(dynamic_cast<const ITensorAttribute &>(*imported_attribute.getTargetAttribute()))
{
}
diff --git a/searchlib/src/vespa/searchlib/tensor/imported_tensor_attribute_vector_read_guard.h b/searchlib/src/vespa/searchlib/tensor/imported_tensor_attribute_vector_read_guard.h
index 139f35d1fba..2715e117927 100644
--- a/searchlib/src/vespa/searchlib/tensor/imported_tensor_attribute_vector_read_guard.h
+++ b/searchlib/src/vespa/searchlib/tensor/imported_tensor_attribute_vector_read_guard.h
@@ -5,6 +5,10 @@
#include <vespa/searchlib/attribute/imported_attribute_vector_read_guard.h>
#include "i_tensor_attribute.h"
+namespace search::attribute {
+class ImportedAttributeVector;
+}
+
namespace search::tensor {
/**
@@ -20,11 +24,7 @@ class ImportedTensorAttributeVectorReadGuard : public attribute::ImportedAttribu
using BitVectorSearchCache = attribute::BitVectorSearchCache;
const ITensorAttribute &_target_tensor_attribute;
public:
- ImportedTensorAttributeVectorReadGuard(vespalib::stringref name,
- std::shared_ptr<ReferenceAttribute> reference_attribute,
- std::shared_ptr<AttributeVector> target_attribute,
- std::shared_ptr<IDocumentMetaStoreContext> document_meta_store,
- std::shared_ptr<BitVectorSearchCache> search_cache,
+ ImportedTensorAttributeVectorReadGuard(const attribute::ImportedAttributeVector &imported_attribute,
bool stableEnumGuard);
~ImportedTensorAttributeVectorReadGuard();
diff --git a/searchlib/src/vespa/searchlib/test/imported_attribute_fixture.h b/searchlib/src/vespa/searchlib/test/imported_attribute_fixture.h
index e49509a444f..6245e0304fb 100644
--- a/searchlib/src/vespa/searchlib/test/imported_attribute_fixture.h
+++ b/searchlib/src/vespa/searchlib/test/imported_attribute_fixture.h
@@ -149,6 +149,10 @@ struct ImportedAttributeFixture {
virtual ~ImportedAttributeFixture();
+ std::unique_ptr<IAttributeVector> get_imported_attr() const {
+ return imported_attr->makeReadGuard(false);
+ }
+
void map_reference(DocId from_lid, GlobalId via_gid, DocId to_lid) {
assert(from_lid < reference_attr->getNumDocs());
mapper_factory->_map[via_gid] = to_lid;
@@ -285,7 +289,7 @@ void assert_multi_value_matches(const ImportedAttributeFixture &f,
const std::vector<AttrValueType> &expected,
PredicateType predicate) {
AttributeContent<AttrValueType> content;
- content.fill(*f.imported_attr, lid);
+ content.fill(*f.get_imported_attr(), lid);
EXPECT_EQUAL(expected.size(), content.size());
std::vector<AttrValueType> actual(content.begin(), content.end());
EXPECT_TRUE(std::equal(expected.begin(), expected.end(),