blob: 2edd00ad5a507a068ff851e977546cb900b8478f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "make_attribute_map_lookup_node.h"
#include <vespa/searchlib/expression/attribute_map_lookup_node.h>
#include <vespa/vespalib/stllike/asciistream.h>
namespace search::expression::test {
namespace {
vespalib::string indirectKeyMarker("attribute(");
}
std::unique_ptr<AttributeNode>
makeAttributeMapLookupNode(vespalib::stringref 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>(attributeName, 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>(attributeName, keyName.str(), valueName.str(), "", keySourceAttributeName);
}
}
return std::unique_ptr<AttributeNode>();
}
}
|