deltasum counter reset bugfix & test

This commit is contained in:
Russ Frank 2021-04-20 10:52:16 -04:00
parent 733f9900fa
commit 822fc9b110
3 changed files with 5 additions and 3 deletions

View File

@ -79,7 +79,7 @@ public:
place_data->sum += rhs_data->sum + (rhs_data->first - place_data->last);
place_data->last = rhs_data->last;
}
else if ((rhs_data->last < place_data->first && rhs_data->seen_last && place_data->seen_first))
else if ((rhs_data->first < place_data->last && rhs_data->seen_last && place_data->seen_first))
{
// In the opposite scenario, the lhs comes after the rhs, e.g. [4, 6] [1, 2]. Since we
// assume the input interval states are sorted by time, we assume this is a counter
@ -87,9 +87,9 @@ public:
// rhs last value.
place_data->sum += rhs_data->sum;
place_data->first = rhs_data->first;
place_data->last = rhs_data->last;
}
else if (rhs_data->seen_first)
else if (rhs_data->seen_first && !place_data->seen_first)
{
// If we're here then the lhs is an empty state and the rhs does have some state, so
// we'll just take that state.

View File

@ -7,3 +7,4 @@
2
2.25
6.5
7

View File

@ -7,3 +7,4 @@ select deltaSumMerge(rows) from (select deltaSumState(arrayJoin([0, 1])) as rows
select deltaSumMerge(rows) from (select deltaSumState(arrayJoin([4, 5])) as rows union all select deltaSumState(arrayJoin([0, 1])) as rows);
select deltaSum(arrayJoin([2.25, 3, 4.5]));
select deltaSumMerge(rows) from (select deltaSumState(arrayJoin([0.1, 0.3, 0.5])) as rows union all select deltaSumState(arrayJoin([4.1, 5.1, 6.6])) as rows);
select deltaSumMerge(rows) from (select deltaSumState(arrayJoin([3, 5])) as rows union all select deltaSumState(arrayJoin([1, 2])) as rows union all select deltaSumState(arrayJoin([4, 6])) as rows);