diff options
author | Tor Egge <Tor.Egge@oath.com> | 2018-09-10 14:00:45 +0000 |
---|---|---|
committer | Tor Egge <Tor.Egge@oath.com> | 2018-09-10 14:29:47 +0000 |
commit | fce52c393e9c5f1bc0427614f46d9c2150418fea (patch) | |
tree | 0d554ecf9446cf4a14697c8e04c7c2d889fb3723 /searchlib/src | |
parent | 90f16b7689e19faef111f127908a513bb6990bb1 (diff) |
Allocate identifiable id for AttributeMapLookupNode.
Diffstat (limited to 'searchlib/src')
7 files changed, 52 insertions, 53 deletions
diff --git a/searchlib/src/tests/expression/attributenode/attribute_node_test.cpp b/searchlib/src/tests/expression/attributenode/attribute_node_test.cpp index b2e4bd41680..fa7972eb928 100644 --- a/searchlib/src/tests/expression/attributenode/attribute_node_test.cpp +++ b/searchlib/src/tests/expression/attributenode/attribute_node_test.cpp @@ -60,6 +60,31 @@ vespalib::string stringValue(const ResultNode &result, const IAttributeVector &a return vespalib::string(sbuf.c_str(), sbuf.c_str() + sbuf.size()); } +vespalib::string indirectKeyMarker("attribute("); + +std::unique_ptr<AttributeNode> +makeAttributeMapLookupNode(const vespalib::string attributeName) +{ + vespalib::asciistream keyName; + vespalib::asciistream valueName; + auto leftBracePos = attributeName.find('{'); + auto baseName = attributeName.substr(0, leftBracePos); + auto rightBracePos = attributeName.rfind('}'); + keyName << baseName << ".key"; + valueName << baseName << ".value" << attributeName.substr(rightBracePos + 1); + if (rightBracePos != vespalib::string::npos && rightBracePos > leftBracePos) { + if (attributeName[leftBracePos + 1] == '"' && attributeName[rightBracePos - 1] == '"') { + vespalib::string key = attributeName.substr(leftBracePos + 2, rightBracePos - leftBracePos - 3); + return std::make_unique<AttributeMapLookupNode>(keyName.str(), valueName.str(), key, ""); + } else if (attributeName.substr(leftBracePos + 1, indirectKeyMarker.size()) == indirectKeyMarker && attributeName[rightBracePos - 1] == ')') { + auto startPos = leftBracePos + 1 + indirectKeyMarker.size(); + vespalib::string keySourceAttributeName = attributeName.substr(startPos, rightBracePos - 1 - startPos); + return std::make_unique<AttributeMapLookupNode>(keyName.str(), valueName.str(), "", keySourceAttributeName); + } + } + return std::unique_ptr<AttributeNode>(); +} + struct AttributeManagerFixture { AttributeManager mgr; @@ -220,7 +245,7 @@ Fixture::makeNode(const vespalib::string &attributeName, bool useEnumOptimizatio if (attributeName.find('{') == vespalib::string::npos) { node = std::make_unique<AttributeNode>(attributeName); } else { - node = std::make_unique<AttributeMapLookupNode>(attributeName); + node = makeAttributeMapLookupNode(attributeName); } if (useEnumOptimization) { node->useEnumOptimization(); diff --git a/searchlib/src/vespa/searchlib/aggregation/modifiers.cpp b/searchlib/src/vespa/searchlib/aggregation/modifiers.cpp index 0b91d37862d..5ffad122c7d 100644 --- a/searchlib/src/vespa/searchlib/aggregation/modifiers.cpp +++ b/searchlib/src/vespa/searchlib/aggregation/modifiers.cpp @@ -64,18 +64,6 @@ Attribute2DocumentAccessor::getReplacementNode(const AttributeNode &attributeNod return std::make_unique<DocumentFieldNode>(attributeNode.getAttributeName()); } -std::unique_ptr<ExpressionNode> -Attribute2AttributeKeyed::getReplacementNode(const AttributeNode &attributeNode) -{ - const vespalib::string &attributeName = attributeNode.getAttributeName(); - auto lBracePos = attributeName.find('{'); - if (attributeNode.isKeyed() || lBracePos == vespalib::string::npos) { - return std::unique_ptr<ExpressionNode>(); - } else { - return std::make_unique<AttributeMapLookupNode>(attributeName); - } -} - } // this function was added by ../../forcelink.sh diff --git a/searchlib/src/vespa/searchlib/aggregation/modifiers.h b/searchlib/src/vespa/searchlib/aggregation/modifiers.h index 6ffda313904..0120cb4eac9 100644 --- a/searchlib/src/vespa/searchlib/aggregation/modifiers.h +++ b/searchlib/src/vespa/searchlib/aggregation/modifiers.h @@ -28,10 +28,4 @@ private: std::unique_ptr<search::expression::ExpressionNode> getReplacementNode(const search::expression::AttributeNode &attributeNode) override; }; -class Attribute2AttributeKeyed : public AttributeNodeReplacer -{ -private: - std::unique_ptr<search::expression::ExpressionNode> getReplacementNode(const search::expression::AttributeNode &attributeNode) override; -}; - } diff --git a/searchlib/src/vespa/searchlib/common/identifiable.h b/searchlib/src/vespa/searchlib/common/identifiable.h index 5a64e29ddf3..35e49b5cddf 100644 --- a/searchlib/src/vespa/searchlib/common/identifiable.h +++ b/searchlib/src/vespa/searchlib/common/identifiable.h @@ -148,6 +148,7 @@ #define CID_search_expression_AggregationRefNode SEARCHLIB_CID(142) #define CID_search_expression_NormalizeSubjectFunctionNode SEARCHLIB_CID(143) #define CID_search_expression_DebugWaitFunctionNode SEARCHLIB_CID(144) +#define CID_search_expression_AttributeMapLookupNode SEARCHLIB_CID(145) #define CID_search_QueryNode SEARCHLIB_CID(150) #define CID_search_Query SEARCHLIB_CID(151) diff --git a/searchlib/src/vespa/searchlib/expression/attribute_map_lookup_node.cpp b/searchlib/src/vespa/searchlib/expression/attribute_map_lookup_node.cpp index f4593552a47..4ec21bbcb9f 100644 --- a/searchlib/src/vespa/searchlib/expression/attribute_map_lookup_node.cpp +++ b/searchlib/src/vespa/searchlib/expression/attribute_map_lookup_node.cpp @@ -11,10 +11,14 @@ using search::attribute::AttributeContent; using search::attribute::IAttributeVector; using search::attribute::BasicType; using search::attribute::getUndefined; +using vespalib::Deserializer; +using vespalib::Serializer; using EnumHandle = IAttributeVector::EnumHandle; namespace search::expression { +IMPLEMENT_EXPRESSIONNODE(AttributeMapLookupNode, AttributeNode); + class AttributeMapLookupNode::KeyHandler { protected: @@ -241,16 +245,15 @@ AttributeMapLookupNode::AttributeMapLookupNode() AttributeMapLookupNode::AttributeMapLookupNode(const AttributeMapLookupNode &) = default; -AttributeMapLookupNode::AttributeMapLookupNode(vespalib::stringref name) - : AttributeNode(name), - _keyAttributeName(), - _valueAttributeName(), - _key(), - _keySourceAttributeName(), +AttributeMapLookupNode::AttributeMapLookupNode(vespalib::stringref keyAttributeName, vespalib::stringref valueAttributeName, vespalib::stringref key, vespalib::stringref keySourceAttributeName) + : AttributeNode(""), + _keyAttributeName(keyAttributeName), + _valueAttributeName(valueAttributeName), + _key(key), + _keySourceAttributeName(keySourceAttributeName), _keyAttribute(nullptr), _keySourceAttribute(nullptr) { - setupAttributeNames(); } AttributeMapLookupNode::~AttributeMapLookupNode() = default; @@ -258,28 +261,6 @@ AttributeMapLookupNode::~AttributeMapLookupNode() = default; AttributeMapLookupNode & AttributeMapLookupNode::operator=(const AttributeMapLookupNode &rhs) = default; -void -AttributeMapLookupNode::setupAttributeNames() -{ - vespalib::asciistream keyName; - vespalib::asciistream valueName; - auto leftBracePos = _attributeName.find('{'); - auto baseName = _attributeName.substr(0, leftBracePos); - auto rightBracePos = _attributeName.rfind('}'); - keyName << baseName << ".key"; - valueName << baseName << ".value" << _attributeName.substr(rightBracePos + 1); - _keyAttributeName = keyName.str(); - _valueAttributeName = valueName.str(); - if (rightBracePos != vespalib::string::npos && rightBracePos > leftBracePos) { - if (_attributeName[leftBracePos + 1] == '"' && _attributeName[rightBracePos - 1] == '"') { - _key = _attributeName.substr(leftBracePos + 2, rightBracePos - leftBracePos - 3); - } else if (_attributeName.substr(leftBracePos + 1, indirectKeyMarker.size()) == indirectKeyMarker && _attributeName[rightBracePos - 1] == ')') { - auto startPos = leftBracePos + 1 + indirectKeyMarker.size(); - _keySourceAttributeName = _attributeName.substr(startPos, rightBracePos - 1 - startPos); - } - } -} - template <typename ResultNodeType> void AttributeMapLookupNode::prepareIntValues(std::unique_ptr<KeyHandler> keyHandler, const IAttributeVector &attribute, IAttributeVector::largeint_t undefinedValue) @@ -399,10 +380,21 @@ AttributeMapLookupNode::wireAttributes(const search::attribute::IAttributeContex } } +Serializer & AttributeMapLookupNode::onSerialize(Serializer & os) const +{ + FunctionNode::onSerialize(os); + return os << _keyAttributeName << _valueAttributeName << _key << _keySourceAttributeName; +} + +Deserializer & AttributeMapLookupNode::onDeserialize(Deserializer & is) +{ + FunctionNode::onDeserialize(is); + return is >> _keyAttributeName >> _valueAttributeName >> _key >> _keySourceAttributeName; +} + void AttributeMapLookupNode::visitMembers(vespalib::ObjectVisitor &visitor) const { - AttributeNode::visitMembers(visitor); visit(visitor, "keyAttributeName", _keyAttributeName); visit(visitor, "keySourceAttributeName", _keySourceAttributeName); visit(visitor, "valueAttributeName", _valueAttributeName); diff --git a/searchlib/src/vespa/searchlib/expression/attribute_map_lookup_node.h b/searchlib/src/vespa/searchlib/expression/attribute_map_lookup_node.h index 36b1a718f84..86b60b079ce 100644 --- a/searchlib/src/vespa/searchlib/expression/attribute_map_lookup_node.h +++ b/searchlib/src/vespa/searchlib/expression/attribute_map_lookup_node.h @@ -22,7 +22,6 @@ private: const IAttributeVector *_keyAttribute; const IAttributeVector *_keySourceAttribute; - void setupAttributeNames(); template <typename ResultNodeType> void prepareIntValues(std::unique_ptr<KeyHandler> keyHandler, const IAttributeVector &attribute, IAttributeVector::largeint_t undefinedValue); std::unique_ptr<KeyHandler> makeKeyHandlerHelper(); @@ -31,15 +30,16 @@ private: void wireAttributes(const search::attribute::IAttributeContext & attrCtx) override; void onPrepare(bool preserveAccurateTypes) override; public: + DECLARE_NBO_SERIALIZE; + DECLARE_EXPRESSIONNODE(AttributeMapLookupNode); AttributeMapLookupNode(); - AttributeMapLookupNode(vespalib::stringref name); + AttributeMapLookupNode(vespalib::stringref keyAttributeName, vespalib::stringref valueAttributeName, vespalib::stringref key, vespalib::stringref keySourceAttributeName); AttributeMapLookupNode(const AttributeMapLookupNode &); AttributeMapLookupNode(AttributeMapLookupNode &&) = delete; ~AttributeMapLookupNode() override; AttributeMapLookupNode &operator=(const AttributeMapLookupNode &rhs); AttributeMapLookupNode &operator=(AttributeMapLookupNode &&rhs) = delete; void visitMembers(vespalib::ObjectVisitor &visitor) const override; - bool isKeyed() const override { return true; } }; } diff --git a/searchlib/src/vespa/searchlib/expression/attributenode.h b/searchlib/src/vespa/searchlib/expression/attributenode.h index e12b5490955..472267f4b5c 100644 --- a/searchlib/src/vespa/searchlib/expression/attributenode.h +++ b/searchlib/src/vespa/searchlib/expression/attributenode.h @@ -55,7 +55,6 @@ public: void useEnumOptimization(bool use=true) { _useEnumOptimization = use; } bool hasMultiValue() const { return _hasMultiValue; } - virtual bool isKeyed() const { return false; } public: class Handler { |