-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d74ecc0
commit 5222c13
Showing
3 changed files
with
189 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include <fstream> | ||
#include <sstream> | ||
#include <vector> | ||
|
||
#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<double>; | ||
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<json>(data_json)).read(dataset::column<double>("x")); | ||
|
||
std::ifstream data_csv("data.csv"); | ||
auto y = df.load(dataset::input<csv>(data_csv)).read(dataset::column<double>("y")); | ||
|
||
auto z = x+y; | ||
|
||
auto all = df.all(); | ||
|
||
auto h_z = df.make(query::plan<h1d>(linax(20,90.0,110.0))) | ||
.fill(z) | ||
.book(all) | ||
.result(); | ||
|
||
std::ostringstream os; | ||
os << *h_z; | ||
std::cout << os.str() << std::endl; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<column<Val>(::varied)>. | ||
*/ | ||
template <typename Col> class series { | ||
|
||
public: | ||
using value_type = column::value_t<typename Col::action_type>; | ||
|
||
public: | ||
series(Col const &col); | ||
~series() = default; | ||
|
||
auto _get(lazy<selection::node> &sel) const | ||
-> lazy<query::series<value_type>>; | ||
|
||
auto _get(lazy<selection::node>::varied &sel) const -> | ||
typename lazy<query::series<value_type>>::varied; | ||
|
||
protected: | ||
Col m_column; | ||
}; | ||
|
||
} // namespace column | ||
|
||
} // namespace queryosity | ||
|
||
template <typename Col> | ||
queryosity::column::series<Col>::series(Col const &col) : m_column(col){}; | ||
|
||
template <typename Col> | ||
auto queryosity::column::series<Col>::_get(lazy<selection::node> &sel) const | ||
-> lazy<query::series<value_type>> { | ||
auto df = sel.m_df; | ||
return df->make(query::plan<query::series<value_type>>()) | ||
.fill(m_column) | ||
.book(sel); | ||
} | ||
|
||
template <typename Col> | ||
auto queryosity::column::series<Col>::_get(lazy<selection::node>::varied &sel) | ||
const -> typename lazy<query::series<value_type>>::varied { | ||
auto df = sel.nominal().m_df; | ||
return df->make(query::plan<query::series<value_type>>()) | ||
.fill(m_column) | ||
.book(sel); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
|
||
#pragma once | ||
|
||
#include <functional> | ||
#include <utility> | ||
#include <vector> | ||
|
||
#include "query.h" | ||
|
||
namespace queryosity { | ||
|
||
template <typename T> class query::booker { | ||
|
||
public: | ||
using query_type = T; | ||
|
||
public: | ||
template <typename... Args> booker(Args... args); | ||
~booker() = default; | ||
|
||
// copyable | ||
booker(const booker &) = default; | ||
booker &operator=(const booker &) = default; | ||
|
||
template <typename... Vals> | ||
auto add_columns(column::valued<Vals> const &...cols) const | ||
-> std::unique_ptr<booker<T>>; | ||
|
||
auto set_selection(const selection::node &sel) const -> std::unique_ptr<T>; | ||
|
||
protected: | ||
std::unique_ptr<T> make_query(); | ||
template <typename... Vals> | ||
void fill_query(column::valued<Vals> const &...cols); | ||
|
||
protected: | ||
std::function<std::unique_ptr<T>()> m_make_unique_query; | ||
std::vector<std::function<void(T &)>> m_add_columns; | ||
}; | ||
|
||
} // namespace queryosity | ||
|
||
template <typename T> | ||
template <typename... Args> | ||
queryosity::query::booker<T>::booker(Args... args) | ||
: m_make_unique_query(std::bind( | ||
[](Args... args) { return std::make_unique<T>(args...); }, args...)) { | ||
} | ||
|
||
template <typename T> | ||
template <typename... Vals> | ||
auto queryosity::query::booker<T>::add_columns( | ||
column::valued<Vals> const &...columns) const -> std::unique_ptr<booker<T>> { | ||
// use a fresh one with its current fills | ||
auto filled = std::make_unique<booker<T>>(*this); | ||
// add fills | ||
filled->fill_query(columns...); | ||
// return new book | ||
return filled; | ||
} | ||
|
||
template <typename T> | ||
template <typename... Vals> | ||
void queryosity::query::booker<T>::fill_query( | ||
column::valued<Vals> const &...columns) { | ||
// use a snapshot of its current calls | ||
m_add_columns.push_back(std::bind( | ||
[](T &cnt, column::valued<Vals> const &...cols) { | ||
cnt.enter_columns(cols...); | ||
}, | ||
std::placeholders::_1, std::cref(columns)...)); | ||
} | ||
|
||
template <typename T> | ||
auto queryosity::query::booker<T>::set_selection(const selection::node &sel) const | ||
-> std::unique_ptr<T> { | ||
// 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; | ||
} |