From 521fea62ef0ddee0e3c3e20341957f593557a84a Mon Sep 17 00:00:00 2001 From: Russ Frank Date: Wed, 17 Mar 2021 13:41:10 -0400 Subject: [PATCH] remove uneeded bool in deltaSum impl --- .../AggregateFunctionDeltaSum.h | 25 ++++++++----------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/AggregateFunctions/AggregateFunctionDeltaSum.h b/src/AggregateFunctions/AggregateFunctionDeltaSum.h index d5760de84ae..c3c61d957da 100644 --- a/src/AggregateFunctions/AggregateFunctionDeltaSum.h +++ b/src/AggregateFunctions/AggregateFunctionDeltaSum.h @@ -22,8 +22,7 @@ struct AggregationFunctionDeltaSumData T sum = 0; T last = 0; T first = 0; - bool seen_last = false; - bool seen_first = false; + bool seen = false; }; template @@ -47,18 +46,17 @@ public: { auto value = assert_cast &>(*columns[0]).getData()[row_num]; - if ((this->data(place).last < value) && this->data(place).seen_last) + if ((this->data(place).last < value) && this->data(place).seen) { this->data(place).sum += (value - this->data(place).last); } this->data(place).last = value; - this->data(place).seen_last = true; - if (!this->data(place).seen_first) + if (!this->data(place).seen) { this->data(place).first = value; - this->data(place).seen_first = true; + this->data(place).seen = true; } } @@ -67,7 +65,7 @@ public: auto place_data = &this->data(place); auto rhs_data = &this->data(rhs); - if ((place_data->last < rhs_data->first) && place_data->seen_last && rhs_data->seen_first) + if ((place_data->last < rhs_data->first) && place_data->seen && rhs_data->seen) { // If the lhs last number seen is less than the first number the rhs saw, the lhs is before // the rhs, for example [0, 2] [4, 7]. So we want to add the deltasums, but also add the @@ -77,7 +75,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->last < place_data->first && rhs_data->seen && place_data->seen)) { // 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,16 +85,15 @@ public: place_data->sum += rhs_data->sum; place_data->first = rhs_data->first; } - else if (rhs_data->seen_first) + else if (rhs_data->seen) { // 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. place_data->first = rhs_data->first; - place_data->seen_first = rhs_data->seen_first; place_data->last = rhs_data->last; - place_data->seen_last = rhs_data->seen_last; place_data->sum = rhs_data->sum; + place_data->seen = rhs_data->seen; } // Otherwise lhs either has data or is uninitialized, so we don't need to modify its values. @@ -107,8 +104,7 @@ public: writeIntBinary(this->data(place).sum, buf); writeIntBinary(this->data(place).first, buf); writeIntBinary(this->data(place).last, buf); - writePODBinary(this->data(place).seen_first, buf); - writePODBinary(this->data(place).seen_last, buf); + writePODBinary(this->data(place).seen, buf); } void deserialize(AggregateDataPtr __restrict place, ReadBuffer & buf, Arena *) const override @@ -116,8 +112,7 @@ public: readIntBinary(this->data(place).sum, buf); readIntBinary(this->data(place).first, buf); readIntBinary(this->data(place).last, buf); - readPODBinary(this->data(place).seen_first, buf); - readPODBinary(this->data(place).seen_last, buf); + readPODBinary(this->data(place).seen, buf); } void insertResultInto(AggregateDataPtr __restrict place, IColumn & to, Arena *) const override