aboutsummaryrefslogtreecommitdiffstats
path: root/eval/src/tests/instruction
diff options
context:
space:
mode:
authorHåvard Pettersen <havardpe@yahooinc.com>2022-09-26 14:10:49 +0000
committerHåvard Pettersen <havardpe@yahooinc.com>2022-09-29 09:34:11 +0000
commita4842f1dc5f8d9b400d42bc10669eb1a9fcfb62d (patch)
treeae49e45ab7d06edea3ad10f522a0bdbb0e473f8c /eval/src/tests/instruction
parentbebaada169361ab757dbc89126f5ac8d55f7f8bb (diff)
simple join count optimization
Diffstat (limited to 'eval/src/tests/instruction')
-rw-r--r--eval/src/tests/instruction/simple_join_count/CMakeLists.txt9
-rw-r--r--eval/src/tests/instruction/simple_join_count/simple_join_count_test.cpp70
2 files changed, 79 insertions, 0 deletions
diff --git a/eval/src/tests/instruction/simple_join_count/CMakeLists.txt b/eval/src/tests/instruction/simple_join_count/CMakeLists.txt
new file mode 100644
index 00000000000..d1be148dc59
--- /dev/null
+++ b/eval/src/tests/instruction/simple_join_count/CMakeLists.txt
@@ -0,0 +1,9 @@
+# Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+vespa_add_executable(eval_simple_join_count_test_app TEST
+ SOURCES
+ simple_join_count_test.cpp
+ DEPENDS
+ vespaeval
+ GTest::GTest
+)
+vespa_add_test(NAME eval_simple_join_count_test_app COMMAND eval_simple_join_count_test_app)
diff --git a/eval/src/tests/instruction/simple_join_count/simple_join_count_test.cpp b/eval/src/tests/instruction/simple_join_count/simple_join_count_test.cpp
new file mode 100644
index 00000000000..a040a876609
--- /dev/null
+++ b/eval/src/tests/instruction/simple_join_count/simple_join_count_test.cpp
@@ -0,0 +1,70 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#include <vespa/eval/eval/fast_value.h>
+#include <vespa/eval/eval/simple_value.h>
+#include <vespa/eval/instruction/simple_join_count.h>
+#include <vespa/eval/eval/test/eval_fixture.h>
+#include <vespa/eval/eval/test/gen_spec.h>
+#include <vespa/vespalib/gtest/gtest.h>
+
+using namespace vespalib::eval;
+using namespace vespalib::eval::test;
+
+//-----------------------------------------------------------------------------
+
+struct FunInfo {
+ using LookFor = SimpleJoinCount;
+ uint64_t expected_dense_factor;
+ FunInfo(uint64_t expected_dense_factor_in)
+ : expected_dense_factor(expected_dense_factor_in) {}
+ void verify(const LookFor &fun) const {
+ EXPECT_TRUE(fun.result_is_mutable());
+ EXPECT_EQ(fun.dense_factor(), expected_dense_factor);
+ }
+};
+
+void verify_optimized_cell_types(const vespalib::string &expr, size_t expected_dense_factor = 1) {
+ CellTypeSpace types(CellTypeUtils::list_types(), 2);
+ EvalFixture::verify<FunInfo>(expr, {FunInfo(expected_dense_factor)}, types);
+}
+
+void verify_optimized(const vespalib::string &expr, size_t expected_dense_factor = 1) {
+ CellTypeSpace just_float({CellType::FLOAT}, 2);
+ EvalFixture::verify<FunInfo>(expr, {FunInfo(expected_dense_factor)}, just_float);
+}
+
+void verify_not_optimized(const vespalib::string &expr) {
+ CellTypeSpace just_float({CellType::FLOAT}, 2);
+ EvalFixture::verify<FunInfo>(expr, {}, just_float);
+}
+
+//-----------------------------------------------------------------------------
+
+TEST(SimpleJoinCount, expression_can_be_optimized) {
+ verify_optimized_cell_types("reduce(x5_2*x5_1,count)");
+ verify_optimized_cell_types("reduce(x5_2y3z4*x5_1z4a1,count)", 12);
+}
+
+TEST(SimpleJoinCount, join_operation_does_not_matter) {
+ verify_optimized("reduce(x5_2+x5_1,count)");
+ verify_optimized("reduce(x5_2-x5_1,count)");
+ verify_optimized("reduce(x5_2/x5_1,count)");
+}
+
+TEST(SimpleJoinCount, parameters_must_have_full_mapped_singledim_overlap) {
+ verify_not_optimized("reduce(x5_2y5_2*x5_1y5_2,count)");
+ verify_not_optimized("reduce(x5_2*y5_2,count)");
+ verify_not_optimized("reduce(x5_2y5_2*x5_1z5_2,count)");
+ verify_not_optimized("reduce(x5_2*y5,count)");
+ verify_not_optimized("reduce(x5*y5,count)");
+}
+
+TEST(SimpleJoinCount, similar_expressions_are_not_optimized) {
+ verify_not_optimized("reduce(x5_2y3z4*x5_1z4a1,count,x)");
+ verify_not_optimized("reduce(x5_2y3z4*x5_1z4a1,count,x,y,z)");
+ verify_not_optimized("reduce(x5_2y3*x5_1,sum)");
+}
+
+//-----------------------------------------------------------------------------
+
+GTEST_MAIN_RUN_ALL_TESTS()