Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add view config class in C++ #672

Merged
merged 6 commits into from
Jul 30, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add t_view_config, remove unused recipe code for aggspecs
add t_view_config

remove t_aggspec_recipe
  • Loading branch information
sc1f committed Jul 26, 2019
commit e9d008608bd58dff17daf452468d6e2a08636bf3
1 change: 1 addition & 0 deletions cpp/perspective/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,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
16 changes: 14 additions & 2 deletions cpp/perspective/src/cpp/emscripten.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1515,6 +1515,7 @@ namespace binding {
*
* View API
*/

template <>
t_config
make_view_config(
Expand Down Expand Up @@ -1916,6 +1917,16 @@ EMSCRIPTEN_BINDINGS(perspective) {
.function("get_column_dtype", &View<t_ctx2>::get_column_dtype)
.function("is_column_only", &View<t_ctx2>::is_column_only);

/******************************************************************************
*
* t_view_config
*/
class_<t_view_config>("t_view_config")
.constructor<std::vector<std::string>, std::vector<std::string>,
std::vector<std::string>, std::map<std::string, std::string>,
std::vector<std::tuple<std::string, std::string, t_tscalar>>,
std::vector<std::vector<std::string>>, bool>();

/******************************************************************************
*
* t_data_table
Expand Down Expand Up @@ -2043,13 +2054,14 @@ EMSCRIPTEN_BINDINGS(perspective) {
* vector
*/
register_vector<std::int32_t>("std::vector<std::int32_t>");
register_vector<std::string>("std::vector<std::string>");
register_vector<t_dtype>("std::vector<t_dtype>");
register_vector<t_cellupd>("std::vector<t_cellupd>");
register_vector<t_tscalar>("std::vector<t_tscalar>");
register_vector<std::vector<t_tscalar>>("std::vector<std::vector<t_tscalar>>");
register_vector<std::string>("std::vector<std::string>");
register_vector<t_updctx>("std::vector<t_updctx>");
register_vector<t_uindex>("std::vector<t_uindex>");
register_vector<std::vector<t_tscalar>>("std::vector<std::vector<t_tscalar>>");
register_vector<std::vector<std::string>>("std::vector<std::vector<std::string>>");

/******************************************************************************
*
Expand Down
19 changes: 0 additions & 19 deletions cpp/perspective/src/cpp/filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,6 @@ namespace perspective {

t_fterm::t_fterm() {}

t_fterm::t_fterm(const t_fterm_recipe& v) {
m_colname = v.m_colname;
m_op = v.m_op;
m_threshold = v.m_threshold;
m_bag = v.m_bag;
m_use_interned
= (m_op == FILTER_OP_EQ || m_op == FILTER_OP_NE) && m_threshold.m_type == DTYPE_STR;
}

t_fterm::t_fterm(const std::string& colname, t_filter_op op, t_tscalar threshold,
const std::vector<t_tscalar>& bag, bool negated, bool is_primary)
: m_colname(colname)
Expand Down Expand Up @@ -55,16 +46,6 @@ t_fterm::coerce_numeric(t_dtype dtype) {
}
}

t_fterm_recipe
t_fterm::get_recipe() const {
t_fterm_recipe rv;
rv.m_colname = m_colname;
rv.m_op = m_op;
rv.m_threshold = m_threshold;
rv.m_bag = m_bag;
return rv;
}

std::string
t_fterm::get_expr() const {
std::stringstream ss;
Expand Down
34 changes: 34 additions & 0 deletions cpp/perspective/src/cpp/view_config.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/******************************************************************************
*
* Copyright (c) 2019, the Perspective Authors.
*
* This file is part of the Perspective library, distributed under the terms of
* the Apache License 2.0. The full license can be found in the LICENSE file.
*
*/

#include <perspective/view_config.h>

namespace perspective {

t_view_config::t_view_config(std::vector<std::string> row_pivots,
std::vector<std::string> column_pivots, std::vector<std::string> columns,
std::map<std::string, std::string> aggregates,
std::vector<std::tuple<std::string, std::string, t_tscalar>> filter,
std::vector<std::vector<std::string>> sort, bool column_only)
: m_row_pivots(row_pivots)
, m_column_pivots(column_pivots)
, m_columns(columns)
, m_aggregates(aggregates)
, m_filter(filter)
, m_sort(sort)
, m_column_only(column_only) {}

void
t_view_config::add_filter_term(
std::string col_name, std::string filter_op, t_tscalar filter_term) {
auto term = std::make_tuple(col_name, filter_op, filter_term);
m_filter.push_back(term);
}

} // namespace perspective
20 changes: 1 addition & 19 deletions cpp/perspective/src/include/perspective/aggspec.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,12 @@ struct PERSPECTIVE_EXPORT t_col_name_type {
t_dtype m_type;
};

struct PERSPECTIVE_EXPORT t_aggspec_recipe {
t_aggspec_recipe() {}
std::string m_name;
std::string m_disp_name;
t_aggtype m_agg;
std::vector<t_dep_recipe> m_dependencies;
std::vector<t_dep_recipe> m_odependencies;
t_sorttype m_sort_type;
t_uindex m_agg_one_idx;
t_uindex m_agg_two_idx;
double m_agg_one_weight;
double m_agg_two_weight;
t_invmode m_invmode;
};

class PERSPECTIVE_EXPORT t_aggspec {
public:
t_aggspec();

~t_aggspec();

t_aggspec(const t_aggspec_recipe& v);

t_aggspec(
const std::string& aggname, t_aggtype agg, const std::vector<t_dep>& dependencies);

Expand All @@ -64,6 +47,7 @@ class PERSPECTIVE_EXPORT t_aggspec {
t_aggspec(const std::string& aggname, const std::string& disp_aggname, t_aggtype agg,
t_uindex agg_one_idx, t_uindex agg_two_idx, double agg_one_weight,
double agg_two_weight);

std::string name() const;
t_tscalar name_scalar() const;
std::string disp_name() const;
Expand Down Expand Up @@ -93,8 +77,6 @@ class PERSPECTIVE_EXPORT t_aggspec {

std::string get_first_depname() const;

t_aggspec_recipe get_recipe() const;

private:
std::string m_name;
std::string m_disp_name;
Expand Down
5 changes: 5 additions & 0 deletions cpp/perspective/src/include/perspective/binding.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <perspective/sym_table.h>
#include <perspective/table.h>
#include <perspective/view.h>
#include <perspective/view_config.h>
#include <random>
#include <cmath>
#include <sstream>
Expand Down Expand Up @@ -271,6 +272,10 @@ namespace binding {
template <typename T>
std::shared_ptr<Table> make_computed_table(std::shared_ptr<Table> table, T computed);

template <typename T>
t_view_config make_view_config2(
const t_schema& schema, std::string separator, T date_parser, T config);

/**
* @brief Extracts and validates the config from the binding language,
* creating a t_config for the new View.
Expand Down
12 changes: 0 additions & 12 deletions cpp/perspective/src/include/perspective/filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,20 +125,9 @@ struct t_operator_contains<t_uindex, DTYPE_STR> {
}
};

struct PERSPECTIVE_EXPORT t_fterm_recipe {
t_fterm_recipe() {}

std::string m_colname;
t_filter_op m_op;
t_tscalar m_threshold;
std::vector<t_tscalar> m_bag;
};

struct PERSPECTIVE_EXPORT t_fterm {
t_fterm();

t_fterm(const t_fterm_recipe& v);

t_fterm(const std::string& colname, t_filter_op op, t_tscalar threshold,
const std::vector<t_tscalar>& bag);

Expand All @@ -164,7 +153,6 @@ struct PERSPECTIVE_EXPORT t_fterm {
std::string get_expr() const;

void coerce_numeric(t_dtype dtype);
t_fterm_recipe get_recipe() const;

std::string m_colname;
t_filter_op m_op;
Expand Down
35 changes: 35 additions & 0 deletions cpp/perspective/src/include/perspective/view_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/******************************************************************************
*
* Copyright (c) 2019, the Perspective Authors.
*
* This file is part of the Perspective library, distributed under the terms of
* the Apache License 2.0. The full license can be found in the LICENSE file.
*
*/
#pragma once

#include <perspective/first.h>
#include <perspective/config.h>
#include <perspective/raw_types.h>
#include <perspective/scalar.h>
#include <boost/optional.hpp>
#include <tuple>

namespace perspective {
struct t_view_config {
t_view_config(std::vector<std::string> row_pivots, std::vector<std::string> column_pivots,
std::vector<std::string> columns, std::map<std::string, std::string> aggregates,
std::vector<std::tuple<std::string, std::string, t_tscalar>> filter,
std::vector<std::vector<std::string>> sort, bool column_only);

void add_filter_term(std::string col_name, std::string filter_op, t_tscalar filter_term);

std::vector<std::string> m_row_pivots;
std::vector<std::string> m_column_pivots;
std::vector<std::string> m_columns;
std::map<std::string, std::string> m_aggregates;
std::vector<std::tuple<std::string, std::string, t_tscalar>> m_filter;
std::vector<std::vector<std::string>> m_sort;
bool m_column_only;
};
} // namespace perspective