blob: cbe5fedf47ae81e1cfb106374354c74b08888ec8 (
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
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
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
#include "documentaccessornode.h"
#include "resultnode.h"
#include "resultvector.h"
#include <vespa/document/fieldvalue/iteratorhandler.h>
#include <vespa/document/base/fieldpath.h>
namespace search::expression {
class DefaultValue final : public ResultNode
{
public:
DECLARE_EXPRESSIONNODE(DefaultValue);
int64_t onGetInteger(size_t index) const override { (void) index; return 0; }
double onGetFloat(size_t index) const override { (void) index; return 0; }
ConstBufferRef onGetString(size_t index, BufferRef buf) const override {
(void) index;
(void) buf;
return ConstBufferRef(&null, 0);
}
private:
void set(const ResultNode&) override;
size_t hash() const override { return 0; }
static char null;
};
class DocumentFieldNode : public DocumentAccessorNode
{
public:
DECLARE_NBO_SERIALIZE;
void visitMembers(vespalib::ObjectVisitor &visitor) const override;
DECLARE_EXPRESSIONNODE(DocumentFieldNode);
DocumentFieldNode() : _fieldPath(), _value(), _fieldName(), _doc(nullptr) { }
~DocumentFieldNode() override;
DocumentFieldNode(vespalib::stringref name) : _fieldPath(), _value(), _fieldName(name), _doc(nullptr) { }
DocumentFieldNode(const DocumentFieldNode & rhs);
DocumentFieldNode & operator = (const DocumentFieldNode & rhs);
DocumentFieldNode(DocumentFieldNode && rhs) noexcept = default;
DocumentFieldNode & operator = (DocumentFieldNode && rhs) noexcept = default;
const vespalib::string & getFieldName() const override { return _fieldName; }
private:
class Handler : public document::fieldvalue::IteratorHandler {
public:
virtual void reset() = 0;
private:
void onCollectionStart(const Content & c) override;
void onStructStart(const Content & c) override;
};
class SingleHandler : public Handler {
public:
SingleHandler(ResultNode & result) : _result(result) {}
private:
void reset() override { _result.set(_defaultValue); }
ResultNode & _result;
static DefaultValue _defaultValue;
void onPrimitive(uint32_t fid, const Content & c) override;
};
class MultiHandler : public Handler {
public:
MultiHandler(ResultNodeVector & result) : _result(result) {}
private:
void reset() override { _result.clear(); }
ResultNodeVector & _result;
void onPrimitive(uint32_t fid, const Content & c) override;
};
const ResultNode * getResult() const override { return _value.get(); }
void onPrepare(bool preserveAccurateTypes) override;
bool onExecute() const override;
void onDoc(const document::Document & doc) override;
void onDocType(const document::DocumentType & docType) override;
document::FieldPath _fieldPath;
mutable ResultNode::CP _value;
mutable std::unique_ptr<Handler> _handler;
vespalib::string _fieldName;
const document::Document * _doc;
};
}
|