summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHåvard Pettersen <havardpe@oath.com>2017-08-16 13:25:46 +0000
committerHåvard Pettersen <havardpe@oath.com>2017-08-16 13:28:30 +0000
commit366e794d3844e3eddc1fd04d717528adaf56c7fa (patch)
tree8fb06d3b5bc69951694ee768d29f69393f9665f8
parentacd1b850cd206474cef8de6231de6782f6e02120 (diff)
add simple unbox feature into test plugin
and use it in the object passing test to verify behavior
-rw-r--r--searchlib/src/tests/fef/object_passing/object_passing_test.cpp14
-rw-r--r--searchlib/src/vespa/searchlib/fef/test/plugin/CMakeLists.txt9
-rw-r--r--searchlib/src/vespa/searchlib/fef/test/plugin/setup.cpp23
-rw-r--r--searchlib/src/vespa/searchlib/fef/test/plugin/unbox.cpp54
-rw-r--r--searchlib/src/vespa/searchlib/fef/test/plugin/unbox.h19
5 files changed, 95 insertions, 24 deletions
diff --git a/searchlib/src/tests/fef/object_passing/object_passing_test.cpp b/searchlib/src/tests/fef/object_passing/object_passing_test.cpp
index 159e17f24f7..5c0f09a1203 100644
--- a/searchlib/src/tests/fef/object_passing/object_passing_test.cpp
+++ b/searchlib/src/tests/fef/object_passing/object_passing_test.cpp
@@ -6,7 +6,7 @@
#include <vespa/searchlib/fef/blueprintfactory.h>
#include <vespa/searchlib/fef/test/indexenvironment.h>
#include <vespa/searchlib/fef/test/queryenvironment.h>
-#include <vespa/searchlib/fef/test/plugin/sum.h>
+#include <vespa/searchlib/fef/test/plugin/unbox.h>
#include <vespa/searchlib/fef/rank_program.h>
#include <vespa/searchlib/fef/verify_feature.h>
#include <vespa/eval/eval/value_type.h>
@@ -73,11 +73,11 @@ struct Fixture {
IndexEnvironment indexEnv;
explicit Fixture() {
- factory.addPrototype(Blueprint::SP(new ValueBlueprint()));
- factory.addPrototype(Blueprint::SP(new ProxyBlueprint("box", Blueprint::AcceptInput::NUMBER, true)));
- factory.addPrototype(Blueprint::SP(new ProxyBlueprint("maybe_box", Blueprint::AcceptInput::ANY, true)));
- factory.addPrototype(Blueprint::SP(new ProxyBlueprint("unbox", Blueprint::AcceptInput::OBJECT, false)));
- factory.addPrototype(Blueprint::SP(new ProxyBlueprint("maybe_unbox", Blueprint::AcceptInput::ANY, false)));
+ factory.addPrototype(std::make_shared<ValueBlueprint>());
+ factory.addPrototype(std::make_shared<UnboxBlueprint>());
+ factory.addPrototype(std::make_shared<ProxyBlueprint>("box", Blueprint::AcceptInput::NUMBER, true));
+ factory.addPrototype(std::make_shared<ProxyBlueprint>("maybe_box", Blueprint::AcceptInput::ANY, true));
+ factory.addPrototype(std::make_shared<ProxyBlueprint>("maybe_unbox", Blueprint::AcceptInput::ANY, false));
}
double eval(const vespalib::string &feature) {
@@ -106,7 +106,7 @@ TEST_F("require that values can be boxed and unboxed", Fixture()) {
EXPECT_EQUAL(3.0, f1.eval("box(value(3))"));
EXPECT_EQUAL(0.0, f1.eval("box(value(3)).was_object"));
EXPECT_EQUAL(3.0, f1.eval("unbox(box(value(3)))"));
- EXPECT_EQUAL(1.0, f1.eval("unbox(box(value(3))).was_object"));
+ EXPECT_EQUAL(1.0, f1.eval("maybe_unbox(box(value(3))).was_object"));
EXPECT_EQUAL(3.0, f1.eval("box(unbox(box(value(3))))"));
EXPECT_EQUAL(0.0, f1.eval("box(unbox(box(value(3)))).was_object"));
}
diff --git a/searchlib/src/vespa/searchlib/fef/test/plugin/CMakeLists.txt b/searchlib/src/vespa/searchlib/fef/test/plugin/CMakeLists.txt
index 5013ae1bb7d..4d26ed49a9d 100644
--- a/searchlib/src/vespa/searchlib/fef/test/plugin/CMakeLists.txt
+++ b/searchlib/src/vespa/searchlib/fef/test/plugin/CMakeLists.txt
@@ -1,12 +1,13 @@
# Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
vespa_add_library(searchlib_fef_test_plugin OBJECT
SOURCES
- double.cpp
- sum.cpp
- staticrank.cpp
- chain.cpp
cfgvalue.cpp
+ chain.cpp
+ double.cpp
query.cpp
setup.cpp
+ staticrank.cpp
+ sum.cpp
+ unbox.cpp
DEPENDS
)
diff --git a/searchlib/src/vespa/searchlib/fef/test/plugin/setup.cpp b/searchlib/src/vespa/searchlib/fef/test/plugin/setup.cpp
index 0c9cba8549b..1b759b457fe 100644
--- a/searchlib/src/vespa/searchlib/fef/test/plugin/setup.cpp
+++ b/searchlib/src/vespa/searchlib/fef/test/plugin/setup.cpp
@@ -7,23 +7,20 @@
#include "setup.h"
#include "staticrank.h"
#include "sum.h"
-#include <vespa/searchlib/fef/blueprint.h>
+#include "unbox.h"
-namespace search {
-namespace fef {
-namespace test {
+namespace search::fef::test {
void setup_fef_test_plugin(IBlueprintRegistry & registry)
{
// register blueprints
- registry.addPrototype(Blueprint::SP(new DoubleBlueprint()));
- registry.addPrototype(Blueprint::SP(new SumBlueprint()));
- registry.addPrototype(Blueprint::SP(new StaticRankBlueprint()));
- registry.addPrototype(Blueprint::SP(new ChainBlueprint()));
- registry.addPrototype(Blueprint::SP(new CfgValueBlueprint()));
- registry.addPrototype(Blueprint::SP(new QueryBlueprint()));
+ registry.addPrototype(std::make_shared<DoubleBlueprint>());
+ registry.addPrototype(std::make_shared<SumBlueprint>());
+ registry.addPrototype(std::make_shared<StaticRankBlueprint>());
+ registry.addPrototype(std::make_shared<ChainBlueprint>());
+ registry.addPrototype(std::make_shared<CfgValueBlueprint>());
+ registry.addPrototype(std::make_shared<QueryBlueprint>());
+ registry.addPrototype(std::make_shared<UnboxBlueprint>());
}
-} // namespace test
-} // namespace fef
-} // namespace search
+} // namespace search::fef::test
diff --git a/searchlib/src/vespa/searchlib/fef/test/plugin/unbox.cpp b/searchlib/src/vespa/searchlib/fef/test/plugin/unbox.cpp
new file mode 100644
index 00000000000..7b3876fada0
--- /dev/null
+++ b/searchlib/src/vespa/searchlib/fef/test/plugin/unbox.cpp
@@ -0,0 +1,54 @@
+// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#include "unbox.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());
+ }
+};
+
+} // namespace search::fef::test::<unnamed>
+
+UnboxBlueprint::UnboxBlueprint()
+ : Blueprint("unbox")
+{
+}
+
+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 &params)
+{
+ defineInput(params[0].getValue(), AcceptInput::OBJECT);
+ describeOutput("value", "unboxed value", FeatureType::number());
+ return true;
+}
+
+FeatureExecutor &
+UnboxBlueprint::createExecutor(const IQueryEnvironment &, vespalib::Stash &stash) const
+{
+ return stash.create<UnboxExecutor>();
+}
+
+} // namespace search::fef::test
diff --git a/searchlib/src/vespa/searchlib/fef/test/plugin/unbox.h b/searchlib/src/vespa/searchlib/fef/test/plugin/unbox.h
new file mode 100644
index 00000000000..8606b440980
--- /dev/null
+++ b/searchlib/src/vespa/searchlib/fef/test/plugin/unbox.h
@@ -0,0 +1,19 @@
+// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#pragma once
+
+#include <vespa/searchlib/fef/blueprint.h>
+#include <vespa/searchlib/fef/featureexecutor.h>
+
+namespace search::fef::test {
+
+struct UnboxBlueprint : Blueprint {
+ UnboxBlueprint();
+ void visitDumpFeatures(const IIndexEnvironment &, IDumpFeatureVisitor &) const override;
+ Blueprint::UP createInstance() const override;
+ ParameterDescriptions getDescriptions() const override;
+ bool setup(const IIndexEnvironment &, const ParameterList &params) override;
+ FeatureExecutor &createExecutor(const IQueryEnvironment &, vespalib::Stash &stash) const override;
+};
+
+} // namespace search::fef::test