Skip to content

Commit

Permalink
Merge pull request #672 from finos/view-config
Browse files Browse the repository at this point in the history
Add view config class in C++
  • Loading branch information
texodus authored Jul 30, 2019
2 parents 4b4b7ea + 879b77c commit e03dcd4
Show file tree
Hide file tree
Showing 23 changed files with 965 additions and 882 deletions.
16 changes: 16 additions & 0 deletions cmake/ordered-map.txt.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
cmake_minimum_required(VERSION 2.8.2)

project(ordered-map-download NONE)

include(ExternalProject)
ExternalProject_Add(ordered-map
GIT_REPOSITORY https://github.com/Tessil/ordered-map.git
GIT_TAG master
SOURCE_DIR "${CMAKE_BINARY_DIR}/ordered-map-src"
BINARY_DIR "${CMAKE_BINARY_DIR}/ordered-map-build"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
CMAKE_ARGS "-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}"
)
2 changes: 2 additions & 0 deletions cpp/perspective/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ elseif(PSP_CPP_BUILD OR PSP_PYTHON_BUILD)
endif()

psp_build_dep("hopscotch" "../../cmake/hopscotch.txt.in")
psp_build_dep("ordered-map" "../../cmake/ordered-map.txt.in")

#####################

Expand Down Expand Up @@ -346,6 +347,7 @@ set (SOURCE_FILES
src/cpp/utils.cpp
src/cpp/update_task.cpp
src/cpp/view.cpp
src/cpp/view_config.cpp
src/cpp/vocab.cpp
)

Expand Down
46 changes: 0 additions & 46 deletions cpp/perspective/src/cpp/aggspec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,6 @@ t_col_name_type::t_col_name_type(const std::string& name, t_dtype type)

t_aggspec::t_aggspec() {}

t_aggspec::t_aggspec(const t_aggspec_recipe& v) {
m_name = v.m_name;
m_disp_name = v.m_name;
m_agg = v.m_agg;

for (const auto& d : v.m_dependencies) {
m_dependencies.push_back(d);
}

for (const auto& d : v.m_odependencies) {
m_odependencies.push_back(d);
}

m_sort_type = v.m_sort_type;
m_agg_one_idx = v.m_agg_one_idx;
m_agg_two_idx = v.m_agg_two_idx;
m_agg_one_weight = v.m_agg_one_weight;
m_agg_two_weight = v.m_agg_two_weight;
m_invmode = v.m_invmode;
}

t_aggspec::t_aggspec(
const std::string& name, t_aggtype agg, const std::vector<t_dep>& dependencies)
: m_name(name)
Expand Down Expand Up @@ -407,29 +386,4 @@ t_aggspec::get_first_depname() const {
return m_dependencies[0].name();
}

t_aggspec_recipe
t_aggspec::get_recipe() const {
t_aggspec_recipe rv;
rv.m_name = m_name;
rv.m_disp_name = m_name;
rv.m_agg = m_agg;

for (const auto& d : m_dependencies) {
rv.m_dependencies.push_back(d.get_recipe());
}

for (const auto& d : m_odependencies) {
rv.m_odependencies.push_back(d.get_recipe());
}

rv.m_sort_type = m_sort_type;
rv.m_agg_one_idx = m_agg_one_idx;
rv.m_agg_two_idx = m_agg_two_idx;
rv.m_agg_one_weight = m_agg_one_weight;
rv.m_agg_two_weight = m_agg_two_weight;
rv.m_invmode = m_invmode;

return rv;
}

} // end namespace perspective
208 changes: 37 additions & 171 deletions cpp/perspective/src/cpp/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,78 +12,7 @@

namespace perspective {

t_config_recipe::t_config_recipe()
: m_child_pkey_column("psp_pkey") {}

t_config::t_config() {}

t_config::t_config(const t_config_recipe& r)
: m_detail_columns(r.m_detail_columns)
, m_totals(r.m_totals)
, m_combiner(r.m_combiner)
, m_handle_nan_sort(r.m_handle_nan_sort)
, m_parent_pkey_column(r.m_parent_pkey_column)
, m_child_pkey_column(r.m_child_pkey_column)
, m_grouping_label_column(r.m_grouping_label_column)
, m_fmode(r.m_fmode)
, m_filter_exprs(r.m_filter_exprs)

{
for (const auto& v : r.m_row_pivots) {
m_row_pivots.push_back(t_pivot(v));
}

for (const auto& v : r.m_col_pivots) {
m_col_pivots.push_back(t_pivot(v));
}

for (const auto& v : r.m_aggregates) {
m_aggregates.push_back(t_aggspec(v));
}

if (m_fmode == FMODE_SIMPLE_CLAUSES) {
for (const auto& v : r.m_fterms) {
m_fterms.push_back(t_fterm(v));
}
}

std::vector<std::string> sort_pivot;
std::vector<std::string> sort_pivot_by;

for (const auto& v : r.m_sortby) {
sort_pivot.push_back(v.first);
sort_pivot_by.push_back(v.second);
}

setup(m_detail_columns, sort_pivot, sort_pivot_by);
}

t_config::t_config(const std::vector<t_pivot>& row_pivots,
const std::vector<t_pivot>& col_pivots, const std::vector<t_aggspec>& aggregates,
const std::vector<std::string>& detail_columns, const t_totals totals,
const std::vector<std::string>& sort_pivot, const std::vector<std::string>& sort_pivot_by,
t_filter_op combiner, const std::vector<t_fterm>& fterms, bool handle_nan_sort,
const std::string& parent_pkey_column, const std::string& child_pkey_column,
const std::string& grouping_label_column, t_fmode fmode,
const std::vector<std::string>& filter_exprs, const std::string& grand_agg_str)
: m_row_pivots(row_pivots)
, m_col_pivots(col_pivots)
, m_aggregates(aggregates)
, m_detail_columns(detail_columns)
, m_totals(totals)
, m_combiner(combiner)
, m_fterms(fterms)
, m_handle_nan_sort(handle_nan_sort)
, m_parent_pkey_column(parent_pkey_column)
, m_child_pkey_column(child_pkey_column)
, m_grouping_label_column(grouping_label_column)
, m_fmode(fmode)
, m_filter_exprs(filter_exprs)
, m_grand_agg_str(grand_agg_str) {
setup(detail_columns, sort_pivot, sort_pivot_by);
}

// view config
// Construct view config
t_config::t_config(const std::vector<std::string>& row_pivots,
const std::vector<std::string>& col_pivots, const std::vector<t_aggspec>& aggregates,
const std::vector<t_sortspec>& sortspecs, const std::vector<t_sortspec>& col_sortspecs,
Expand All @@ -104,59 +33,56 @@ t_config::t_config(const std::vector<std::string>& row_pivots,
}
};

t_config::t_config(
const std::vector<t_pivot>& row_pivots, const std::vector<t_aggspec>& aggregates)
: m_row_pivots(row_pivots)
, m_aggregates(aggregates)
, m_fmode(FMODE_SIMPLE_CLAUSES) {
setup(m_detail_columns, std::vector<std::string>{}, std::vector<std::string>{});
}
// t_ctx0
t_config::t_config(const std::vector<std::string>& detail_columns, t_filter_op combiner,
const std::vector<t_fterm>& fterms)
: m_detail_columns(detail_columns)
, m_combiner(combiner)
, m_fterms(fterms)
, m_fmode(FMODE_SIMPLE_CLAUSES) {}

// grouped_pkeys
// t_ctx1
t_config::t_config(const std::vector<std::string>& row_pivots,
const std::vector<std::string>& detail_columns, t_filter_op combiner,
const std::vector<t_fterm>& fterms, const std::string& parent_pkey_column,
const std::string& child_pkey_column, const std::string& grouping_label_column)
: m_detail_columns(detail_columns)
const std::vector<t_aggspec>& aggregates, t_filter_op combiner,
const std::vector<t_fterm>& fterms)
: m_aggregates(aggregates)
, m_totals(TOTALS_BEFORE)
, m_combiner(combiner)
, m_fterms(fterms)
, m_handle_nan_sort(true)
, m_parent_pkey_column(parent_pkey_column)
, m_child_pkey_column(child_pkey_column)
, m_grouping_label_column(grouping_label_column)
, m_fmode(FMODE_SIMPLE_CLAUSES)

{
, m_fmode(FMODE_SIMPLE_CLAUSES) {
for (const auto& p : row_pivots) {
m_row_pivots.push_back(t_pivot(p));
}

setup(m_detail_columns, std::vector<std::string>{}, std::vector<std::string>{});
}

// ctx2
// t_ctx2
t_config::t_config(const std::vector<std::string>& row_pivots,
const std::vector<std::string>& col_pivots, const std::vector<t_aggspec>& aggregates)
: t_config(row_pivots, col_pivots, aggregates, TOTALS_HIDDEN, FILTER_OP_AND, {})

{}

t_config::t_config(const std::vector<t_pivot>& row_pivots,
const std::vector<t_pivot>& col_pivots, const std::vector<t_aggspec>& aggregates,
const std::vector<std::string>& col_pivots, const std::vector<t_aggspec>& aggregates,
const t_totals totals, t_filter_op combiner, const std::vector<t_fterm>& fterms,
bool column_only)
: m_row_pivots(row_pivots)
, m_col_pivots(col_pivots)
, m_column_only(column_only)
: m_column_only(column_only)
, m_aggregates(aggregates)
, m_totals(totals)
, m_combiner(combiner)
, m_fterms(fterms)
, m_handle_nan_sort(true)
, m_fmode(FMODE_SIMPLE_CLAUSES) {
for (const auto& p : row_pivots) {
m_row_pivots.push_back(t_pivot(p));
}
for (const auto& p : col_pivots) {
m_col_pivots.push_back(t_pivot(p));
}
setup(m_detail_columns, std::vector<std::string>{}, std::vector<std::string>{});
}

// Constructors used for C++ tests
t_config::t_config(const std::vector<std::string>& row_pivots,
const std::vector<std::string>& col_pivots, const std::vector<t_aggspec>& aggregates)
: t_config(row_pivots, col_pivots, aggregates, TOTALS_HIDDEN, FILTER_OP_AND, {}) {}

t_config::t_config(const std::vector<std::string>& row_pivots,
const std::vector<std::string>& col_pivots, const std::vector<t_aggspec>& aggregates,
const t_totals totals, t_filter_op combiner, const std::vector<t_fterm>& fterms)
Expand All @@ -177,7 +103,14 @@ t_config::t_config(const std::vector<std::string>& row_pivots,
setup(m_detail_columns, std::vector<std::string>{}, std::vector<std::string>{});
}

// t_ctx1
t_config::t_config(
const std::vector<t_pivot>& row_pivots, const std::vector<t_aggspec>& aggregates)
: m_row_pivots(row_pivots)
, m_aggregates(aggregates)
, m_fmode(FMODE_SIMPLE_CLAUSES) {
setup(m_detail_columns, std::vector<std::string>{}, std::vector<std::string>{});
}

t_config::t_config(
const std::vector<std::string>& row_pivots, const std::vector<t_aggspec>& aggregates)
: m_aggregates(aggregates)
Expand Down Expand Up @@ -205,45 +138,10 @@ t_config::t_config(const std::vector<std::string>& row_pivots, const t_aggspec&
setup(m_detail_columns, std::vector<std::string>{}, std::vector<std::string>{});
}

t_config::t_config(const std::vector<t_pivot>& row_pivots,
const std::vector<t_aggspec>& aggregates, t_filter_op combiner,
const std::vector<t_fterm>& fterms)
: m_row_pivots(row_pivots)
, m_aggregates(aggregates)
, m_totals(TOTALS_BEFORE)
, m_combiner(combiner)
, m_fterms(fterms)
, m_handle_nan_sort(true)
, m_fmode(FMODE_SIMPLE_CLAUSES) {
setup(m_detail_columns, std::vector<std::string>{}, std::vector<std::string>{});
}

t_config::t_config(const std::vector<std::string>& row_pivots,
const std::vector<t_aggspec>& aggregates, t_filter_op combiner,
const std::vector<t_fterm>& fterms)
: m_aggregates(aggregates)
, m_totals(TOTALS_BEFORE)
, m_combiner(combiner)
, m_fterms(fterms)
, m_handle_nan_sort(true)
, m_fmode(FMODE_SIMPLE_CLAUSES) {
for (const auto& p : row_pivots) {
m_row_pivots.push_back(t_pivot(p));
}

setup(m_detail_columns, std::vector<std::string>{}, std::vector<std::string>{});
}

// t_ctx0
t_config::t_config(const std::vector<std::string>& detail_columns)
: t_config(detail_columns, FILTER_OP_AND, {}) {}

t_config::t_config(const std::vector<std::string>& detail_columns, t_filter_op combiner,
const std::vector<t_fterm>& fterms)
: m_detail_columns(detail_columns)
, m_combiner(combiner)
, m_fterms(fterms)
, m_fmode(FMODE_SIMPLE_CLAUSES) {}
t_config::t_config() {}

void
t_config::setup(const std::vector<std::string>& detail_columns,
Expand Down Expand Up @@ -496,38 +394,6 @@ t_config::get_grouping_label_column() const {
return m_grouping_label_column;
}

t_config_recipe
t_config::get_recipe() const {
t_config_recipe rv;

for (const auto& p : m_row_pivots) {
rv.m_row_pivots.push_back(p.get_recipe());
}

for (const auto& p : m_col_pivots) {
rv.m_col_pivots.push_back(p.get_recipe());
}

rv.m_sortby = get_sortby_pairs();

for (const auto& a : m_aggregates) {
rv.m_aggregates.push_back(a.get_recipe());
}

rv.m_totals = m_totals;
rv.m_combiner = m_combiner;

for (const auto& ft : m_fterms) {
rv.m_fterms.push_back(ft.get_recipe());
}

rv.m_handle_nan_sort = m_handle_nan_sort;
rv.m_parent_pkey_column = m_parent_pkey_column;
rv.m_child_pkey_column = m_child_pkey_column;
rv.m_grouping_label_column = m_grouping_label_column;
return rv;
}

std::string
t_config::unity_get_column_name(t_uindex idx) const {
if (m_aggregates.empty()) {
Expand Down
Loading

0 comments on commit e03dcd4

Please sign in to comment.