diff --git a/CMakeLists.txt b/CMakeLists.txt index 90e3493..4374aa2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,6 +42,9 @@ target_compile_options( $<$:-O0> $<$:-ggdb3> ) +find_package(Threads REQUIRED) +target_link_libraries(queryosity INTERFACE Threads::Threads) + if (QUERYOSITY_INSTALL) include(CMakePackageConfigHelpers) include(GNUInstallDirs) @@ -88,14 +91,7 @@ if (QUERYOSITY_INSTALL) endif() -if (QUERYOSITY_TESTS OR QUERYOSITY_EXAMPLES) - - # boost - find_package(Boost REQUIRED) - include_directories(${Boost_INCLUDE_DIRS}) - link_directories(${Boost_LIBRARY_DIRS}) - - +if (QUERYOSITY_EXTENSIONS OR QUERYOSITY_TESTS OR QUERYOSITY_EXAMPLES) add_subdirectory("extensions") endif() diff --git a/README.md b/README.md index 5d4dbce..39dc136 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ namespace query = qty::query; using json = qty::json; using h1d = qty::hist::hist; -using linax = qty::hist::axis::linear; +using linax = qty::hist::axis::regular; int main() { diff --git a/docs/pages/example.md b/docs/pages/example.md index 4bd7b11..21c1d06 100644 --- a/docs/pages/example.md +++ b/docs/pages/example.md @@ -21,7 +21,7 @@ namespace query = qty::query; using json = qty::json; using h1d = qty::hist::hist; -using linax = qty::hist::axis::linear; +using linax = qty::hist::axis::regular; int main() { diff --git a/docs/pages/guide.md b/docs/pages/guide.md index 1c14762..eaedd55 100644 --- a/docs/pages/guide.md +++ b/docs/pages/guide.md @@ -162,7 +162,7 @@ Subsequently, the plan can be filled with input columns and booked at a selectio @cpp using h1d = qty::hist::hist; using h2d = qty::hist::hist; -using linax = qty::hist::axis::linear; +using linax = qty::hist::axis::regular; // instantiate a 1d histogram query filled with x over all entries auto q = df.make(query::plan(linax(100,0.0,1.0))).fill(x).book(inclusive); diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt new file mode 100644 index 0000000..297245f --- /dev/null +++ b/examples/CMakeLists.txt @@ -0,0 +1,8 @@ +if (QUERYOSITY_EXAMPLES) + + add_executable(example-hello_world ./example-hello_world.cxx) + target_compile_features(example-hello_world PUBLIC cxx_std_17) + target_link_libraries(example-hello_world queryosity::extensions pthread ${Boost_LIBRARIES}) + add_test(NAME example-hello_world COMMAND example-hello_world) + +endif() diff --git a/examples/example-hello_world.cxx b/examples/example-hello_world.cxx new file mode 100644 index 0000000..c09cd14 --- /dev/null +++ b/examples/example-hello_world.cxx @@ -0,0 +1,47 @@ +#include "queryosity/json.h" +#include "queryosity/hist.h" + +#include "queryosity.h" + +#include +#include +#include + +using dataflow = qty::dataflow; +namespace multithread = qty::multithread; +namespace dataset = qty::dataset; +namespace column = qty::column; +namespace query = qty::query; + +using json = qty::json; +using h1d = qty::hist::hist; +using linax = qty::hist::axis::regular; + +int main() +{ + + dataflow df(multithread::enable(10)); + + std::ifstream data("data.json"); + auto [x, w] = df.read( + dataset::input(data), + dataset::column>("x_nom"), + dataset::column("w_nom")); + + auto zero = df.define(column::constant(0)); + auto x0 = x[zero]; + + auto sel = df.weight(w).filter( + column::expression([](std::vector const &v) + { return v.size(); }), + x); + + auto h_x0_w = df.make( + query::plan(linax(100, 0.0, 1.0))) + .fill(x0) + .book(sel) + .result(); + + // std::ostringstream os; os << *h_x0_w; + // std::cout << os.str() << std::endl; +} \ No newline at end of file diff --git a/extensions/CMakeLists.txt b/extensions/CMakeLists.txt index 3456f2b..c3588a8 100644 --- a/extensions/CMakeLists.txt +++ b/extensions/CMakeLists.txt @@ -17,6 +17,10 @@ target_compile_options( $<$:-O0> $<$:-ggdb3> ) +# boost::histogram +find_package(Boost REQUIRED) + +# nlohmann::json include(FetchContent) FetchContent_Declare(json URL https://github.com/nlohmann/json/releases/download/v3.11.3/json.tar.xz) FetchContent_MakeAvailable(json) @@ -26,7 +30,7 @@ FetchContent_MakeAvailable(csv) target_include_directories( queryosity_extensions - PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} + PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${Boost_INCLUDE_DIRS} ) include(ExternalProject) diff --git a/extensions/queryosity/col.h b/extensions/queryosity/col.h deleted file mode 100644 index 4a6bd2c..0000000 --- a/extensions/queryosity/col.h +++ /dev/null @@ -1,45 +0,0 @@ -#pragma once - -#include -#include - -#include "queryosity.h" - -namespace queryosity { - -template -class col : public queryosity::query::definition(T)> { - -public: - col() = default; - ~col() = default; - - virtual void fill(queryosity::column::observable, double) override; - virtual std::vector result() const override; - virtual std::vector - merge(std::vector> const &results) const override; - -protected: - std::vector m_result; -}; - -} // namespace queryosity - -template -void queryosity::col::fill(queryosity::column::observable x, double) { - m_result.push_back(x.value()); -} - -template std::vector queryosity::col::result() const { - return m_result; -} - -template -std::vector -queryosity::col::merge(std::vector> const &results) const { - std::vector merged; - for (const auto &result : results) { - merged.insert(merged.end(), result.begin(), result.end()); - } - return merged; -} \ No newline at end of file diff --git a/include/queryosity.h b/include/queryosity.h index db153d7..d65072f 100644 --- a/include/queryosity.h +++ b/include/queryosity.h @@ -16,6 +16,7 @@ #include "queryosity/query_aggregation.h" #include "queryosity/query_definition.h" +#include "queryosity/query_series.h" #include "queryosity/dataflow.h" diff --git a/include/queryosity/dataflow.h b/include/queryosity/dataflow.h index 2a46046..76ee80c 100644 --- a/include/queryosity/dataflow.h +++ b/include/queryosity/dataflow.h @@ -134,8 +134,8 @@ class dataflow { * @return Varied lazy column. */ template - auto define(column::expression const &expr, Cols const &...cols) - -> typename lazy>::varied; + auto define(column::expression const &expr, Cols const &...cols) -> + typename lazy>::varied; /** * @brief Define a custom column. @@ -158,8 +158,8 @@ class dataflow { * @return Varied lazy column. */ template - auto define(column::definition const &defn, Cols const &...cols) - -> typename lazy::varied; + auto define(column::definition const &defn, Cols const &...cols) -> + typename lazy::varied; /** * @brief Initiate a cutflow. @@ -245,10 +245,14 @@ class dataflow { -> lazy>>; template auto _define(Args &&...args); - template auto _define(column::definition const &defn) -> todo>; + template + auto _define(column::definition const &defn) + -> todo>; template auto _equate(Fn fn); - template auto _equate(column::expression const &expr) -> todo>> ; + template + auto _equate(column::expression const &expr) + -> todo>>; template auto _select(lazy const &col) -> lazy; @@ -416,8 +420,8 @@ auto queryosity::dataflow::define( template auto queryosity::dataflow::define( - queryosity::column::definition const &defn, Cols const &...cols) - -> typename lazy::varied { + queryosity::column::definition const &defn, Cols const &...cols) -> + typename lazy::varied { return this->_define(defn).template evaluate(cols...); } @@ -430,8 +434,8 @@ auto queryosity::dataflow::define( template auto queryosity::dataflow::define( - queryosity::column::expression const &expr, Cols const &...cols) - -> typename lazy>::varied { + queryosity::column::expression const &expr, Cols const &...cols) -> + typename lazy>::varied { return this->_equate(expr).template evaluate(cols...); } @@ -609,13 +613,13 @@ auto queryosity::dataflow::_define(Args &&...args) { template auto queryosity::dataflow::_define( - queryosity::column::definition const &defn) -> todo> { + queryosity::column::definition const &defn) + -> todo> { return defn._define(*this); } -template auto queryosity::dataflow::_equate(Fn fn){ - return todo>>( +template auto queryosity::dataflow::_equate(Fn fn) { + return todo>>( *this, ensemble::invoke( [fn](dataset::player *plyr) { return plyr->template equate(fn); }, @@ -624,7 +628,8 @@ template auto queryosity::dataflow::_equate(Fn fn){ template auto queryosity::dataflow::_equate( - queryosity::column::expression const &expr) -> todo>> { + queryosity::column::expression const &expr) + -> todo>> { return expr._equate(*this); } diff --git a/include/queryosity/lazy.h b/include/queryosity/lazy.h index 7e3ecad..e8a3480 100644 --- a/include/queryosity/lazy.h +++ b/include/queryosity/lazy.h @@ -10,133 +10,146 @@ #include "detail.h" #include "systematic_resolver.h" -namespace queryosity { - -// mixin class to conditionally add a member variable -template -struct result_if_aggregation {}; - -// Specialization for types satisfying is_query -template -struct result_if_aggregation< - Action, std::enable_if_t>> { - using result_type = decltype(std::declval().result()); - result_if_aggregation() : m_merged(false) {} - virtual ~result_if_aggregation() = default; - -protected: - result_type m_result; - bool m_merged; -}; - -/** - * @ingroup api - * @brief Lazy action over dataset. - * @tparam Action Action to be performed. - */ -template -class lazy : public dataflow::node, - public ensemble::slotted, - public systematic::resolver>, - public result_if_aggregation { - -public: - class varied; - -public: - using action_type = Action; - -public: - friend class dataflow; - template friend class lazy; - -public: - lazy(dataflow &df, std::vector const &slots) - : dataflow::node(df), m_slots(slots) {} - - template - lazy(dataflow &df, std::vector const &slots); - template - lazy(dataflow &df, std::vector> const &slots); - - lazy(const lazy &) = default; - lazy &operator=(const lazy &) = default; - - lazy(lazy &&) = default; - lazy &operator=(lazy &&) = default; - - virtual ~lazy() = default; - - virtual std::vector const &get_slots() const override; - - virtual void set_variation(const std::string &var_name, lazy var) override; - - virtual lazy &nominal() override; - virtual lazy &variation(const std::string &var_name) override; - virtual lazy const &nominal() const override; - virtual lazy const &variation(const std::string &var_name) const override; - - virtual bool has_variation(const std::string &var_name) const override; - virtual std::set get_variation_names() const override; - - template , bool> = false> - auto to() const -> lazy>; - - template auto filter(lazy const &col) const; - template auto weight(lazy const &col) const; - - template auto filter(Col const &col) const; - template auto weight(Col const &col) const; - - template - auto filter(queryosity::column::expression const &expr, - Cols const &...cols) const; - - template - auto weight(queryosity::column::expression const &expr, - Cols const &...cols) const; - - template auto book(Agg &&agg) const; - template auto book(Aggs &&...aggs) const; - - template , - bool> = false> - auto result() -> decltype(std::declval().result()); - - template , - bool> = false> - auto operator->() -> decltype(std::declval().result()) { - return this->result(); - } +namespace queryosity +{ + + // mixin class to conditionally add a member variable + template + struct result_if_aggregation + { + }; + + // Specialization for types satisfying is_query + template + struct result_if_aggregation< + Action, std::enable_if_t>> + { + using result_type = decltype(std::declval().result()); + result_if_aggregation() : m_merged(false) {} + virtual ~result_if_aggregation() = default; + + protected: + result_type m_result; + bool m_merged; + }; + + /** + * @ingroup api + * @brief Lazy action over dataset. + * @tparam Action Action to be performed. + */ + template + class lazy : public dataflow::node, + public ensemble::slotted, + public systematic::resolver>, + public result_if_aggregation + { + + public: + class varied; + + public: + using action_type = Action; + + public: + friend class dataflow; + template + friend class lazy; + + public: + lazy(dataflow &df, std::vector const &slots) + : dataflow::node(df), m_slots(slots) {} + + template + lazy(dataflow &df, std::vector const &slots); + template + lazy(dataflow &df, std::vector> const &slots); + + lazy(const lazy &) = default; + lazy &operator=(const lazy &) = default; + + lazy(lazy &&) = default; + lazy &operator=(lazy &&) = default; + + virtual ~lazy() = default; + + virtual std::vector const &get_slots() const override; + + virtual void set_variation(const std::string &var_name, lazy var) override; + + virtual lazy &nominal() override; + virtual lazy &variation(const std::string &var_name) override; + virtual lazy const &nominal() const override; + virtual lazy const &variation(const std::string &var_name) const override; + + virtual bool has_variation(const std::string &var_name) const override; + virtual std::set get_variation_names() const override; + + template , bool> = false> + auto to() const -> lazy>; + + template + auto filter(lazy const &col) const; + template + auto weight(lazy const &col) const; + + template + auto filter(Col const &col) const; + template + auto weight(Col const &col) const; + + template + auto filter(queryosity::column::expression const &expr, + Cols const &...cols) const; + + template + auto weight(queryosity::column::expression const &expr, + Cols const &...cols) const; + + template + auto book(Agg &&agg) const; + template + auto book(Aggs &&...aggs) const; + + template , + bool> = false> + auto result() -> decltype(std::declval().result()); + + template , + bool> = false> + auto operator->() -> decltype(std::declval().result()) + { + return this->result(); + } - DEFINE_LAZY_UNARY_OP(logical_not, !) - DEFINE_LAZY_UNARY_OP(minus, -) - DEFINE_LAZY_BINARY_OP(equality, ==) - DEFINE_LAZY_BINARY_OP(inequality, !=) - DEFINE_LAZY_BINARY_OP(addition, +) - DEFINE_LAZY_BINARY_OP(subtraction, -) - DEFINE_LAZY_BINARY_OP(multiplication, *) - DEFINE_LAZY_BINARY_OP(division, /) - DEFINE_LAZY_BINARY_OP(logical_or, ||) - DEFINE_LAZY_BINARY_OP(logical_and, &&) - DEFINE_LAZY_BINARY_OP(greater_than, >) - DEFINE_LAZY_BINARY_OP(less_than, <) - DEFINE_LAZY_BINARY_OP(greater_than_or_equal_to, >=) - DEFINE_LAZY_BINARY_OP(less_than_or_equal_to, <=) - DEFINE_LAZY_INDEX_OP() - -protected: - template , - bool> = false> - void merge_results(); - -protected: - std::vector m_slots; -}; + DEFINE_LAZY_UNARY_OP(logical_not, !) + DEFINE_LAZY_UNARY_OP(minus, -) + DEFINE_LAZY_BINARY_OP(equality, ==) + DEFINE_LAZY_BINARY_OP(inequality, !=) + DEFINE_LAZY_BINARY_OP(addition, +) + DEFINE_LAZY_BINARY_OP(subtraction, -) + DEFINE_LAZY_BINARY_OP(multiplication, *) + DEFINE_LAZY_BINARY_OP(division, /) + DEFINE_LAZY_BINARY_OP(logical_or, ||) + DEFINE_LAZY_BINARY_OP(logical_and, &&) + DEFINE_LAZY_BINARY_OP(greater_than, >) + DEFINE_LAZY_BINARY_OP(less_than, <) + DEFINE_LAZY_BINARY_OP(greater_than_or_equal_to, >=) + DEFINE_LAZY_BINARY_OP(less_than_or_equal_to, <=) + DEFINE_LAZY_INDEX_OP() + + protected: + template , + bool> = false> + void merge_results(); + + protected: + std::vector m_slots; + }; } // namespace queryosity @@ -148,10 +161,12 @@ template template queryosity::lazy::lazy(dataflow &df, std::vector const &slots) - : dataflow::node(df) { + : dataflow::node(df) +{ m_slots.clear(); m_slots.reserve(slots.size()); - for (auto slot : slots) { + for (auto slot : slots) + { m_slots.push_back(static_cast(slot)); } } @@ -160,57 +175,68 @@ template template queryosity::lazy::lazy( dataflow &df, std::vector> const &slots) - : dataflow::node(df) { + : dataflow::node(df) +{ m_slots.clear(); m_slots.reserve(slots.size()); - for (auto const &slot : slots) { + for (auto const &slot : slots) + { m_slots.push_back(static_cast(slot.get())); } } template -std::vector const &queryosity::lazy::get_slots() const { +std::vector const &queryosity::lazy::get_slots() const +{ return this->m_slots; } template -void queryosity::lazy::set_variation(const std::string &, lazy) { +void queryosity::lazy::set_variation(const std::string &, lazy) +{ // should never be called throw std::logic_error("cannot set variation to a nominal-only action"); } -template auto queryosity::lazy::nominal() -> lazy & { +template +auto queryosity::lazy::nominal() -> lazy & +{ // this is nominal return *this; } template -auto queryosity::lazy::variation(const std::string &) -> lazy & { +auto queryosity::lazy::variation(const std::string &) -> lazy & +{ // propagation of variations must occur "transparently" return *this; } template -auto queryosity::lazy::nominal() const -> lazy const & { +auto queryosity::lazy::nominal() const -> lazy const & +{ // this is nominal return *this; } template auto queryosity::lazy::variation(const std::string &) const - -> lazy const & { + -> lazy const & +{ // propagation of variations must occur "transparently" return *this; } template -std::set queryosity::lazy::get_variation_names() const { +std::set queryosity::lazy::get_variation_names() const +{ // no variations to list return std::set(); } template -bool queryosity::lazy::has_variation(const std::string &) const { +bool queryosity::lazy::has_variation(const std::string &) const +{ // always false return false; } @@ -218,11 +244,15 @@ bool queryosity::lazy::has_variation(const std::string &) const { template template , bool>> -auto queryosity::lazy::to() const -> lazy> { +auto queryosity::lazy::to() const -> lazy> +{ if constexpr (std::is_same_v> || - std::is_base_of_v>) { + std::is_base_of_v>) + { return lazy>(*this->m_df, this->get_slots()); - } else { + } + else + { return lazy>( *this->m_df, this->m_df->template _convert(*this).get_slots()); } @@ -230,10 +260,14 @@ auto queryosity::lazy::to() const -> lazy> { template template -auto queryosity::lazy::filter(lazy const &col) const { - if constexpr (std::is_base_of_v) { +auto queryosity::lazy::filter(lazy const &col) const +{ + if constexpr (std::is_base_of_v) + { return this->m_df->template _select(*this, col); - } else { + } + else + { static_assert(std::is_base_of_v, "filter must be called from a selection"); } @@ -241,10 +275,14 @@ auto queryosity::lazy::filter(lazy const &col) const { template template -auto queryosity::lazy::weight(lazy const &col) const { - if constexpr (std::is_base_of_v) { +auto queryosity::lazy::weight(lazy const &col) const +{ + if constexpr (std::is_base_of_v) + { return this->m_df->template _select(*this, col); - } else { + } + else + { static_assert(std::is_base_of_v, "filter must be called from a selection"); } @@ -252,15 +290,20 @@ auto queryosity::lazy::weight(lazy const &col) const { template template -auto queryosity::lazy::filter(Col const &col) const { - if constexpr (std::is_base_of_v) { +auto queryosity::lazy::filter(Col const &col) const +{ + if constexpr (std::is_base_of_v) + { using varied_type = typename lazy::varied; auto syst = varied_type(this->filter(col.nominal())); - for (auto const &var_name : col.get_variation_names()) { + for (auto const &var_name : col.get_variation_names()) + { syst.set_variation(var_name, this->filter(col.variation(var_name))); } return syst; - } else { + } + else + { static_assert(std::is_base_of_v, "filter must be called from a selection"); } @@ -268,15 +311,20 @@ auto queryosity::lazy::filter(Col const &col) const { template template -auto queryosity::lazy::weight(Col const &col) const { - if constexpr (std::is_base_of_v) { +auto queryosity::lazy::weight(Col const &col) const +{ + if constexpr (std::is_base_of_v) + { using varied_type = typename lazy::varied; auto syst = varied_type(this->weight(col.nominal())); - for (auto const &var_name : col.get_variation_names()) { + for (auto const &var_name : col.get_variation_names()) + { syst.set_variation(var_name, this->weight(col.variation(var_name))); } return syst; - } else { + } + else + { static_assert(std::is_base_of_v, "weight must be called from a selection"); } @@ -286,11 +334,15 @@ template template auto queryosity::lazy::filter( queryosity::column::expression const &expr, - Cols const &...cols) const { - if constexpr (std::is_base_of_v) { + Cols const &...cols) const +{ + if constexpr (std::is_base_of_v) + { auto col = this->m_df->define(expr, cols...); return this->filter(col); - } else { + } + else + { static_assert(std::is_base_of_v, "filter must be called from a selection"); } @@ -300,11 +352,15 @@ template template auto queryosity::lazy::weight( queryosity::column::expression const &expr, - Cols const &...cols) const { - if constexpr (std::is_base_of_v) { + Cols const &...cols) const +{ + if constexpr (std::is_base_of_v) + { auto col = this->m_df->define(expr, cols...); return this->weight(col); - } else { + } + else + { static_assert(std::is_base_of_v, "filter must be called from a selection"); } @@ -312,7 +368,8 @@ auto queryosity::lazy::weight( template template -auto queryosity::lazy::book(Agg &&agg) const { +auto queryosity::lazy::book(Agg &&agg) const +{ static_assert(std::is_base_of_v, "book must be called from a selection"); return agg.book(*this); @@ -320,7 +377,8 @@ auto queryosity::lazy::book(Agg &&agg) const { template template -auto queryosity::lazy::book(Aggs &&...aggs) const { +auto queryosity::lazy::book(Aggs &&...aggs) const +{ static_assert(std::is_base_of_v, "book must be called from a selection"); return std::make_tuple((aggs.book(*this), ...)); @@ -331,7 +389,8 @@ template < typename V, std::enable_if_t, bool>> auto queryosity::lazy::result() - -> decltype(std::declval().result()) { + -> decltype(std::declval().result()) +{ this->m_df->analyze(); this->merge_results(); return this->m_result; @@ -341,18 +400,23 @@ template template < typename V, std::enable_if_t, bool> e> -void queryosity::lazy::merge_results() { +void queryosity::lazy::merge_results() +{ if (this->m_merged) return; auto model = this->get_slot(0); using result_type = decltype(model->result()); const auto nslots = this->size(); - if (nslots == 1) { + if (nslots == 1) + { this->m_result = model->result(); - } else { + } + else + { std::vector results; results.reserve(nslots); - for (size_t islot = 0; islot < nslots; ++islot) { + for (size_t islot = 0; islot < nslots; ++islot) + { results.push_back(std::move(this->get_slot(islot)->result())); } this->m_result = model->merge(results); diff --git a/include/queryosity/lazy_varied.h b/include/queryosity/lazy_varied.h index b3e9719..bd3dd01 100644 --- a/include/queryosity/lazy_varied.h +++ b/include/queryosity/lazy_varied.h @@ -71,13 +71,13 @@ class lazy::varied : public dataflow::node, std::enable_if_t, bool> = false> auto book(Aggs &&...aggs); - template , - bool> = false> + template < + typename V = Act, + std::enable_if_t, bool> = false> auto operator[](const std::string &var_name) -> lazy &; - template , - bool> = false> + template < + typename V = Act, + std::enable_if_t, bool> = false> auto operator[](const std::string &var_name) const -> lazy const &; DECLARE_LAZY_VARIED_UNARY_OP(-) @@ -244,9 +244,8 @@ auto queryosity::lazy::varied::book(Aggs &&...aggs) { } template -template < - typename V, - std::enable_if_t, bool>> +template , bool>> auto queryosity::lazy::varied::operator[](const std::string &var_name) -> lazy & { if (!this->has_variation(var_name)) { @@ -256,9 +255,8 @@ auto queryosity::lazy::varied::operator[](const std::string &var_name) } template -template < - typename V, - std::enable_if_t, bool>> +template , bool>> auto queryosity::lazy::varied::operator[]( const std::string &var_name) const -> lazy const & { if (!this->has_variation(var_name)) { diff --git a/include/queryosity/query_series.h b/include/queryosity/query_series.h new file mode 100644 index 0000000..7c8f717 --- /dev/null +++ b/include/queryosity/query_series.h @@ -0,0 +1,65 @@ +#pragma once + +#include "query_definition.h" + +#include + +namespace queryosity { + +namespace query { + +template +class series : public queryosity::query::definition(T)> { + +public: + series() = default; + ~series() = default; + + virtual void initialize(unsigned int, unsigned long long, + unsigned long long) override; + virtual void fill(queryosity::column::observable, double) override; + virtual void finalize(unsigned int) override; + virtual std::vector result() const override; + virtual std::vector + merge(std::vector> const &results) const override; + +protected: + std::vector m_result; +}; + +} // namespace query + +} // namespace queryosity + +template +void queryosity::query::series::initialize(unsigned int, + unsigned long long begin, + unsigned long long end) { + m_result.reserve(end - begin); +} + +template +void queryosity::query::series::fill(queryosity::column::observable x, + double) { + m_result.push_back(x.value()); +} + +template +void queryosity::query::series::finalize(unsigned int) { + m_result.resize(m_result.size()); +} + +template +std::vector queryosity::query::series::result() const { + return m_result; +} + +template +std::vector queryosity::query::series::merge( + std::vector> const &results) const { + std::vector merged; + for (const auto &result : results) { + merged.insert(merged.end(), result.begin(), result.end()); + } + return merged; +} \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 845c53b..81b44cd 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,11 +1,4 @@ if (QUERYOSITY_TESTS) - - find_package(Threads REQUIRED) - - find_package(Boost REQUIRED) - include_directories(${Boost_INCLUDE_DIRS}) - link_directories(${Boost_LIBRARY_DIRS}) - #add_executable(test-definition ./test-definition.cxx) #target_compile_features(test-definition PUBLIC cxx_std_17) #target_link_libraries(test-definition queryosity::extensions pthread ${Boost_LIBRARIES}) diff --git a/tests/test-multithreading.cxx b/tests/test-multithreading.cxx index 33513e6..7dcc590 100644 --- a/tests/test-multithreading.cxx +++ b/tests/test-multithreading.cxx @@ -1,15 +1,13 @@ #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN #include "doctest.h" -#include -#include +#include +#include "queryosity/json.h" #include "queryosity.h" -#include - -#include "queryosity/col.h" -#include "queryosity/json.h" +#include +#include using dataflow = qty::dataflow; namespace multithread = qty::multithread; @@ -34,7 +32,7 @@ std::vector get_queryosity_result(const nlohmann::json &random_data, auto entry_value = ds.read(dataset::column("value")); auto all = df.define(column::constant(true)); auto incl = df.filter(all); - auto col = df.make(query::plan>()); + auto col = df.make(query::plan>()); col = col.fill(entry_value); return incl.book(col).result(); }