mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 15:12:02 +00:00
refactored
This commit is contained in:
parent
907115a4c4
commit
8ed90864cb
@ -52,8 +52,8 @@ template <typename Value, bool float_return> using FuncQuantilesTDigest = Aggreg
|
|||||||
template <typename Value, bool float_return> using FuncQuantileTDigestWeighted = AggregateFunctionQuantile<Value, QuantileTDigest<Value>, NameQuantileTDigestWeighted, true, std::conditional_t<float_return, Float32, void>, false>;
|
template <typename Value, bool float_return> using FuncQuantileTDigestWeighted = AggregateFunctionQuantile<Value, QuantileTDigest<Value>, NameQuantileTDigestWeighted, true, std::conditional_t<float_return, Float32, void>, false>;
|
||||||
template <typename Value, bool float_return> using FuncQuantilesTDigestWeighted = AggregateFunctionQuantile<Value, QuantileTDigest<Value>, NameQuantilesTDigestWeighted, true, std::conditional_t<float_return, Float32, void>, true>;
|
template <typename Value, bool float_return> using FuncQuantilesTDigestWeighted = AggregateFunctionQuantile<Value, QuantileTDigest<Value>, NameQuantilesTDigestWeighted, true, std::conditional_t<float_return, Float32, void>, true>;
|
||||||
|
|
||||||
template <typename Value, bool float_return> using FuncQuantileBfloat16 = AggregateFunctionQuantile<Value, QuantileBfloat16Histogram<Value>, NameQuantileBfloat16, false, std::conditional_t<float_return, Float64, void>, false>;
|
template <typename Value, bool float_return> using FuncQuantileBFloat16 = AggregateFunctionQuantile<Value, QuantileBFloat16Histogram<Value>, NameQuantileBFloat16, false, std::conditional_t<float_return, Float64, void>, false>;
|
||||||
template <typename Value, bool float_return> using FuncQuantilesBfloat16 = AggregateFunctionQuantile<Value, QuantileBfloat16Histogram<Value>, NameQuantilesBfloat16, false, std::conditional_t<float_return, Float64, void>, true>;
|
template <typename Value, bool float_return> using FuncQuantilesBFloat16 = AggregateFunctionQuantile<Value, QuantileBFloat16Histogram<Value>, NameQuantilesBFloat16, false, std::conditional_t<float_return, Float64, void>, true>;
|
||||||
|
|
||||||
|
|
||||||
template <template <typename, bool> class Function>
|
template <template <typename, bool> class Function>
|
||||||
@ -158,8 +158,8 @@ void registerAggregateFunctionsQuantile(AggregateFunctionFactory & factory)
|
|||||||
factory.registerFunction(NameQuantileTDigestWeighted::name, createAggregateFunctionQuantile<FuncQuantileTDigestWeighted>);
|
factory.registerFunction(NameQuantileTDigestWeighted::name, createAggregateFunctionQuantile<FuncQuantileTDigestWeighted>);
|
||||||
factory.registerFunction(NameQuantilesTDigestWeighted::name, createAggregateFunctionQuantile<FuncQuantilesTDigestWeighted>);
|
factory.registerFunction(NameQuantilesTDigestWeighted::name, createAggregateFunctionQuantile<FuncQuantilesTDigestWeighted>);
|
||||||
|
|
||||||
factory.registerFunction(NameQuantileBfloat16::name, createAggregateFunctionQuantile<FuncQuantileBfloat16>);
|
factory.registerFunction(NameQuantileBFloat16::name, createAggregateFunctionQuantile<FuncQuantileBFloat16>);
|
||||||
factory.registerFunction(NameQuantilesBfloat16::name, createAggregateFunctionQuantile<FuncQuantilesBfloat16>);
|
factory.registerFunction(NameQuantilesBFloat16::name, createAggregateFunctionQuantile<FuncQuantilesBFloat16>);
|
||||||
|
|
||||||
/// 'median' is an alias for 'quantile'
|
/// 'median' is an alias for 'quantile'
|
||||||
factory.registerAlias("median", NameQuantile::name);
|
factory.registerAlias("median", NameQuantile::name);
|
||||||
@ -172,7 +172,7 @@ void registerAggregateFunctionsQuantile(AggregateFunctionFactory & factory)
|
|||||||
factory.registerAlias("medianTimingWeighted", NameQuantileTimingWeighted::name);
|
factory.registerAlias("medianTimingWeighted", NameQuantileTimingWeighted::name);
|
||||||
factory.registerAlias("medianTDigest", NameQuantileTDigest::name);
|
factory.registerAlias("medianTDigest", NameQuantileTDigest::name);
|
||||||
factory.registerAlias("medianTDigestWeighted", NameQuantileTDigestWeighted::name);
|
factory.registerAlias("medianTDigestWeighted", NameQuantileTDigestWeighted::name);
|
||||||
factory.registerAlias("medianBfloat16", NameQuantileBfloat16::name);
|
factory.registerAlias("medianBFloat16", NameQuantileBFloat16::name);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
#include <AggregateFunctions/QuantileExactWeighted.h>
|
#include <AggregateFunctions/QuantileExactWeighted.h>
|
||||||
#include <AggregateFunctions/QuantileTiming.h>
|
#include <AggregateFunctions/QuantileTiming.h>
|
||||||
#include <AggregateFunctions/QuantileTDigest.h>
|
#include <AggregateFunctions/QuantileTDigest.h>
|
||||||
#include <AggregateFunctions/QuantileBfloat16Histogram.h>
|
#include <AggregateFunctions/QuantileBFloat16Histogram.h>
|
||||||
|
|
||||||
#include <AggregateFunctions/IAggregateFunction.h>
|
#include <AggregateFunctions/IAggregateFunction.h>
|
||||||
#include <AggregateFunctions/QuantilesCommon.h>
|
#include <AggregateFunctions/QuantilesCommon.h>
|
||||||
@ -229,7 +229,7 @@ struct NameQuantileTDigestWeighted { static constexpr auto name = "quantileTDige
|
|||||||
struct NameQuantilesTDigest { static constexpr auto name = "quantilesTDigest"; };
|
struct NameQuantilesTDigest { static constexpr auto name = "quantilesTDigest"; };
|
||||||
struct NameQuantilesTDigestWeighted { static constexpr auto name = "quantilesTDigestWeighted"; };
|
struct NameQuantilesTDigestWeighted { static constexpr auto name = "quantilesTDigestWeighted"; };
|
||||||
|
|
||||||
struct NameQuantileBfloat16 { static constexpr auto name = "quantileBfloat16"; };
|
struct NameQuantileBFloat16 { static constexpr auto name = "quantileBFloat16"; };
|
||||||
struct NameQuantilesBfloat16 { static constexpr auto name = "quantilesBfloat16"; };
|
struct NameQuantilesBFloat16 { static constexpr auto name = "quantilesBFloat16"; };
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ namespace ErrorCodes
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename Value>
|
template <typename Value>
|
||||||
struct Bfloat16Histogram
|
struct BFloat16Histogram
|
||||||
{
|
{
|
||||||
using bfloat16 = UInt16;
|
using bfloat16 = UInt16;
|
||||||
using Data = HashMap<bfloat16, size_t>;
|
using Data = HashMap<bfloat16, size_t>;
|
||||||
@ -39,7 +39,7 @@ struct Bfloat16Histogram
|
|||||||
data[val] += to_add;
|
data[val] += to_add;
|
||||||
}
|
}
|
||||||
|
|
||||||
void merge(const Bfloat16Histogram & rhs)
|
void merge(const BFloat16Histogram & rhs)
|
||||||
{
|
{
|
||||||
for (const Float32 & value : rhs.array)
|
for (const Float32 & value : rhs.array)
|
||||||
{
|
{
|
@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AggregateFunctions/Bfloat16Histogram.h>
|
#include <AggregateFunctions/BFloat16Histogram.h>
|
||||||
|
|
||||||
namespace DB
|
namespace DB
|
||||||
{
|
{
|
||||||
@ -10,9 +10,9 @@ namespace ErrorCodes
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename Value>
|
template <typename Value>
|
||||||
struct QuantileBfloat16Histogram
|
struct QuantileBFloat16Histogram
|
||||||
{
|
{
|
||||||
using Histogram = Bfloat16Histogram<Value>;
|
using Histogram = BFloat16Histogram<Value>;
|
||||||
Histogram data;
|
Histogram data;
|
||||||
|
|
||||||
void add(const Value & x) { data.add(x); }
|
void add(const Value & x) { data.add(x); }
|
||||||
@ -20,10 +20,10 @@ struct QuantileBfloat16Histogram
|
|||||||
template <typename Weight>
|
template <typename Weight>
|
||||||
void add(const Value &, const Weight &)
|
void add(const Value &, const Weight &)
|
||||||
{
|
{
|
||||||
throw Exception("Method add with weight is not implemented for QuantileBfloat16Histogram", ErrorCodes::NOT_IMPLEMENTED);
|
throw Exception("Method add with weight is not implemented for QuantileBFloat16Histogram", ErrorCodes::NOT_IMPLEMENTED);
|
||||||
}
|
}
|
||||||
|
|
||||||
void merge(const QuantileBfloat16Histogram & rhs) { data.merge(rhs.data); }
|
void merge(const QuantileBFloat16Histogram & rhs) { data.merge(rhs.data); }
|
||||||
|
|
||||||
void serialize(WriteBuffer & buf) const { data.write(buf); }
|
void serialize(WriteBuffer & buf) const { data.write(buf); }
|
||||||
|
|
@ -27,7 +27,7 @@ SELECT quantilesTDigest(0.2)(d) FROM datetime;
|
|||||||
SELECT quantileTDigestWeighted(0.2)(d, 1) FROM datetime;
|
SELECT quantileTDigestWeighted(0.2)(d, 1) FROM datetime;
|
||||||
SELECT quantilesTDigestWeighted(0.2)(d, 1) FROM datetime;
|
SELECT quantilesTDigestWeighted(0.2)(d, 1) FROM datetime;
|
||||||
|
|
||||||
SELECT quantileBfloat16(0.2)(d) FROM datetime;
|
SELECT quantileBFloat16(0.2)(d) FROM datetime;
|
||||||
SELECT quantilesBfloat16(0.2)(d) FROM datetime;
|
SELECT quantilesBFloat16(0.2)(d) FROM datetime;
|
||||||
|
|
||||||
DROP TABLE datetime;
|
DROP TABLE datetime;
|
||||||
|
@ -8,8 +8,8 @@ FROM
|
|||||||
arrayFilter(x -> x != intDiv(number, 10), arr) AS arr_filtered
|
arrayFilter(x -> x != intDiv(number, 10), arr) AS arr_filtered
|
||||||
SELECT
|
SELECT
|
||||||
number,
|
number,
|
||||||
arrayReduce('quantileBfloat16', arr_with_nan) AS q1,
|
arrayReduce('quantileBFloat16', arr_with_nan) AS q1,
|
||||||
arrayReduce('quantileBfloat16', arr_filtered) AS q2,
|
arrayReduce('quantileBFloat16', arr_filtered) AS q2,
|
||||||
q1 = q2 AS eq
|
q1 = q2 AS eq
|
||||||
FROM
|
FROM
|
||||||
numbers(100)
|
numbers(100)
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
SELECT CounterID AS k, quantileBfloat16(0.5)(ResolutionWidth) FROM test.hits GROUP BY k ORDER BY count() DESC, CounterID LIMIT 10;
|
SELECT CounterID AS k, quantileBFloat16(0.5)(ResolutionWidth) FROM test.hits GROUP BY k ORDER BY count() DESC, CounterID LIMIT 10;
|
||||||
SELECT CounterID AS k, quantilesBfloat16(0.1, 0.5, 0.9, 0.99, 0.999)(ResolutionWidth) FROM test.hits GROUP BY k ORDER BY count() DESC, CounterID LIMIT 10;
|
SELECT CounterID AS k, quantilesBFloat16(0.1, 0.5, 0.9, 0.99, 0.999)(ResolutionWidth) FROM test.hits GROUP BY k ORDER BY count() DESC, CounterID LIMIT 10;
|
||||||
|
|
||||||
|
|
||||||
SELECT CounterID AS k, quantileBfloat16(0.5)(ResolutionWidth) FROM remote('127.0.0.{1,2}', test.hits) GROUP BY k ORDER BY count() DESC, CounterID LIMIT 10;
|
SELECT CounterID AS k, quantileBFloat16(0.5)(ResolutionWidth) FROM remote('127.0.0.{1,2}', test.hits) GROUP BY k ORDER BY count() DESC, CounterID LIMIT 10;
|
||||||
SELECT CounterID AS k, quantilesBfloat16(0.1, 0.5, 0.9, 0.99, 0.999)(ResolutionWidth) FROM remote('127.0.0.{1,2}', test.hits) GROUP BY k ORDER BY count() DESC, CounterID LIMIT 10;
|
SELECT CounterID AS k, quantilesBFloat16(0.1, 0.5, 0.9, 0.99, 0.999)(ResolutionWidth) FROM remote('127.0.0.{1,2}', test.hits) GROUP BY k ORDER BY count() DESC, CounterID LIMIT 10;
|
||||||
|
Loading…
Reference in New Issue
Block a user