blob: 0be9b08b6c44b21eeb80afc4962987c0c6de32d3 (
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
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "unbox.h"
#include <vespa/vespalib/util/stash.h>
namespace search::fef::test {
namespace {
struct UnboxExecutor : FeatureExecutor {
bool isPure() override { return true; }
void execute(uint32_t) override {
outputs().set_number(0, inputs().get_object(0).get().as_double());
}
};
struct ForwardExecutor : FeatureExecutor {
bool isPure() override { return true; }
void execute(uint32_t) override {
outputs().set_number(0, inputs().get_number(0));
}
};
} // namespace search::fef::test::<unnamed>
UnboxBlueprint::UnboxBlueprint()
: Blueprint("unbox"),
_was_object(false)
{
}
void
UnboxBlueprint::visitDumpFeatures(const IIndexEnvironment &, IDumpFeatureVisitor &) const
{
}
Blueprint::UP
UnboxBlueprint::createInstance() const
{
return std::make_unique<UnboxBlueprint>();
}
ParameterDescriptions
UnboxBlueprint::getDescriptions() const
{
return fef::ParameterDescriptions().desc().feature();
}
bool
UnboxBlueprint::setup(const IIndexEnvironment &, const ParameterList ¶ms)
{
if (auto input = defineInput(params[0].getValue(), AcceptInput::ANY)) {
_was_object = input.value().is_object();
describeOutput("value", "unboxed value", FeatureType::number());
return true;
}
return false; // dependency error
}
FeatureExecutor &
UnboxBlueprint::createExecutor(const IQueryEnvironment &, vespalib::Stash &stash) const
{
if (_was_object) {
return stash.create<UnboxExecutor>();
} else {
return stash.create<ForwardExecutor>();
}
}
} // namespace search::fef::test
|