Merge pull request #23437 from rf/rf/deltasum-condition-fix

`deltaSum` aggregate function counter reset bugfix & test
This commit is contained in:
Kruglov Pavel 2021-04-22 10:37:41 +03:00 committed by GitHub
commit f125db243e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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->sum += rhs_data->sum + (rhs_data->first - place_data->last);
place_data->last = rhs_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 // 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 // assume the input interval states are sorted by time, we assume this is a counter
@ -87,9 +87,9 @@ public:
// rhs last value. // rhs last value.
place_data->sum += rhs_data->sum; 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 // 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. // we'll just take that state.

View File

@ -7,3 +7,4 @@
2 2
2.25 2.25
6.5 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 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 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([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);