// Copyright Vespa.ai. 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_attribute_vector.h" #include "imported_multi_value_read_view.h" #include "imported_search_context.h" #include "reference_attribute.h" #include #include namespace search::attribute { ImportedAttributeVectorReadGuard::ImportedAttributeVectorReadGuard(std::shared_ptr targetMetaStoreReadGuard, const ImportedAttributeVector &imported_attribute, bool stableEnumGuard) : AttributeReadGuard(this), _target_document_meta_store_read_guard(std::move(targetMetaStoreReadGuard)), _imported_attribute(imported_attribute), _targetLids(), _target_docid_limit(0u), _reference_attribute_guard(imported_attribute.getReferenceAttribute()->takeGenerationGuard()), _target_attribute_guard(imported_attribute.getTargetAttribute()->makeReadGuard(stableEnumGuard)), _reference_attribute(*imported_attribute.getReferenceAttribute()), _target_attribute(*_target_attribute_guard->attribute()) { _targetLids = _reference_attribute.getTargetLids(); _target_docid_limit = _target_attribute.getCommittedDocIdLimit(); } ImportedAttributeVectorReadGuard::~ImportedAttributeVectorReadGuard() = default; 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(getTargetLid(doc)); } uint32_t ImportedAttributeVectorReadGuard::getMaxValueCount() const { return _target_attribute.getMaxValueCount(); } IAttributeVector::largeint_t ImportedAttributeVectorReadGuard::getInt(DocId doc) const { return _target_attribute.getInt(getTargetLid(doc)); } double ImportedAttributeVectorReadGuard::getFloat(DocId doc) const { return _target_attribute.getFloat(getTargetLid(doc)); } vespalib::ConstArrayRef ImportedAttributeVectorReadGuard::get_raw(DocId doc) const { return _target_attribute.get_raw(getTargetLid(doc)); } IAttributeVector::EnumHandle ImportedAttributeVectorReadGuard::getEnum(DocId doc) const { return _target_attribute.getEnum(getTargetLid(doc)); } uint32_t ImportedAttributeVectorReadGuard::get(DocId docId, largeint_t *buffer, uint32_t sz) const { return _target_attribute.get(getTargetLid(docId), buffer, sz); } uint32_t ImportedAttributeVectorReadGuard::get(DocId docId, double *buffer, uint32_t sz) const { return _target_attribute.get(getTargetLid(docId), buffer, sz); } uint32_t ImportedAttributeVectorReadGuard::get(DocId docId, const char **buffer, uint32_t sz) const { return _target_attribute.get(getTargetLid(docId), buffer, sz); } uint32_t ImportedAttributeVectorReadGuard::get(DocId docId, EnumHandle *buffer, uint32_t sz) const { return _target_attribute.get(getTargetLid(docId), buffer, sz); } uint32_t ImportedAttributeVectorReadGuard::get(DocId docId, WeightedInt *buffer, uint32_t sz) const { return _target_attribute.get(getTargetLid(docId), buffer, sz); } uint32_t ImportedAttributeVectorReadGuard::get(DocId docId, WeightedFloat *buffer, uint32_t sz) const { return _target_attribute.get(getTargetLid(docId), buffer, sz); } uint32_t ImportedAttributeVectorReadGuard::get(DocId docId, WeightedString *buffer, uint32_t sz) const { return _target_attribute.get(getTargetLid(docId), buffer, sz); } uint32_t ImportedAttributeVectorReadGuard::get(DocId docId, WeightedConstChar *buffer, uint32_t sz) const { return _target_attribute.get(getTargetLid(docId), buffer, sz); } uint32_t ImportedAttributeVectorReadGuard::get(DocId docId, WeightedEnum *buffer, uint32_t sz) const { return _target_attribute.get(getTargetLid(docId), buffer, sz); } bool ImportedAttributeVectorReadGuard::findEnum(const char *value, EnumHandle &e) const { return _target_attribute.findEnum(value, e); } std::vector ImportedAttributeVectorReadGuard::findFoldedEnums(const char *value) const { return _target_attribute.findFoldedEnums(value); } const char * ImportedAttributeVectorReadGuard::getStringFromEnum(EnumHandle e) const { return _target_attribute.getStringFromEnum(e); } std::unique_ptr ImportedAttributeVectorReadGuard::createSearchContext(std::unique_ptr term, const SearchContextParams ¶ms) const { return std::make_unique(std::move(term), params, _imported_attribute, _target_attribute); } const IDocidPostingStore* ImportedAttributeVectorReadGuard::as_docid_posting_store() const { return nullptr; } const IDocidWithWeightPostingStore *ImportedAttributeVectorReadGuard::as_docid_with_weight_posting_store() const { return nullptr; } const tensor::ITensorAttribute *ImportedAttributeVectorReadGuard::asTensorAttribute() const { return nullptr; } const attribute::IMultiValueAttribute* ImportedAttributeVectorReadGuard::as_multi_value_attribute() const { return this; } 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(); } bool ImportedAttributeVectorReadGuard::getIsFilter() const { return _target_attribute.getIsFilter(); } bool ImportedAttributeVectorReadGuard::getIsFastSearch() const { return _target_attribute.getIsFastSearch(); } uint32_t ImportedAttributeVectorReadGuard::getCommittedDocIdLimit() const { return _reference_attribute.getCommittedDocIdLimit(); } bool ImportedAttributeVectorReadGuard::isImported() const { return true; } template const IMultiValueReadView* ImportedAttributeVectorReadGuard::make_read_view_helper(MultiValueTag tag, vespalib::Stash &stash) const { auto target_mv_attr = _target_attribute.as_multi_value_attribute(); if (target_mv_attr == nullptr) { return nullptr; } auto target_read_view = target_mv_attr->make_read_view(tag, stash); if (target_read_view == nullptr) { return nullptr; } return &stash.create>(_targetLids, target_read_view); } const IArrayReadView* ImportedAttributeVectorReadGuard::make_read_view(ArrayTag tag, vespalib::Stash& stash) const { return make_read_view_helper(tag, stash); } const IArrayReadView* ImportedAttributeVectorReadGuard::make_read_view(ArrayTag tag, vespalib::Stash& stash) const { return make_read_view_helper(tag, stash); } const IArrayReadView* ImportedAttributeVectorReadGuard::make_read_view(ArrayTag tag, vespalib::Stash& stash) const { return make_read_view_helper(tag, stash); } const IArrayReadView* ImportedAttributeVectorReadGuard::make_read_view(ArrayTag tag, vespalib::Stash& stash) const { return make_read_view_helper(tag, stash); } const IArrayReadView* ImportedAttributeVectorReadGuard::make_read_view(ArrayTag tag, vespalib::Stash& stash) const { return make_read_view_helper(tag, stash); } const IArrayReadView* ImportedAttributeVectorReadGuard::make_read_view(ArrayTag tag, vespalib::Stash& stash) const { return make_read_view_helper(tag, stash); } const IArrayReadView* ImportedAttributeVectorReadGuard::make_read_view(ArrayTag tag, vespalib::Stash& stash) const { return make_read_view_helper(tag, stash); } const IWeightedSetReadView* ImportedAttributeVectorReadGuard::make_read_view(WeightedSetTag tag, vespalib::Stash& stash) const { return make_read_view_helper(tag, stash); } const IWeightedSetReadView* ImportedAttributeVectorReadGuard::make_read_view(WeightedSetTag tag, vespalib::Stash& stash) const { return make_read_view_helper(tag, stash); } const IWeightedSetReadView* ImportedAttributeVectorReadGuard::make_read_view(WeightedSetTag tag, vespalib::Stash& stash) const { return make_read_view_helper(tag, stash); } const IWeightedSetReadView* ImportedAttributeVectorReadGuard::make_read_view(WeightedSetTag tag, vespalib::Stash& stash) const { return make_read_view_helper(tag, stash); } const IWeightedSetReadView* ImportedAttributeVectorReadGuard::make_read_view(WeightedSetTag tag, vespalib::Stash& stash) const { return make_read_view_helper(tag, stash); } const IWeightedSetReadView* ImportedAttributeVectorReadGuard:: make_read_view(WeightedSetTag tag, vespalib::Stash& stash) const { return make_read_view_helper(tag, stash); } const IWeightedSetReadView* ImportedAttributeVectorReadGuard::make_read_view(WeightedSetTag tag, vespalib::Stash& stash) const { return make_read_view_helper(tag, stash); } const IArrayEnumReadView* ImportedAttributeVectorReadGuard::make_read_view(ArrayEnumTag tag, vespalib::Stash& stash) const { return make_read_view_helper(tag, stash); } const IWeightedSetEnumReadView* ImportedAttributeVectorReadGuard::make_read_view(WeightedSetEnumTag tag, vespalib::Stash& stash) const { return make_read_view_helper(tag, stash); } bool ImportedAttributeVectorReadGuard::isUndefined(DocId doc) const { return _target_attribute.isUndefined(getTargetLid(doc)); } long ImportedAttributeVectorReadGuard::onSerializeForAscendingSort(DocId doc, void *serTo, long available, const common::BlobConverter *bc) const { return _target_attribute.serializeForAscendingSort(getTargetLid(doc), serTo, available, bc); } long ImportedAttributeVectorReadGuard::onSerializeForDescendingSort(DocId doc, void *serTo, long available, const common::BlobConverter *bc) const { return _target_attribute.serializeForDescendingSort(getTargetLid(doc), serTo, available, bc); } }