Skip to content

Commit

Permalink
Merge pull request #1793 from finos/sum-expressions-fix
Browse files Browse the repository at this point in the history
Fix `sum` aggregate to force re-agg for expression columns
  • Loading branch information
texodus authored May 1, 2022
2 parents 6bbcb40 + 7131a7f commit b726e29
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions cpp/perspective/src/cpp/sparse_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -955,13 +955,16 @@ void
t_stree::update_agg_table(t_uindex nidx, t_agg_update_info& info,
t_uindex src_ridx, t_uindex dst_ridx, t_index nstrands,
const t_gstate& gstate, const t_data_table& expression_master_table) {
const t_schema& expression_schema = expression_master_table.get_schema();

for (t_uindex idx : info.m_dst_topo_sorted) {
const t_column* src = info.m_src[idx];
t_column* dst = info.m_dst[idx];
const t_aggspec& spec = info.m_aggspecs[idx];
t_tscalar new_value = mknone();
t_tscalar old_value = mknone();
auto is_expr
= expression_schema.has_column(spec.get_dependencies()[0].name());

switch (spec.agg()) {
case AGGTYPE_PCT_SUM_PARENT:
Expand All @@ -971,9 +974,9 @@ t_stree::update_agg_table(t_uindex nidx, t_agg_update_info& info,
t_tscalar dst_scalar = dst->get_scalar(dst_ridx);
old_value.set(dst_scalar);
new_value.set(dst_scalar.add(src_scalar));
if (old_value
.is_nan()) // is_nan returns false for non-float types
{

// is_nan returns false for non-float types
if (is_expr || old_value.is_nan()) {
// if we previously had a NaN, add can't make it finite
// again; recalculate entire sum in case it is now finite
auto pkeys = get_pkeys(nidx);
Expand Down

0 comments on commit b726e29

Please sign in to comment.