mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-22 23:52:03 +00:00
Simplification of aggregate functions: development [#CLICKHOUSE-2].
This commit is contained in:
parent
178deea21c
commit
b3f4d439fb
@ -81,17 +81,17 @@ AggregateFunctionPtr createAggregateFunctionQuantileTwoArgs(const std::string &
|
||||
|
||||
#define CREATE(TYPE) \
|
||||
if (typeid_cast<const DataType ## TYPE *>(argument_type.get())) \
|
||||
return createAggregateFunctionQuantileTwoArgsForSecondArg<TYPE, Data<TYPE>, Name, returns_float, returns_many>(name, argument_types, params);
|
||||
return createAggregateFunctionQuantileTwoArgsForSecondArg<TYPE, Data, Name, returns_float, returns_many>(name, argument_types, params);
|
||||
|
||||
FOR_NUMERIC_TYPES(CREATE)
|
||||
#undef CREATE
|
||||
|
||||
if (typeid_cast<const DataTypeDate *>(argument_type.get()))
|
||||
return createAggregateFunctionQuantileTwoArgsForSecondArg<
|
||||
DataTypeDate::FieldType, Data<DataTypeDate::FieldType>, Name, false, returns_many>(name, argument_types, params);
|
||||
DataTypeDate::FieldType, Data, Name, false, returns_many>(name, argument_types, params);
|
||||
if (typeid_cast<const DataTypeDateTime *>(argument_type.get()))
|
||||
return createAggregateFunctionQuantileTwoArgsForSecondArg<
|
||||
DataTypeDateTime::FieldType, Data<DataTypeDateTime::FieldType>, Name, false, returns_many>(name, argument_types, params);
|
||||
DataTypeDateTime::FieldType, Data, Name, false, returns_many>(name, argument_types, params);
|
||||
|
||||
throw Exception("Illegal type " + argument_type->getName() + " of first argument for aggregate function " + name, ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
|
||||
}
|
||||
@ -108,7 +108,7 @@ struct NameQuantileExact { static constexpr auto name = "quantileExact"; };
|
||||
struct NameQuantileExactWeighted { static constexpr auto name = "quantileExactWeighted"; };
|
||||
struct NameQuantilesExact { static constexpr auto name = "quantilesExact"; };
|
||||
struct NameQuantilesExactWeighted { static constexpr auto name = "quantilesExactWeighted"; };
|
||||
|
||||
/*
|
||||
struct NameQuantileTiming { static constexpr auto name = "quantileTiming"; };
|
||||
struct NameQuantileTimingWeighted { static constexpr auto name = "quantileTimingWeighted"; };
|
||||
struct NameQuantilesTiming { static constexpr auto name = "quantilesTiming"; };
|
||||
@ -118,7 +118,7 @@ struct NameQuantileTDigest { static constexpr auto name = "quantileTDigest"; };
|
||||
struct NameQuantileTDigestWeighted { static constexpr auto name = "quantileTDigestWeighted"; };
|
||||
struct NameQuantilesTDigest { static constexpr auto name = "quantilesTDigest"; };
|
||||
struct NameQuantilesTDigestWeighted { static constexpr auto name = "quantilesTDigestWeighted"; };
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
void registerAggregateFunctionsQuantile(AggregateFunctionFactory & factory)
|
||||
@ -136,7 +136,7 @@ void registerAggregateFunctionsQuantile(AggregateFunctionFactory & factory)
|
||||
|
||||
factory.registerFunction("quantileExactWeighted", createAggregateFunctionQuantileTwoArgs<QuantileExactWeighted, NameQuantileExactWeighted, false, false>);
|
||||
factory.registerFunction("quantilesExactWeighted", createAggregateFunctionQuantileTwoArgs<QuantileExactWeighted, NameQuantilesExactWeighted, false, true>);
|
||||
|
||||
/*
|
||||
factory.registerFunction("quantileTiming", createAggregateFunctionQuantile<QuantileTiming, NameQuantileTiming, false, false>);
|
||||
factory.registerFunction("quantilesTiming", createAggregateFunctionQuantile<QuantileTiming, NameQuantilesTiming, false, true>);
|
||||
|
||||
@ -148,7 +148,7 @@ void registerAggregateFunctionsQuantile(AggregateFunctionFactory & factory)
|
||||
|
||||
factory.registerFunction("quantileTDigestWeighted", createAggregateFunctionQuantileTwoArgs<QuantileTDigest, NameQuantileTDigestWeighted, true, false>);
|
||||
factory.registerFunction("quantilesTDigestWeighted", createAggregateFunctionQuantileTwoArgs<QuantileTDigest, NameQuantilesTDigestWeighted, true, true>);
|
||||
|
||||
*/
|
||||
/// TODO Aliases
|
||||
}
|
||||
|
||||
|
@ -51,10 +51,10 @@ class AggregateFunctionQuantile final : public IAggregateFunctionDataHelper<Data
|
||||
AggregateFunctionQuantile<Value, SecondArg, Data, Name, returns_float, returns_many>>
|
||||
{
|
||||
private:
|
||||
bool have_second_arg = !std::is_same_v<SecondArg, void>;
|
||||
static constexpr bool have_second_arg = !std::is_same_v<SecondArg, void>;
|
||||
|
||||
Float64 level = 0.5;
|
||||
QuantileLevels<Float64> levels;
|
||||
Float64 level = 0.5;
|
||||
DataTypePtr argument_type;
|
||||
|
||||
public:
|
||||
@ -85,11 +85,11 @@ public:
|
||||
void add(AggregateDataPtr place, const IColumn ** columns, size_t row_num, Arena *) const override
|
||||
{
|
||||
if constexpr (have_second_arg)
|
||||
this->data(place).insert(
|
||||
this->data(place).add(
|
||||
static_cast<const ColumnVector<Value> &>(*columns[0]).getData()[row_num],
|
||||
static_cast<const ColumnVector<SecondArg> &>(*columns[1]).getData()[row_num]);
|
||||
else
|
||||
this->data(place).insert(
|
||||
this->data(place).add(
|
||||
static_cast<const ColumnVector<Value> &>(*columns[0]).getData()[row_num]);
|
||||
}
|
||||
|
||||
|
@ -53,7 +53,7 @@ struct QuantileExact
|
||||
}
|
||||
|
||||
/// Get the value of the `level` quantile. The level must be between 0 and 1.
|
||||
Value get(Float64 level) const
|
||||
Value get(Float64 level)
|
||||
{
|
||||
if (!array.empty())
|
||||
{
|
||||
@ -70,7 +70,7 @@ struct QuantileExact
|
||||
|
||||
/// Get the `size` values of `levels` quantiles. Write `size` results starting with `result` address.
|
||||
/// indices - an array of index levels such that the corresponding elements will go in ascending order.
|
||||
void getMany(const Float64 * levels, const size_t * indices, size_t size, Value * result) const
|
||||
void getMany(const Float64 * levels, const size_t * indices, size_t size, Value * result)
|
||||
{
|
||||
if (!array.empty())
|
||||
{
|
||||
|
@ -32,7 +32,7 @@ struct QuantileReservoirSampler
|
||||
|
||||
void merge(const QuantileReservoirSampler & rhs)
|
||||
{
|
||||
data.merge(rhs);
|
||||
data.merge(rhs.data);
|
||||
}
|
||||
|
||||
void serialize(WriteBuffer & buf) const
|
||||
@ -46,26 +46,26 @@ struct QuantileReservoirSampler
|
||||
}
|
||||
|
||||
/// Get the value of the `level` quantile. The level must be between 0 and 1.
|
||||
Value get(Float64 level) const
|
||||
Value get(Float64 level)
|
||||
{
|
||||
return data.quantileInterpolated(level);
|
||||
}
|
||||
|
||||
/// Get the `size` values of `levels` quantiles. Write `size` results starting with `result` address.
|
||||
/// indices - an array of index levels such that the corresponding elements will go in ascending order.
|
||||
void getMany(const Float64 * levels, const size_t * indices, size_t size, Value * result) const
|
||||
void getMany(const Float64 * levels, const size_t * indices, size_t size, Value * result)
|
||||
{
|
||||
for (size_t i = 0; i < size; ++i)
|
||||
result[indices[i]] = data.quantileInterpolated(levels[indices[i]]);
|
||||
}
|
||||
|
||||
/// The same, but in the case of an empty state, NaN is returned.
|
||||
float getFloat(Float64 level) const
|
||||
float getFloat(Float64 level)
|
||||
{
|
||||
return data.quantileInterpolated(level);
|
||||
}
|
||||
|
||||
void getManyFloat(const Float64 * levels, const size_t * indices, size_t size, float * result) const
|
||||
void getManyFloat(const Float64 * levels, const size_t * indices, size_t size, float * result)
|
||||
{
|
||||
for (size_t i = 0; i < size; ++i)
|
||||
result[indices[i]] = data.quantileInterpolated(levels[indices[i]]);
|
||||
|
@ -32,7 +32,7 @@ struct QuantileReservoirSamplerDeterministic
|
||||
|
||||
void merge(const QuantileReservoirSamplerDeterministic & rhs)
|
||||
{
|
||||
data.merge(rhs);
|
||||
data.merge(rhs.data);
|
||||
}
|
||||
|
||||
void serialize(WriteBuffer & buf) const
|
||||
@ -46,26 +46,26 @@ struct QuantileReservoirSamplerDeterministic
|
||||
}
|
||||
|
||||
/// Get the value of the `level` quantile. The level must be between 0 and 1.
|
||||
Value get(Float64 level) const
|
||||
Value get(Float64 level)
|
||||
{
|
||||
return data.quantileInterpolated(level);
|
||||
}
|
||||
|
||||
/// Get the `size` values of `levels` quantiles. Write `size` results starting with `result` address.
|
||||
/// indices - an array of index levels such that the corresponding elements will go in ascending order.
|
||||
void getMany(const Float64 * levels, const size_t * indices, size_t size, Value * result) const
|
||||
void getMany(const Float64 * levels, const size_t * indices, size_t size, Value * result)
|
||||
{
|
||||
for (size_t i = 0; i < size; ++i)
|
||||
result[indices[i]] = data.quantileInterpolated(levels[indices[i]]);
|
||||
}
|
||||
|
||||
/// The same, but in the case of an empty state, NaN is returned.
|
||||
float getFloat(Float64 level) const
|
||||
float getFloat(Float64 level)
|
||||
{
|
||||
return data.quantileInterpolated(level);
|
||||
}
|
||||
|
||||
void getManyFloat(const Float64 * levels, const size_t * indices, size_t size, float * result) const
|
||||
void getManyFloat(const Float64 * levels, const size_t * indices, size_t size, float * result)
|
||||
{
|
||||
for (size_t i = 0; i < size; ++i)
|
||||
result[indices[i]] = data.quantileInterpolated(levels[indices[i]]);
|
||||
|
Loading…
Reference in New Issue
Block a user