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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "arrayatlookupfunctionnode.h"
namespace search::expression {
using vespalib::Serializer;
using vespalib::Deserializer;
IMPLEMENT_EXPRESSIONNODE(ArrayAtLookup, AttributeNode);
ArrayAtLookup::ArrayAtLookup() noexcept
: AttributeNode(),
_currentIndex(),
_indexExpression()
{
setCurrentIndex(&_currentIndex);
}
ArrayAtLookup::~ArrayAtLookup() = default;
ArrayAtLookup & ArrayAtLookup::operator=(const ArrayAtLookup &rhs) = default;
ArrayAtLookup::ArrayAtLookup(const vespalib::string &attribute, ExpressionNode::UP indexExpr)
: AttributeNode(attribute),
_currentIndex(),
_indexExpression(std::move(indexExpr))
{
setCurrentIndex(&_currentIndex);
}
ArrayAtLookup::ArrayAtLookup(const search::attribute::IAttributeVector &attr,
ExpressionNode::UP indexExpr)
: AttributeNode(attr),
_currentIndex(),
_indexExpression(std::move(indexExpr))
{
setCurrentIndex(&_currentIndex);
}
ArrayAtLookup::ArrayAtLookup(const ArrayAtLookup &rhs)
: AttributeNode(rhs),
_currentIndex(),
_indexExpression(rhs._indexExpression)
{
setCurrentIndex(&_currentIndex);
}
bool
ArrayAtLookup::onExecute() const
{
_indexExpression->execute();
int64_t idx = _indexExpression->getResult()->getInteger();
_currentIndex.set(idx);
AttributeNode::onExecute();
return true;
}
Serializer &
ArrayAtLookup::onSerialize(Serializer & os) const
{
// Here we are doing a dirty skipping AttributeNode in the inheritance.
// This is due to refactoring and the need to keep serialization the same.
FunctionNode::onSerialize(os);
os << uint32_t(1u) << _indexExpression; // Simulating a single element vector.
os << _attributeName;
return os;
}
Deserializer &
ArrayAtLookup::onDeserialize(Deserializer & is)
{
// See comment in onSerialize method.
FunctionNode::onDeserialize(is);
uint32_t count(0);
is >> count;
if (count > 0) {
is >> _indexExpression;
} else {
_indexExpression.reset();
}
is >> _attributeName;
return is;
}
void
ArrayAtLookup::visitMembers(vespalib::ObjectVisitor &visitor) const
{
AttributeNode::visitMembers(visitor);
visit(visitor, "index", *_indexExpression);
}
void
ArrayAtLookup::selectMembers(const vespalib::ObjectPredicate & predicate, vespalib::ObjectOperation & operation)
{
AttributeNode::selectMembers(predicate, operation);
if (_indexExpression) {
_indexExpression->select(predicate, operation);
}
}
}
|