Repository navigation
avgWeighted - #7898
avgWeighted#7898
Conversation
| namespace DB | ||
| { | ||
| template <typename T> | ||
| struct AggregateFunctionAvgWeightedData |
There was a problem hiding this comment.
I don't see any difference with AggregateFunctionAvgData. Why don't we use it?
| /// Calculates arithmetic mean of numbers. | ||
| template <typename T, typename Data> | ||
| class AggregateFunctionAvg final : public IAggregateFunctionDataHelper<Data, AggregateFunctionAvg<T, Data>> | ||
| template <typename Data, typename T, typename F> |
There was a problem hiding this comment.
F is not very good name. maybe rename to Derived or something?
There was a problem hiding this comment.
Why did we change T and Data order? Don't think it's important, but suspicious.
| class AggregateFunctionAvg final : public AggregateFunctionAvgBase<Data, T, AggregateFunctionAvg<T, Data>> | ||
| { | ||
| public: | ||
| AggregateFunctionAvg(const DataTypes & argument_types_) |
There was a problem hiding this comment.
You can probably inherit constructor from AggregateFunctionAvgBase. It's not very important and not necessary to fix.
| @@ -0,0 +1 @@ | |||
| SELECT avgWeighted(x, weight) FROM (SELECT t.1 AS x, t.2 AS weight FROM (SELECT arrayJoin([(1, 1), (2, 1), (3, 1), (4, 1), (5, 1)]) AS t)); | |||
There was a problem hiding this comment.
Well, this test is not interesting if all weights are 1. Need test with different weights. And with all weights = 0.
There was a problem hiding this comment.
And also need test with different types of x and weight (which could pass or throw specified exception).
| using Function = AggregateFunctionAvgWeighted<T, AggregateFunctionAvgWeightedData<FieldType>>; | ||
| }; | ||
|
|
||
| template <typename T> |
There was a problem hiding this comment.
Now it is impossible to use different types for values and weights. It may be not very convenient.
it is possible to improve later.
There was a problem hiding this comment.
@KochetovNicolai ,
We are wanting to use the avgWeighted function but with custom weights for different fields. Would be great if that improvement can be provided.
| assertBinary(name, argument_types); | ||
|
|
||
| AggregateFunctionPtr res; | ||
| DataTypePtr data_type = argument_types[0]; |
There was a problem hiding this comment.
We don't check that second argument is the same as the first one. But later use static_cast to it.
https://github.com/ClickHouse/ClickHouse/pull/7898/files#diff-acc7d09909cab310ba93073f472e3850R44
|
|
||
| void registerAggregateFunctionAvgWeighted(AggregateFunctionFactory & factory) | ||
| { | ||
| factory.registerFunction("AvgWeighted", createAggregateFunctionAvgWeighted, AggregateFunctionFactory::CaseInsensitive); |
There was a problem hiding this comment.
It's better to use AvgWeighted name by our style.
Also I don't think that it should be CaseInsensitive, cause AVGWEIGHTED looks wired. But can leave it if you want.
There was a problem hiding this comment.
avgWeighted for sure.
Because we are using camelCase (starting from lowercase letter except if it is starting by all caps acronym).
|
00463_long_sessions_in_http_interface - flacky test. |
|
There is no |
|
Everything else is ok. |
|
@apbodrov Why do you need |
I hereby agree to the terms of the CLA available at: https://yandex.ru/legal/cla/?lang=en
Changelog category (leave one):
Changelog entry (up to few sentences, required except for Non-significant/Documentation categories):
new aggregate function avgWeighted