Skip to content

Commit

Permalink
Merge pull request #1031 from harsh-jindal/feature-abs-sum
Browse files Browse the repository at this point in the history
Add abs sum as an aggregator
  • Loading branch information
texodus authored May 8, 2020
2 parents faa9f72 + 4c25d1f commit a4c28be
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions cpp/perspective/src/cpp/aggspec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ t_aggspec::agg_str() const {
case AGGTYPE_SUM_ABS: {
return "sum_abs";
} break;
case AGGTYPE_ABS_SUM: {
return "abs_sum";
} break;
case AGGTYPE_MUL: {
return "mul";
} break;
Expand Down Expand Up @@ -281,6 +284,7 @@ t_aggspec::get_output_specs(const t_schema& schema) const {
switch (agg()) {
case AGGTYPE_SUM:
case AGGTYPE_SUM_ABS:
case AGGTYPE_ABS_SUM:
case AGGTYPE_PCT_SUM_PARENT:
case AGGTYPE_PCT_SUM_GRAND_TOTAL:
case AGGTYPE_MUL:
Expand Down
4 changes: 3 additions & 1 deletion cpp/perspective/src/cpp/base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -590,8 +590,10 @@ str_to_aggtype(const std::string& str) {
return t_aggtype::AGGTYPE_HIGH_WATER_MARK;
} else if (str == "low" || str == "low_water_mark") {
return t_aggtype::AGGTYPE_LOW_WATER_MARK;
} else if (str == "sum abs") {
} else if (str == "sum abs" || str == "sum_abs") {
return t_aggtype::AGGTYPE_SUM_ABS;
} else if (str == "abs sum" || str == "abs_sum") {
return t_aggtype::AGGTYPE_ABS_SUM;
} else if (str == "sum not null" || str == "sum_not_null") {
return t_aggtype::AGGTYPE_SUM_NOT_NULL;
} else if (str == "mean by count" || str == "mean_by_count") {
Expand Down
1 change: 1 addition & 0 deletions cpp/perspective/src/cpp/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ t_config::setup(const std::vector<std::string>& detail_columns,
case AGGTYPE_PY_AGG:
case AGGTYPE_SUM_NOT_NULL:
case AGGTYPE_SUM_ABS:
case AGGTYPE_ABS_SUM:
case AGGTYPE_MUL:
case AGGTYPE_DISTINCT_COUNT:
case AGGTYPE_DISTINCT_LEAF:
Expand Down
1 change: 1 addition & 0 deletions cpp/perspective/src/cpp/extract_aggregate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ extract_aggregate(
} break;
case AGGTYPE_SUM:
case AGGTYPE_SUM_ABS:
case AGGTYPE_ABS_SUM:
case AGGTYPE_SUM_NOT_NULL:
case AGGTYPE_MUL:
case AGGTYPE_COUNT:
Expand Down
9 changes: 9 additions & 0 deletions cpp/perspective/src/cpp/sparse_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1192,6 +1192,15 @@ t_stree::update_agg_table(t_uindex nidx, t_agg_update_info& info, t_uindex src_r
}));
dst->set_scalar(dst_ridx, new_value);
} break;
case AGGTYPE_ABS_SUM: {
old_value.set(dst->get_scalar(dst_ridx));
auto pkeys = get_pkeys(nidx);
std::vector<double> values;
gstate.read_column(spec.get_dependencies()[0].name(), pkeys, values);
double sum = std::accumulate(values.begin(), values.end(), double(0));
new_value.set(std::abs(sum));
dst->set_scalar(dst_ridx, new_value);
} break;
case AGGTYPE_MUL: {
old_value.set(dst->get_scalar(dst_ridx));
auto pkeys = get_pkeys(nidx);
Expand Down
1 change: 1 addition & 0 deletions cpp/perspective/src/include/perspective/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ enum t_aggtype {
AGGTYPE_UDF_COMBINER,
AGGTYPE_UDF_REDUCER,
AGGTYPE_SUM_ABS,
AGGTYPE_ABS_SUM,
AGGTYPE_SUM_NOT_NULL,
AGGTYPE_MEAN_BY_COUNT,
AGGTYPE_IDENTITY,
Expand Down
1 change: 1 addition & 0 deletions python/perspective/perspective/core/aggregate.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class Aggregate(Enum):
PCT_SUM_GRAND_TOTAL = 'pct sum grand total'
SUM = 'sum'
SUM_ABS = 'sum abs'
ABS_SUM = 'abs sum'
SUM_NOT_NULL = 'sum not null'
UNIQUE = 'unique'

Expand Down

0 comments on commit a4c28be

Please sign in to comment.