diff options
author | Tor Egge <Tor.Egge@online.no> | 2023-03-10 17:13:24 +0100 |
---|---|---|
committer | Tor Egge <Tor.Egge@online.no> | 2023-03-10 17:13:24 +0100 |
commit | 295012530408b47743643aaccd15780ef6272464 (patch) | |
tree | 763701b54dad2db36459d7623a248d7b33791212 /searchsummary | |
parent | 86748ce4fadf24108eb5a459fd7f6caa01623cc4 (diff) |
Handle single value raw attribute in attribute dfw.
Diffstat (limited to 'searchsummary')
4 files changed, 55 insertions, 8 deletions
diff --git a/searchsummary/src/tests/docsummary/attributedfw/attributedfw_test.cpp b/searchsummary/src/tests/docsummary/attributedfw/attributedfw_test.cpp index bba3a5ab506..88b3423a199 100644 --- a/searchsummary/src/tests/docsummary/attributedfw/attributedfw_test.cpp +++ b/searchsummary/src/tests/docsummary/attributedfw/attributedfw_test.cpp @@ -23,6 +23,10 @@ using search::docsummary::test::SlimeValue; using ElementVector = std::vector<uint32_t>; +std::vector<char> as_vector(vespalib::stringref value) { + return {value.data(), value.data() + value.size()}; +} + class AttributeDFWTest : public ::testing::Test { protected: MockAttributeManager _attrs; @@ -48,7 +52,8 @@ public: _attrs.build_string_attribute("wset_str", { {"a", "b", "c"}, {} }, CollectionType::WSET); _attrs.build_int_attribute("wset_int", BasicType::INT32, { {10, 20, 30}, {} }, CollectionType::WSET); _attrs.build_float_attribute("wset_float", { {10.5, 20.5, 30.5}, {} }, CollectionType::WSET); - + _attrs.build_string_attribute("single_str", { {"world"}, {}}, CollectionType::SINGLE); + _attrs.build_raw_attribute("single_raw", { {as_vector("hello")}, {} }); _state._attrCtx = _attrs.mgr().createContext(); } ~AttributeDFWTest() {} @@ -59,17 +64,24 @@ public: } _writer = AttributeDFWFactory::create(_attrs.mgr(), field_name, filter_elements, _matching_elems_fields); _writer->setIndex(0); - EXPECT_TRUE(_writer->setFieldWriterStateIndex(0)); - _state._fieldWriterStates.resize(1); + auto attr = _state._attrCtx->getAttribute(field_name); + if (attr->hasMultiValue()) { + EXPECT_TRUE(_writer->setFieldWriterStateIndex(0)); + _state._fieldWriterStates.resize(1); + } else { + EXPECT_FALSE(_writer->setFieldWriterStateIndex(0)); + } _field_name = field_name; _state._attributes.resize(1); - _state._attributes[0] = _state._attrCtx->getAttribute(field_name); + _state._attributes[0] = attr; } void expect_field(const vespalib::string& exp_slime_as_json, uint32_t docid) { vespalib::Slime act; vespalib::slime::SlimeInserter inserter(act); - _writer->insertField(docid, nullptr, _state, inserter); + if (!_writer->isDefaultValue(docid, _state)) { + _writer->insertField(docid, nullptr, _state, inserter); + } SlimeValue exp(exp_slime_as_json); EXPECT_EQ(exp.slime, act); @@ -150,4 +162,18 @@ TEST_F(AttributeDFWTest, filteres_matched_elements_in_wset_attribute) expect_filtered({3}, "null"); } +TEST_F(AttributeDFWTest, single_string) +{ + setup("single_str", false); + expect_field(R"("world")", 1); + expect_field("null", 2); +} + +TEST_F(AttributeDFWTest, single_value_raw) +{ + setup("single_raw", false); + expect_field("x68656C6C6F", 1); + expect_field("null", 2); +} + GTEST_MAIN_RUN_ALL_TESTS() diff --git a/searchsummary/src/vespa/searchsummary/docsummary/attributedfw.cpp b/searchsummary/src/vespa/searchsummary/docsummary/attributedfw.cpp index e606c6f08bb..6f0f6737c0f 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/attributedfw.cpp +++ b/searchsummary/src/vespa/searchsummary/docsummary/attributedfw.cpp @@ -101,6 +101,11 @@ SingleAttrDFW::insertField(uint32_t docid, GetDocsumsState& state, Inserter &tar target.insertString(vespalib::Memory(s.data(), s.size())); break; } + case BasicType::RAW: { + auto s = v.get_raw(docid); + target.insertData(vespalib::Memory(s.data(), s.size())); + break; + } case BasicType::REFERENCE: case BasicType::PREDICATE: break; // Should never use attribute docsum field writer diff --git a/searchsummary/src/vespa/searchsummary/test/mock_attribute_manager.cpp b/searchsummary/src/vespa/searchsummary/test/mock_attribute_manager.cpp index 4bfaf105501..77dc38d3057 100644 --- a/searchsummary/src/vespa/searchsummary/test/mock_attribute_manager.cpp +++ b/searchsummary/src/vespa/searchsummary/test/mock_attribute_manager.cpp @@ -5,12 +5,14 @@ #include <vespa/searchlib/attribute/floatbase.h> #include <vespa/searchlib/attribute/integerbase.h> #include <vespa/searchlib/attribute/stringbase.h> +#include <vespa/searchlib/attribute/single_raw_attribute.h> #include <vespa/searchcommon/attribute/config.h> #include <cassert> using search::attribute::BasicType; using search::attribute::CollectionType; using search::attribute::Config; +using search::attribute::SingleRawAttribute; namespace search::docsummary::test { @@ -29,8 +31,14 @@ MockAttributeManager::build_attribute(const vespalib::string& name, BasicType ty for (const auto& docValues : values) { uint32_t docId = 0; attr->addDoc(docId); - for (const auto& value : docValues) { - attr->append(docId, value, 1); + attr->clearDoc(docId); + if (attr->hasMultiValue()) { + for (const auto& value : docValues) { + attr->append(docId, value, 1); + } + } else if (!docValues.empty()) { + assert(docValues.size() == 1); + attr->update(docId, docValues[0]); } attr->commit(); } @@ -68,4 +76,11 @@ MockAttributeManager::build_int_attribute(const vespalib::string& name, BasicTyp build_attribute<IntegerAttribute, int64_t>(name, type, col_type, values); } +void +MockAttributeManager::build_raw_attribute(const vespalib::string& name, + const std::vector<std::vector<std::vector<char>>>& values) +{ + build_attribute<SingleRawAttribute, std::vector<char>>(name, BasicType::Type::RAW, CollectionType::SINGLE, values); +} + } diff --git a/searchsummary/src/vespa/searchsummary/test/mock_attribute_manager.h b/searchsummary/src/vespa/searchsummary/test/mock_attribute_manager.h index 0c4f3a5cc9b..6cdcfcbb6db 100644 --- a/searchsummary/src/vespa/searchsummary/test/mock_attribute_manager.h +++ b/searchsummary/src/vespa/searchsummary/test/mock_attribute_manager.h @@ -31,7 +31,8 @@ public: void build_int_attribute(const vespalib::string& name, search::attribute::BasicType type, const std::vector<std::vector<int64_t>>& values, search::attribute::CollectionType col_type = search::attribute::CollectionType::ARRAY); - + void build_raw_attribute(const vespalib::string& name, + const std::vector<std::vector<std::vector<char>>>& values); }; } |