diff --git a/examples/example-multiple_datasets.cxx b/examples/example-multiple_datasets.cxx new file mode 100644 index 0000000..30d552f --- /dev/null +++ b/examples/example-multiple_datasets.cxx @@ -0,0 +1,42 @@ +#include +#include +#include + +#include "queryosity.h" +#include "queryosity/hist.h" +#include "queryosity/json.h" +#include "queryosity/csv.h" + +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 csv = qty::csv; +using h1d = qty::hist::hist; +using linax = qty::hist::axis::regular; + +int main() { + dataflow df(multithread::enable(10)); + + std::ifstream data_json("data.json"); + auto x = df.load(dataset::input(data_json)).read(dataset::column("x")); + + std::ifstream data_csv("data.csv"); + auto y = df.load(dataset::input(data_csv)).read(dataset::column("y")); + + auto z = x+y; + + auto all = df.all(); + + auto h_z = df.make(query::plan(linax(20,90.0,110.0))) + .fill(z) + .book(all) + .result(); + + std::ostringstream os; + os << *h_z; + std::cout << os.str() << std::endl; +} \ No newline at end of file diff --git a/include/queryosity/column_series.h b/include/queryosity/column_series.h new file mode 100644 index 0000000..444f1b3 --- /dev/null +++ b/include/queryosity/column_series.h @@ -0,0 +1,61 @@ +#pragma once + +#include "column.h" +#include "dataflow.h" +#include "lazy.h" +#include "lazy_varied.h" +#include "query_series.h" +#include "selection.h" + +namespace queryosity { + +namespace column { + +/** + * @brief Argumnet for column series. + * @tparam Col (Varied) lazy column node. + * @todo C++20: Use concept to require lazy(::varied)>. + */ +template class series { + +public: + using value_type = column::value_t; + +public: + series(Col const &col); + ~series() = default; + + auto _get(lazy &sel) const + -> lazy>; + + auto _get(lazy::varied &sel) const -> + typename lazy>::varied; + +protected: + Col m_column; +}; + +} // namespace column + +} // namespace queryosity + +template +queryosity::column::series::series(Col const &col) : m_column(col){}; + +template +auto queryosity::column::series::_get(lazy &sel) const + -> lazy> { + auto df = sel.m_df; + return df->make(query::plan>()) + .fill(m_column) + .book(sel); +} + +template +auto queryosity::column::series::_get(lazy::varied &sel) + const -> typename lazy>::varied { + auto df = sel.nominal().m_df; + return df->make(query::plan>()) + .fill(m_column) + .book(sel); +} \ No newline at end of file diff --git a/include/queryosity/query_booker.h b/include/queryosity/query_booker.h new file mode 100644 index 0000000..e8b7aaa --- /dev/null +++ b/include/queryosity/query_booker.h @@ -0,0 +1,86 @@ + +#pragma once + +#include +#include +#include + +#include "query.h" + +namespace queryosity { + +template class query::booker { + +public: + using query_type = T; + +public: + template booker(Args... args); + ~booker() = default; + + // copyable + booker(const booker &) = default; + booker &operator=(const booker &) = default; + + template + auto add_columns(column::valued const &...cols) const + -> std::unique_ptr>; + + auto set_selection(const selection::node &sel) const -> std::unique_ptr; + +protected: + std::unique_ptr make_query(); + template + void fill_query(column::valued const &...cols); + +protected: + std::function()> m_make_unique_query; + std::vector> m_add_columns; +}; + +} // namespace queryosity + +template +template +queryosity::query::booker::booker(Args... args) + : m_make_unique_query(std::bind( + [](Args... args) { return std::make_unique(args...); }, args...)) { +} + +template +template +auto queryosity::query::booker::add_columns( + column::valued const &...columns) const -> std::unique_ptr> { + // use a fresh one with its current fills + auto filled = std::make_unique>(*this); + // add fills + filled->fill_query(columns...); + // return new book + return filled; +} + +template +template +void queryosity::query::booker::fill_query( + column::valued const &...columns) { + // use a snapshot of its current calls + m_add_columns.push_back(std::bind( + [](T &cnt, column::valued const &...cols) { + cnt.enter_columns(cols...); + }, + std::placeholders::_1, std::cref(columns)...)); +} + +template +auto queryosity::query::booker::set_selection(const selection::node &sel) const + -> std::unique_ptr { + // call constructor + auto cnt = m_make_unique_query(); + // fill columns (if set) + for (const auto &fill_query : m_add_columns) { + fill_query(*cnt); + } + // book cnt at the selection + cnt->set_selection(sel); + return cnt; +} \ No newline at end of file