From 64a0c8e97e097ea6efb8e828cd67025d3da83a92 Mon Sep 17 00:00:00 2001 From: HÃ¥vard Pettersen Date: Fri, 15 Dec 2023 11:40:51 +0000 Subject: dump blueprint cost and ignore it when comparing structures --- .../tests/queryeval/blueprint/blueprint_test.cpp | 4 ++ .../blueprint/intermediate_blueprints_test.cpp | 68 ++++++++++++++++++++-- .../parallel_weak_and/parallel_weak_and_test.cpp | 2 + .../src/vespa/searchlib/queryeval/blueprint.cpp | 1 + 4 files changed, 70 insertions(+), 5 deletions(-) (limited to 'searchlib') diff --git a/searchlib/src/tests/queryeval/blueprint/blueprint_test.cpp b/searchlib/src/tests/queryeval/blueprint/blueprint_test.cpp index 20cf2008e4b..eefca5c82e9 100644 --- a/searchlib/src/tests/queryeval/blueprint/blueprint_test.cpp +++ b/searchlib/src/tests/queryeval/blueprint/blueprint_test.cpp @@ -646,6 +646,7 @@ getExpectedBlueprint() " tree_size: 2\n" " allow_termwise_eval: false\n" " }\n" + " cost: 1\n" " sourceId: 4294967295\n" " docid_limit: 0\n" " children: std::vector {\n" @@ -666,6 +667,7 @@ getExpectedBlueprint() " tree_size: 1\n" " allow_termwise_eval: true\n" " }\n" + " cost: 1\n" " sourceId: 4294967295\n" " docid_limit: 0\n" " }\n" @@ -696,6 +698,7 @@ getExpectedSlimeBlueprint() { " tree_size: 2," " allow_termwise_eval: false" " }," + " cost: 1.0," " sourceId: 4294967295," " docid_limit: 0," " children: {" @@ -721,6 +724,7 @@ getExpectedSlimeBlueprint() { " tree_size: 1," " allow_termwise_eval: true" " }," + " cost: 1.0," " sourceId: 4294967295," " docid_limit: 0" " }" diff --git a/searchlib/src/tests/queryeval/blueprint/intermediate_blueprints_test.cpp b/searchlib/src/tests/queryeval/blueprint/intermediate_blueprints_test.cpp index e24e91c2f1d..04a13198b02 100644 --- a/searchlib/src/tests/queryeval/blueprint/intermediate_blueprints_test.cpp +++ b/searchlib/src/tests/queryeval/blueprint/intermediate_blueprints_test.cpp @@ -14,6 +14,10 @@ #include #include #include +#include +#include +#include +#include #include #include @@ -24,6 +28,11 @@ using namespace search::fef; using namespace search::query; using search::BitVector; using BlueprintVector = std::vector>; +using vespalib::Slime; +using vespalib::slime::Inspector; +using vespalib::slime::SlimeInserter; +using vespalib::make_string_short::fmt; +using Path = std::vector>; struct InvalidSelector : ISourceSelector { InvalidSelector() : ISourceSelector(Source()) {} @@ -480,13 +489,62 @@ struct SourceBlenderTestFixture { void addChildrenForSimpleSBTest(IntermediateBlueprint & parent); }; +vespalib::string path_to_str(const Path &path) { + size_t cnt = 0; + vespalib::string str("["); + for (const auto &item: path) { + if (cnt++ > 0) { + str.append(","); + } + std::visit(vespalib::overload{ + [&str](size_t value)noexcept{ str.append(fmt("%zu", value)); }, + [&str](vespalib::stringref value)noexcept{ str.append(value); }}, item); + } + str.append("]"); + return str; +} + +vespalib::string to_str(const Inspector &value) { + if (!value.valid()) { + return ""; + } + vespalib::SimpleBuffer buf; + vespalib::slime::JsonFormat::encode(value, buf, true); + return buf.get().make_string(); +} + +void compare(const Blueprint &bp1, const Blueprint &bp2, bool expect_eq) { + auto ignore_cost = [expect_eq](const auto &path, const auto &a, const auto &b) { + if (!path.empty() && std::holds_alternative(path.back())) { + vespalib::stringref field = std::get(path.back()); + if (field == "cost") { + return true; + } + } + if (expect_eq) { + fprintf(stderr, " mismatch at %s: %s vs %s\n", path_to_str(path).c_str(), + to_str(a).c_str(), to_str(b).c_str()); + } + return false; + }; + Slime a; + Slime b; + bp1.asSlime(SlimeInserter(a)); + bp2.asSlime(SlimeInserter(b)); + if (expect_eq) { + EXPECT_TRUE(vespalib::slime::are_equal(a.get(), b.get(), ignore_cost)); + } else { + EXPECT_FALSE(vespalib::slime::are_equal(a.get(), b.get(), ignore_cost)); + } +} + void optimize_and_compare(Blueprint::UP top, Blueprint::UP expect) { - EXPECT_NOT_EQUAL(expect->asString(), top->asString()); + TEST_DO(compare(*top, *expect, false)); top = Blueprint::optimize(std::move(top)); - EXPECT_EQUAL(expect->asString(), top->asString()); + TEST_DO(compare(*top, *expect, true)); expect = Blueprint::optimize(std::move(expect)); - EXPECT_EQUAL(expect->asString(), top->asString()); + TEST_DO(compare(*expect, *top, true)); } void SourceBlenderTestFixture::addChildrenForSBTest(IntermediateBlueprint & parent) { @@ -1104,7 +1162,7 @@ TEST("require that children of near are not optimized") { addChild(addLeafs(std::make_unique(), {20, {0, true}})). addChild(addLeafs(std::make_unique(), {{0, true}, 30}))); top_up = Blueprint::optimize(std::move(top_up)); - EXPECT_EQUAL(expect_up->asString(), top_up->asString()); + TEST_DO(compare(*top_up, *expect_up, true)); } TEST("require that children of onear are not optimized") { @@ -1115,7 +1173,7 @@ TEST("require that children of onear are not optimized") { addChild(addLeafs(std::make_unique(), {20, {0, true}})). addChild(addLeafs(std::make_unique(), {{0, true}, 30}))); top_up = Blueprint::optimize(std::move(top_up)); - EXPECT_EQUAL(expect_up->asString(), top_up->asString()); + TEST_DO(compare(*top_up, *expect_up, true)); } TEST("require that ANDNOT without children is optimized to empty search") { diff --git a/searchlib/src/tests/queryeval/parallel_weak_and/parallel_weak_and_test.cpp b/searchlib/src/tests/queryeval/parallel_weak_and/parallel_weak_and_test.cpp index 2a59a578ec9..fa12b453d8c 100644 --- a/searchlib/src/tests/queryeval/parallel_weak_and/parallel_weak_and_test.cpp +++ b/searchlib/src/tests/queryeval/parallel_weak_and/parallel_weak_and_test.cpp @@ -599,6 +599,7 @@ TEST_F("require that asString() on blueprint works", BlueprintAsStringFixture) " tree_size: 2\n" " allow_termwise_eval: false\n" " }\n" + " cost: 1\n" " sourceId: 4294967295\n" " docid_limit: 0\n" " _weights: std::vector {\n" @@ -622,6 +623,7 @@ TEST_F("require that asString() on blueprint works", BlueprintAsStringFixture) " tree_size: 1\n" " allow_termwise_eval: true\n" " }\n" + " cost: 1\n" " sourceId: 4294967295\n" " docid_limit: 0\n" " }\n" diff --git a/searchlib/src/vespa/searchlib/queryeval/blueprint.cpp b/searchlib/src/vespa/searchlib/queryeval/blueprint.cpp index b71a579e097..71d53ade2f7 100644 --- a/searchlib/src/vespa/searchlib/queryeval/blueprint.cpp +++ b/searchlib/src/vespa/searchlib/queryeval/blueprint.cpp @@ -358,6 +358,7 @@ Blueprint::visitMembers(vespalib::ObjectVisitor &visitor) const visitor.visitInt("tree_size", state.tree_size()); visitor.visitBool("allow_termwise_eval", state.allow_termwise_eval()); visitor.closeStruct(); + visitor.visitFloat("cost", _cost); visitor.visitInt("sourceId", _sourceId); visitor.visitInt("docid_limit", _docid_limit); } -- cgit v1.2.3