mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-18 04:12:19 +00:00
Fix serialize/deserialize of denominator of Average functions
Use writeBinary/readBinary to serialize/deserialize the denominator of Average functions. Previously it would be transmitted as an unsigned int, which means its value would get corrupted when doing an avgWeighted over a floating point number. Note: this commit is not backwards compatible! Signed-off-by: Baudouin Giard <bgiard@bloomberg.net>
This commit is contained in:
parent
99561ab8e8
commit
be2cf70da8
@ -71,13 +71,13 @@ public:
|
||||
void serialize(ConstAggregateDataPtr place, WriteBuffer & buf) const override
|
||||
{
|
||||
writeBinary(this->data(place).numerator, buf);
|
||||
writeVarUInt(this->data(place).denominator, buf);
|
||||
writeBinary(this->data(place).denominator, buf);
|
||||
}
|
||||
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf, Arena *) const override
|
||||
{
|
||||
readBinary(this->data(place).numerator, buf);
|
||||
readVarUInt(this->data(place).denominator, buf);
|
||||
readBinary(this->data(place).denominator, buf);
|
||||
}
|
||||
|
||||
void insertResultInto(ConstAggregateDataPtr place, IColumn & to) const override
|
||||
|
@ -0,0 +1,6 @@
|
||||
100
|
||||
10
|
||||
0
|
||||
nan
|
||||
nan
|
||||
100
|
9
tests/queries/0_stateless/01268_shard_avgweighted.sql
Normal file
9
tests/queries/0_stateless/01268_shard_avgweighted.sql
Normal file
@ -0,0 +1,9 @@
|
||||
CREATE TABLE dummy(foo Int64) ENGINE = Memory();
|
||||
INSERT INTO dummy VALUES (1);
|
||||
SELECT avgWeighted(100., .1) FROM remote('127.0.0.{2,3}', currentDatabase(), dummy);
|
||||
SELECT avgWeighted(10, 100) FROM remote('127.0.0.{2,3}', currentDatabase(), dummy);
|
||||
SELECT avgWeighted(0, 1) FROM remote('127.0.0.{2,3}', currentDatabase(), dummy);
|
||||
SELECT avgWeighted(0., 0.) FROM remote('127.0.0.{2,3}', currentDatabase(), dummy);
|
||||
SELECT avgWeighted(1., 0.) FROM remote('127.0.0.{2,3}', currentDatabase(), dummy);
|
||||
SELECT avgWeighted(toInt8(100), -1) FROM remote('127.0.0.{2,3}', currentDatabase(), dummy);
|
||||
DROP TABLE dummy;
|
Loading…
Reference in New Issue
Block a user