From b8e30961b8c5f140823bd2828f87ab9fd906a1d7 Mon Sep 17 00:00:00 2001 From: HÃ¥vard Pettersen Date: Wed, 19 Jun 2019 10:18:08 +0000 Subject: readjust to a world without ErrorValue --- .../src/apps/verify_ranksetup/verify_ranksetup.cpp | 15 +++++++------ .../documentdb/configurer/configurer_test.cpp | 3 +-- .../constant_value_repo_test.cpp | 13 ++++++----- .../src/tests/proton/matching/matching_test.cpp | 3 +-- .../proton/matching/constant_value_repo.cpp | 3 +-- .../proton/matching/error_constant_value.h | 25 ---------------------- .../proton/matching/i_constant_value_repo.h | 2 +- 7 files changed, 19 insertions(+), 45 deletions(-) delete mode 100644 searchcore/src/vespa/searchcore/proton/matching/error_constant_value.h (limited to 'searchcore') diff --git a/searchcore/src/apps/verify_ranksetup/verify_ranksetup.cpp b/searchcore/src/apps/verify_ranksetup/verify_ranksetup.cpp index f60863ef0b0..721ee9978b0 100644 --- a/searchcore/src/apps/verify_ranksetup/verify_ranksetup.cpp +++ b/searchcore/src/apps/verify_ranksetup/verify_ranksetup.cpp @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include @@ -34,11 +33,11 @@ using vespa::config::search::IndexschemaConfig; using vespa::config::search::RankProfilesConfig; using vespa::config::search::core::RankingConstantsConfig; using vespalib::eval::ConstantValue; -using vespalib::eval::ErrorValue; using vespalib::eval::TensorSpec; using vespalib::eval::ValueType; using vespalib::tensor::DefaultTensorEngine; using vespalib::eval::SimpleConstantValue; +using vespalib::eval::BadConstantValue; class App : public FastOS_Application { @@ -61,13 +60,17 @@ struct DummyConstantValueRepo : IConstantValueRepo { DummyConstantValueRepo(const RankingConstantsConfig &cfg_in) : cfg(cfg_in) {} virtual vespalib::eval::ConstantValue::UP getConstant(const vespalib::string &name) const override { for (const auto &entry: cfg.constant) { - if (entry.name == name) { + if (entry.name == name) { const auto &engine = DefaultTensorEngine::ref(); - auto tensor = engine.from_spec(TensorSpec(entry.type)); - return std::make_unique(std::move(tensor)); + try { + auto tensor = engine.from_spec(TensorSpec(entry.type)); + return std::make_unique(std::move(tensor)); + } catch (std::exception &) { + return std::make_unique(); + } } } - return std::make_unique(std::make_unique()); + return vespalib::eval::ConstantValue::UP(nullptr); } }; diff --git a/searchcore/src/tests/proton/documentdb/configurer/configurer_test.cpp b/searchcore/src/tests/proton/documentdb/configurer/configurer_test.cpp index aba879e5a44..3154b420789 100644 --- a/searchcore/src/tests/proton/documentdb/configurer/configurer_test.cpp +++ b/searchcore/src/tests/proton/documentdb/configurer/configurer_test.cpp @@ -9,7 +9,6 @@ #include #include #include -#include #include #include #include @@ -138,7 +137,7 @@ ViewSet::~ViewSet() {} struct EmptyConstantValueFactory : public vespalib::eval::ConstantValueFactory { virtual vespalib::eval::ConstantValue::UP create(const vespalib::string &, const vespalib::string &) const override { - return std::make_unique(); + return vespalib::eval::ConstantValue::UP(nullptr); } }; diff --git a/searchcore/src/tests/proton/matching/constant_value_repo/constant_value_repo_test.cpp b/searchcore/src/tests/proton/matching/constant_value_repo/constant_value_repo_test.cpp index acc16f41872..68959d8e20f 100644 --- a/searchcore/src/tests/proton/matching/constant_value_repo/constant_value_repo_test.cpp +++ b/searchcore/src/tests/proton/matching/constant_value_repo/constant_value_repo_test.cpp @@ -3,7 +3,6 @@ #include #include -#include #include using namespace proton::matching; @@ -36,7 +35,7 @@ public: if (itr != _map.end()) { return std::make_unique(itr->second); } - return std::make_unique(); + return std::make_unique(); } }; @@ -58,14 +57,14 @@ TEST_F("require that constant value can be retrieved from repo", Fixture) EXPECT_EQUAL(3, f.repo.getConstant("foo")->value().as_double()); } -TEST_F("require that non-existing constant value in repo returns error value", Fixture) +TEST_F("require that non-existing constant value in repo returns nullptr", Fixture) { - EXPECT_TRUE(f.repo.getConstant("none")->value().is_error()); + EXPECT_TRUE(f.repo.getConstant("none").get() == nullptr); } -TEST_F("require that non-existing constant value in factory returns error value", Fixture) +TEST_F("require that non-existing constant value in factory returns bad constant", Fixture) { - EXPECT_TRUE(f.repo.getConstant("bar")->value().is_error()); + EXPECT_TRUE(f.repo.getConstant("bar")->type().is_error()); } TEST_F("require that reconfigure replaces existing constant values in repo", Fixture) @@ -73,7 +72,7 @@ TEST_F("require that reconfigure replaces existing constant values in repo", Fix f.repo.reconfigure(RankingConstants({{"bar", "double", "path_3"}, {"baz", "double", "path_2"}})); f.factory.add("path_3", "double", 7); - EXPECT_TRUE(f.repo.getConstant("foo")->value().is_error()); + EXPECT_TRUE(f.repo.getConstant("foo").get() == nullptr); EXPECT_EQUAL(7, f.repo.getConstant("bar")->value().as_double()); EXPECT_EQUAL(5, f.repo.getConstant("baz")->value().as_double()); } diff --git a/searchcore/src/tests/proton/matching/matching_test.cpp b/searchcore/src/tests/proton/matching/matching_test.cpp index 967d8bfd0aa..e46ed997d0f 100644 --- a/searchcore/src/tests/proton/matching/matching_test.cpp +++ b/searchcore/src/tests/proton/matching/matching_test.cpp @@ -6,7 +6,6 @@ #include #include #include -#include #include #include #include @@ -105,7 +104,7 @@ const uint32_t NUM_DOCS = 1000; struct EmptyConstantValueRepo : public proton::matching::IConstantValueRepo { virtual vespalib::eval::ConstantValue::UP getConstant(const vespalib::string &) const override { - return std::make_unique(); + return vespalib::eval::ConstantValue::UP(nullptr); } }; diff --git a/searchcore/src/vespa/searchcore/proton/matching/constant_value_repo.cpp b/searchcore/src/vespa/searchcore/proton/matching/constant_value_repo.cpp index 7e355da041c..bdfa4013c86 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/constant_value_repo.cpp +++ b/searchcore/src/vespa/searchcore/proton/matching/constant_value_repo.cpp @@ -1,7 +1,6 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "constant_value_repo.h" -#include "error_constant_value.h" using vespalib::eval::ConstantValue; @@ -27,7 +26,7 @@ ConstantValueRepo::getConstant(const vespalib::string &name) const if (constant != nullptr) { return _factory.create(constant->filePath, constant->type); } - return std::make_unique(); + return ConstantValue::UP(nullptr); } } diff --git a/searchcore/src/vespa/searchcore/proton/matching/error_constant_value.h b/searchcore/src/vespa/searchcore/proton/matching/error_constant_value.h deleted file mode 100644 index 9b0b688085d..00000000000 --- a/searchcore/src/vespa/searchcore/proton/matching/error_constant_value.h +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - -#pragma once - -#include - -namespace proton { -namespace matching { - -/** - * Class representing an error constant value. - * Typically used to indicate that a named constant value does not exists. - */ -class ErrorConstantValue : public vespalib::eval::ConstantValue { -private: - vespalib::eval::ErrorValue _value; - vespalib::eval::ValueType _type; -public: - ErrorConstantValue() : _value(), _type(vespalib::eval::ValueType::error_type()) {} - virtual const vespalib::eval::Value &value() const override { return _value; } - virtual const vespalib::eval::ValueType &type() const override { return _type; } -}; - -} -} diff --git a/searchcore/src/vespa/searchcore/proton/matching/i_constant_value_repo.h b/searchcore/src/vespa/searchcore/proton/matching/i_constant_value_repo.h index faa368c734b..5ac4fd14802 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/i_constant_value_repo.h +++ b/searchcore/src/vespa/searchcore/proton/matching/i_constant_value_repo.h @@ -9,7 +9,7 @@ namespace matching { /** * Interface for retrieving a named constant rank value to be used by features in the rank framework. - * If the given value is not found an vespalib::eval::ErrorValue should be returned. + * If the given value is not found a nullptr should be returned. */ struct IConstantValueRepo { virtual vespalib::eval::ConstantValue::UP getConstant(const vespalib::string &name) const = 0; -- cgit v1.2.3