diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2020-03-02 13:42:45 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2020-03-05 13:05:01 +0000 |
commit | 3f9ebe010b78feb15b8866b27db615ef9281ee99 (patch) | |
tree | f698f44314a2e3f5a7addaddf2e82f61d223568c /searchlib | |
parent | f21bf723e19b774f7b8f07564e3672d21b0c431d (diff) |
Restructure and do sanity checking against num outputs.
Diffstat (limited to 'searchlib')
-rw-r--r-- | searchlib/src/vespa/searchlib/features/attributefeature.cpp | 77 |
1 files changed, 48 insertions, 29 deletions
diff --git a/searchlib/src/vespa/searchlib/features/attributefeature.cpp b/searchlib/src/vespa/searchlib/features/attributefeature.cpp index fbaf1958332..d55db4ba748 100644 --- a/searchlib/src/vespa/searchlib/features/attributefeature.cpp +++ b/searchlib/src/vespa/searchlib/features/attributefeature.cpp @@ -359,7 +359,9 @@ createAttributeExecutor(uint32_t numOutputs, const IAttributeVector *attribute, std::vector<feature_t> values(4, 0.0f); return stash.create<ValueExecutor>(values); } - if (attribute->getCollectionType() == CollectionType::WSET) { + CollectionType collectionType = attribute->getCollectionType(); + if (collectionType == CollectionType::WSET) { + assert(numOutputs == 4); bool useKey = !extraParam.empty(); if (useKey) { if (attribute->isStringType()) { @@ -373,37 +375,54 @@ createAttributeExecutor(uint32_t numOutputs, const IAttributeVector *attribute, return stash.create<CountOnlyAttributeExecutor>(*attribute); } } else { // SINGLE or ARRAY - if ((attribute->getCollectionType() == CollectionType::SINGLE) && (attribute->isIntegerType() || attribute->isFloatingPointType())) { - { SingleValueExecutorCreator<FloatingPointAttributeTemplate<double>> creator; if (creator.handle(attribute)) return creator.create(stash); } - { SingleValueExecutorCreator<FloatingPointAttributeTemplate<float>> creator; if (creator.handle(attribute)) return creator.create(stash); } - { SingleValueExecutorCreator<IntegerAttributeTemplate<int8_t>> creator; if (creator.handle(attribute)) return creator.create(stash); } - { SingleValueExecutorCreator<IntegerAttributeTemplate<int32_t>> creator; if (creator.handle(attribute)) return creator.create(stash); } - { SingleValueExecutorCreator<IntegerAttributeTemplate<int64_t>> creator; if (creator.handle(attribute)) return creator.create(stash); } - { - auto boolAttribute = dynamic_cast<const SingleBoolAttribute *>(attribute); - if (boolAttribute && (numOutputs == 1)) { - return stash.create<BoolAttributeExecutor>(*boolAttribute); + BasicType basicType = attribute->getBasicType(); + if (collectionType == CollectionType::SINGLE) { + if (attribute->isIntegerType()) { + if (basicType == BasicType::BOOL) { + auto boolAttribute = dynamic_cast<const SingleBoolAttribute *>(attribute); + if (boolAttribute && (numOutputs == 1)) { + return stash.create<BoolAttributeExecutor>(*boolAttribute); + } + } else { + assert(numOutputs == 4); + if (basicType == BasicType::INT8) { + SingleValueExecutorCreator<IntegerAttributeTemplate<int8_t>> creator; + if (creator.handle(attribute)) return creator.create(stash); + } else if (basicType == BasicType::INT32) { + SingleValueExecutorCreator<IntegerAttributeTemplate<int32_t>> creator; + if (creator.handle(attribute)) return creator.create(stash); + } + SingleValueExecutorCreator<IntegerAttributeTemplate<int64_t>> creator; + if (creator.handle(attribute)) return creator.create(stash); + } + } else if (attribute->isFloatingPointType()) { + assert(numOutputs == 4); + if (basicType == BasicType::DOUBLE) { + SingleValueExecutorCreator<FloatingPointAttributeTemplate<double>> creator; + if (creator.handle(attribute)) return creator.create(stash); + } else { + SingleValueExecutorCreator<FloatingPointAttributeTemplate<float>> creator; + if (creator.handle(attribute)) return creator.create(stash); } } } - { - uint32_t idx = 0; - if (!extraParam.empty()) { - idx = util::strToNum<uint32_t>(extraParam); - } else if (attribute->getCollectionType() == CollectionType::ARRAY) { - return stash.create<CountOnlyAttributeExecutor>(*attribute); - } - if (attribute->isStringType()) { - return stash.create<AttributeExecutor<ConstCharContent>>(attribute, idx); - } else if (attribute->isIntegerType()) { - { MultiValueExecutorCreator<IntegerAttributeTemplate<int32_t>> creator; if (creator.handle(attribute)) return creator.create(stash, idx); } - { MultiValueExecutorCreator<IntegerAttributeTemplate<int64_t>> creator; if (creator.handle(attribute)) return creator.create(stash, idx); } - return stash.create<AttributeExecutor<IntegerContent>>(attribute, idx); - } else { // FLOAT - { MultiValueExecutorCreator<FloatingPointAttributeTemplate<double>> creator; if (creator.handle(attribute)) return creator.create(stash, idx); } - { MultiValueExecutorCreator<FloatingPointAttributeTemplate<float>> creator; if (creator.handle(attribute)) return creator.create(stash, idx); } - return stash.create<AttributeExecutor<FloatContent>>(attribute, idx); - } + assert(numOutputs == 4); + uint32_t idx = 0; + if (!extraParam.empty()) { + idx = util::strToNum<uint32_t>(extraParam); + } else if (attribute->getCollectionType() == CollectionType::ARRAY) { + return stash.create<CountOnlyAttributeExecutor>(*attribute); + } + if (attribute->isStringType()) { + return stash.create<AttributeExecutor<ConstCharContent>>(attribute, idx); + } else if (attribute->isIntegerType()) { + { MultiValueExecutorCreator<IntegerAttributeTemplate<int32_t>> creator; if (creator.handle(attribute)) return creator.create(stash, idx); } + { MultiValueExecutorCreator<IntegerAttributeTemplate<int64_t>> creator; if (creator.handle(attribute)) return creator.create(stash, idx); } + return stash.create<AttributeExecutor<IntegerContent>>(attribute, idx); + } else { // FLOAT + { MultiValueExecutorCreator<FloatingPointAttributeTemplate<double>> creator; if (creator.handle(attribute)) return creator.create(stash, idx); } + { MultiValueExecutorCreator<FloatingPointAttributeTemplate<float>> creator; if (creator.handle(attribute)) return creator.create(stash, idx); } + return stash.create<AttributeExecutor<FloatContent>>(attribute, idx); } } } |