@@ -1011,18 +1011,26 @@ t_stree::update_aggs_from_static(const t_dtree_ctx& ctx,
10111011 cols_topo_sorted.clear ();
10121012 cols_topo_sorted.reserve (col_cnt);
10131013
1014+ static bool const enable_aggregate_reordering = true ;
1015+ static bool const enable_fix_double_calculation = true ;
1016+
10141017 std::unordered_set< t_column* > dst_visited;
1015- auto push_column = [&](size_t idx)
1018+ auto push_column = [&]( size_t idx )
10161019 {
1017- t_column* dst = agg_update_info.m_dst [idx];
1018- if (dst_visited.find (dst) != dst_visited.end ())
1020+ if ( enable_fix_double_calculation )
10191021 {
1020- return ;
1022+ t_column* dst = agg_update_info.m_dst [ idx ];
1023+ if ( dst_visited.find ( dst ) != dst_visited.end () )
1024+ {
1025+ return ;
1026+ }
1027+ dst_visited.insert ( dst );
10211028 }
1022- dst_visited.insert (dst);
1023- cols_topo_sorted.push_back (idx);
1029+ cols_topo_sorted.push_back ( idx );
10241030 };
10251031
1032+ if ( enable_aggregate_reordering )
1033+ {
10261034 // Move scaled agg columns to the end
10271035 // This does not handle case where scaled aggregate depends on other scaled aggregate
10281036 // ( not sure if that is possible )
@@ -1040,6 +1048,15 @@ t_stree::update_aggs_from_static(const t_dtree_ctx& ctx,
10401048 push_column (i);
10411049 }
10421050 }
1051+ }
1052+ else
1053+ {
1054+ // If backed out, use same column order as before ( not topo sorted )
1055+ for ( size_t i = 0 ; i < col_cnt; ++i )
1056+ {
1057+ push_column ( i );
1058+ }
1059+ }
10431060
10441061 for (const auto & r : m_tree_unification_records)
10451062 {
@@ -1213,6 +1230,7 @@ t_stree::update_agg_table(t_uindex nidx,
12131230 t_index nstrands,
12141231 const t_gstate& gstate)
12151232{
1233+ static bool const enable_sticky_nan_fix = true ;
12161234 for (t_uindex idx : info.m_dst_topo_sorted )
12171235 {
12181236 const t_column* src = info.m_src [idx];
@@ -1231,16 +1249,14 @@ t_stree::update_agg_table(t_uindex nidx,
12311249 t_tscalar dst_scalar = dst->get_scalar (dst_ridx);
12321250 old_value.set (dst_scalar);
12331251 new_value.set (dst_scalar.add (src_scalar));
1234-
1235- if (old_value.is_nan ())
1252+ if ( enable_sticky_nan_fix && old_value.is_nan () ) // is_nan returns false for non-float types
12361253 {
12371254 // if we previously had a NaN, add can't make it finite again; recalculate entire sum in case it is now finite
12381255 auto pkeys = get_pkeys (nidx);
12391256 t_f64vec values;
12401257 gstate.read_column (spec.get_dependencies ()[0 ].name (), pkeys, values);
12411258 new_value.set (std::accumulate (values.begin (), values.end (), t_float64 (0 )));
12421259 }
1243-
12441260 dst->set_scalar (dst_ridx, new_value);
12451261 }
12461262 break ;
@@ -2337,7 +2353,7 @@ t_stree::get_aggcols(const t_idxvec& agg_indices) const
23372353// aggregates should be presized to be same size
23382354// as agg_indices
23392355void
2340- t_stree::get_aggregates (t_uindex nidx,
2356+ t_stree::get_aggregates_for_sorting (t_uindex nidx,
23412357 const t_idxvec& agg_indices,
23422358 t_tscalvec& aggregates,
23432359 t_ctx2 * ctx2) const
@@ -2350,7 +2366,7 @@ t_stree::get_aggregates(t_uindex nidx,
23502366 auto which_agg = agg_indices[idx];
23512367 if (which_agg < 0 )
23522368 {
2353- aggregates[idx] = get_value (nidx);
2369+ aggregates[idx] = get_sortby_value (nidx);
23542370 }
23552371 else if ( ctx2 || ( size_t (which_agg) >= m_aggcols.size () ) )
23562372 {
0 commit comments