From 9fe305c7d28e993e55c55427f377ae7e3251ea4f Mon Sep 17 00:00:00 2001 From: "Douglas B. Rumbaugh" Date: Fri, 6 Dec 2024 13:13:51 -0500 Subject: Interface update (#5) * Query Interface Adjustments/Refactoring Began the process of adjusting the query interface (and also the shard interface, to a lesser degree) to better accommodate the user. In particular the following changes have been made, 1. The number of necessary template arguments for the query type has been drastically reduced, while also removing the void pointers and manual delete functions from the interface. This was accomplished by requiring many of the sub-types associated with a query (parameters, etc.) to be nested inside the main query class, and by forcing the SHARD type to expose its associated record type. 2. User-defined query return types are now supported. Queries no longer are required to return strictly sets of records. Instead, the query now has LocalResultType and ResultType template parameters (which can be defaulted using a typedef in the Query type itself), allowing much more flexibility. Note that, at least for the short term, the LocalResultType must still expose the same is_deleted/is_tombstone interface as a Wrapped used to, as this is currently needed for delete filtering. A better approach to this is, hopefully, forthcoming. 3. Updated the ISAMTree.h shard and rangequery.h query to use the new interfaces, and adjusted the associated unit tests as well. 4. Dropped the unnecessary "get_data()" function from the ShardInterface concept. 5. Dropped the need to specify a record type in the ShardInterface concept. This is now handled using a required Shard::RECORD member of the Shard class itself, which should expose the name of the record type. * Updates to framework to support new Query/Shard interfaces Pretty extensive adjustments to the framework, particularly to the templates themselves, along with some type-renaming work, to support the new query and shard interfaces. Adjusted the external query interface to take an rvalue reference, rather than a pointer, to the query parameters. * Removed framework-level delete filtering This was causing some issues with the new query interface, and should probably be reworked anyway, so I'm temporarily (TM) removing the feature. * Updated benchmarks + remaining code for new interface --- tests/include/irs.h | 165 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 165 insertions(+) create mode 100644 tests/include/irs.h (limited to 'tests/include/irs.h') diff --git a/tests/include/irs.h b/tests/include/irs.h new file mode 100644 index 0000000..1c5be2c --- /dev/null +++ b/tests/include/irs.h @@ -0,0 +1,165 @@ +/* + * tests/include/irs.h + * + * Standardized unit tests for range queries against supporting + * shard types + * + * Copyright (C) 2023 Douglas Rumbaugh + * + * Distributed under the Modified BSD License. + * + * WARNING: This file must be included in the main unit test set + * after the definition of an appropriate Shard and R + * type. In particular, R needs to implement the key-value + * pair interface and Shard needs to support lower_bound. + * For other types of record and shard, you'll need to + * use a different set of unit tests. + */ +#pragma once + +#include "query/irs.h" +#include + +/* + * Uncomment these lines temporarily to remove errors in this file + * temporarily for development purposes. They should be removed prior + * to building, to ensure no duplicate definitions. These includes/defines + * should be included in the source file that includes this one, above the + * include statement. + */ +#include "shard/ISAMTree.h" +#include "query/irs.h" +#include "testing.h" +#include +#include +using namespace de; + +typedef Rec R; +typedef ISAMTree Shard; +typedef irs::Query> Query; + +static gsl_rng *g_rng; + +START_TEST(t_irs) +{ + auto buffer = create_sequential_mbuffer(100, 1000); + auto shard = Shard(buffer->get_buffer_view()); + + size_t k = 5; + irs::Query::Parameters parms; + parms.lower_bound = 300; + parms.upper_bound = 500; + parms.sample_size = k; + parms.rng = g_rng; + + auto local_query = irs::Query::local_preproc(&shard, &parms); + irs::Query::distribute_query(&parms, {local_query}, nullptr); + + auto result = irs::Query::local_query(&shard, local_query); + delete local_query; + + ck_assert_int_eq(result.size(), k); + for (size_t i=0; i(100, 1000); + + size_t k = 5; + irs::Query::Parameters parms; + parms.lower_bound = 300; + parms.upper_bound = 500; + parms.sample_size = k; + parms.rng = g_rng; + + { + auto view = buffer->get_buffer_view(); + auto query = irs::Query::local_preproc_buffer(&view, &parms); + irs::Query::distribute_query(&parms, {}, query); + auto result = irs::Query::local_query_buffer(query); + delete query; + + ck_assert_int_le(result.size(), k); + for (size_t i=0; i(100, 200); + auto buffer2 = create_sequential_mbuffer(400, 1000); + + auto shard1 = Shard(buffer1->get_buffer_view()); + auto shard2 = Shard(buffer2->get_buffer_view()); + + size_t k = 10; + irs::Query::Parameters parms; + parms.lower_bound = 150; + parms.upper_bound = 500; + parms.sample_size = k; + parms.rng = g_rng; + + /* necessary to store the alias structure */ + auto dummy_buffer_query = irs::Query::LocalQueryBuffer(); + dummy_buffer_query.buffer = nullptr; + dummy_buffer_query.sample_size = 0; + dummy_buffer_query.cutoff = 0; + dummy_buffer_query.global_parms = parms; + dummy_buffer_query.records = {}; + dummy_buffer_query.alias = nullptr; + + auto query1 = irs::Query::local_preproc(&shard1, &parms); + auto query2 = irs::Query::local_preproc(&shard2, &parms); + + irs::Query::distribute_query(&parms, {query1, query2}, &dummy_buffer_query); + + std::vector::LocalResultType>> results(2); + results[0] = irs::Query::local_query(&shard1, query1); + results[1] = irs::Query::local_query(&shard2, query2); + delete query1; + delete query2; + + ck_assert_int_eq(results[0].size() + results[1].size(), k); + + std::vector>> proc_results; + + for (size_t j=0; j>()); + for (size_t i=0; i::ResultType> result; + irs::Query::combine(proc_results, nullptr, result); + ck_assert_int_eq(result.size(), k); + + delete buffer1; + delete buffer2; +} +END_TEST + +static void inject_irs_tests(Suite *suite) { + g_rng = gsl_rng_alloc(gsl_rng_mt19937); + + TCase *irs = tcase_create("Independent Range Sampling Query Testing"); + tcase_add_test(irs, t_irs); + tcase_add_test(irs, t_buffer_irs); + tcase_add_test(irs, t_irs_merge); + suite_add_tcase(suite, irs); +} -- cgit v1.2.3