rename func to quantileInterpolatedWeighted

This commit is contained in:
Bharat Nallan Chakravarthy 2022-07-09 14:02:39 +05:30
parent f4488dfee1
commit 054ce6f712
9 changed files with 53 additions and 79 deletions

View File

@ -41,8 +41,8 @@ template <typename Value, bool _> using FuncQuantilesExactInclusive = AggregateF
template <typename Value, bool _> using FuncQuantileExactWeighted = AggregateFunctionQuantile<Value, QuantileExactWeighted<Value>, NameQuantileExactWeighted, true, void, false>;
template <typename Value, bool _> using FuncQuantilesExactWeighted = AggregateFunctionQuantile<Value, QuantileExactWeighted<Value>, NameQuantilesExactWeighted, true, void, true>;
template <typename Value, bool _> using FuncQuantileApproximateWeighted = AggregateFunctionQuantile<Value, QuantileApproximateWeighted<Value>, NameQuantileApproximateWeighted, true, void, false>;
template <typename Value, bool _> using FuncQuantilesApproximateWeighted = AggregateFunctionQuantile<Value, QuantileApproximateWeighted<Value>, NameQuantilesApproximateWeighted, true, void, true>;
template <typename Value, bool _> using FuncQuantileInterpolatedWeighted = AggregateFunctionQuantile<Value, QuantileInterpolatedWeighted<Value>, NameQuantileInterpolatedWeighted, true, void, false>;
template <typename Value, bool _> using FuncQuantilesInterpolatedWeighted = AggregateFunctionQuantile<Value, QuantileInterpolatedWeighted<Value>, NameQuantilesInterpolatedWeighted, true, void, true>;
template <typename Value, bool _> using FuncQuantileTiming = AggregateFunctionQuantile<Value, QuantileTiming<Value>, NameQuantileTiming, false, Float32, false>;
template <typename Value, bool _> using FuncQuantilesTiming = AggregateFunctionQuantile<Value, QuantileTiming<Value>, NameQuantilesTiming, false, Float32, true>;
@ -75,8 +75,8 @@ constexpr bool supportDecimal()
std::is_same_v<Function<Float32, false>, FuncQuantilesExactHigh<Float32, false>> ||
std::is_same_v<Function<Float32, false>, FuncQuantileExactWeighted<Float32, false>> ||
std::is_same_v<Function<Float32, false>, FuncQuantilesExactWeighted<Float32, false>> ||
std::is_same_v<Function<Float32, false>, FuncQuantileApproximateWeighted<Float32, false>> ||
std::is_same_v<Function<Float32, false>, FuncQuantilesApproximateWeighted<Float32, false>>;
std::is_same_v<Function<Float32, false>, FuncQuantileInterpolatedWeighted<Float32, false>> ||
std::is_same_v<Function<Float32, false>, FuncQuantilesInterpolatedWeighted<Float32, false>>;
}
template <template <typename, bool> class Function>
@ -88,8 +88,8 @@ constexpr bool supportBigInt()
std::is_same_v<Function<Float32, false>, FuncQuantilesExact<Float32, false>> ||
std::is_same_v<Function<Float32, false>, FuncQuantileExactWeighted<Float32, false>> ||
std::is_same_v<Function<Float32, false>, FuncQuantilesExactWeighted<Float32, false>> ||
std::is_same_v<Function<Float32, false>, FuncQuantilesApproximateWeighted<Float32, false>> ||
std::is_same_v<Function<Float32, false>, FuncQuantilesApproximateWeighted<Float32, false>>;
std::is_same_v<Function<Float32, false>, FuncQuantilesInterpolatedWeighted<Float32, false>> ||
std::is_same_v<Function<Float32, false>, FuncQuantilesInterpolatedWeighted<Float32, false>>;
}
template <template <typename, bool> class Function>
@ -161,8 +161,8 @@ void registerAggregateFunctionsQuantile(AggregateFunctionFactory & factory)
factory.registerFunction(NameQuantileExactWeighted::name, createAggregateFunctionQuantile<FuncQuantileExactWeighted>);
factory.registerFunction(NameQuantilesExactWeighted::name, { createAggregateFunctionQuantile<FuncQuantilesExactWeighted>, properties });
factory.registerFunction(NameQuantileApproximateWeighted::name, createAggregateFunctionQuantile<FuncQuantileApproximateWeighted>);
factory.registerFunction(NameQuantilesApproximateWeighted::name, { createAggregateFunctionQuantile<FuncQuantilesApproximateWeighted>, properties });
factory.registerFunction(NameQuantileInterpolatedWeighted::name, createAggregateFunctionQuantile<FuncQuantileInterpolatedWeighted>);
factory.registerFunction(NameQuantilesInterpolatedWeighted::name, { createAggregateFunctionQuantile<FuncQuantilesInterpolatedWeighted>, properties });
factory.registerFunction(NameQuantileTiming::name, createAggregateFunctionQuantile<FuncQuantileTiming>);
factory.registerFunction(NameQuantilesTiming::name, { createAggregateFunctionQuantile<FuncQuantilesTiming>, properties });
@ -189,7 +189,7 @@ void registerAggregateFunctionsQuantile(AggregateFunctionFactory & factory)
factory.registerAlias("medianExactLow", NameQuantileExactLow::name);
factory.registerAlias("medianExactHigh", NameQuantileExactHigh::name);
factory.registerAlias("medianExactWeighted", NameQuantileExactWeighted::name);
factory.registerAlias("medianApproximateWeighted", NameQuantileApproximateWeighted::name);
factory.registerAlias("medianInterpolatedWeighted", NameQuantileInterpolatedWeighted::name);
factory.registerAlias("medianTiming", NameQuantileTiming::name);
factory.registerAlias("medianTimingWeighted", NameQuantileTimingWeighted::name);
factory.registerAlias("medianTDigest", NameQuantileTDigest::name);

View File

@ -3,14 +3,14 @@
#include <AggregateFunctions/FactoryHelpers.h>
/// These must be exposed in header for the purpose of dynamic compilation.
#include <AggregateFunctions/QuantileReservoirSampler.h>
#include <AggregateFunctions/QuantileReservoirSamplerDeterministic.h>
#include <AggregateFunctions/QuantileBFloat16Histogram.h>
#include <AggregateFunctions/QuantileExact.h>
#include <AggregateFunctions/QuantileExactWeighted.h>
#include <AggregateFunctions/QuantileApproximateWeighted.h>
#include <AggregateFunctions/QuantileTiming.h>
#include <AggregateFunctions/QuantileInterpolatedWeighted.h>
#include <AggregateFunctions/QuantileReservoirSampler.h>
#include <AggregateFunctions/QuantileReservoirSamplerDeterministic.h>
#include <AggregateFunctions/QuantileTDigest.h>
#include <AggregateFunctions/QuantileBFloat16Histogram.h>
#include <AggregateFunctions/QuantileTiming.h>
#include <AggregateFunctions/IAggregateFunction.h>
#include <AggregateFunctions/QuantilesCommon.h>
@ -226,8 +226,8 @@ struct NameQuantilesExactInclusive { static constexpr auto name = "quantilesExac
struct NameQuantileExactWeighted { static constexpr auto name = "quantileExactWeighted"; };
struct NameQuantilesExactWeighted { static constexpr auto name = "quantilesExactWeighted"; };
struct NameQuantileApproximateWeighted { static constexpr auto name = "quantileApproximateWeighted"; };
struct NameQuantilesApproximateWeighted { static constexpr auto name = "quantilesApproximateWeighted"; };
struct NameQuantileInterpolatedWeighted { static constexpr auto name = "quantileInterpolatedWeighted"; };
struct NameQuantilesInterpolatedWeighted { static constexpr auto name = "quantilesInterpolatedWeighted"; };
struct NameQuantileTiming { static constexpr auto name = "quantileTiming"; };
struct NameQuantileTimingWeighted { static constexpr auto name = "quantileTimingWeighted"; };

View File

@ -22,7 +22,7 @@ namespace ErrorCodes
*
*/
template <typename Value>
struct QuantileApproximateWeighted
struct QuantileInterpolatedWeighted
{
struct Int128Hash
{
@ -54,7 +54,7 @@ struct QuantileApproximateWeighted
map[x] += weight;
}
void merge(const QuantileApproximateWeighted & rhs)
void merge(const QuantileInterpolatedWeighted & rhs)
{
for (const auto & pair : rhs.map)
map[pair.getKey()] += pair.getMapped();
@ -327,12 +327,12 @@ struct QuantileApproximateWeighted
/// The same, but in the case of an empty state, NaN is returned.
Float64 getFloat(Float64) const
{
throw Exception("Method getFloat is not implemented for QuantileApproximateWeighted", ErrorCodes::NOT_IMPLEMENTED);
throw Exception("Method getFloat is not implemented for QuantileInterpolatedWeighted", ErrorCodes::NOT_IMPLEMENTED);
}
void getManyFloat(const Float64 *, const size_t *, size_t, Float64 *) const
{
throw Exception("Method getManyFloat is not implemented for QuantileApproximateWeighted", ErrorCodes::NOT_IMPLEMENTED);
throw Exception("Method getManyFloat is not implemented for QuantileInterpolatedWeighted", ErrorCodes::NOT_IMPLEMENTED);
}
};

View File

@ -24,7 +24,7 @@ static const std::unordered_map<String, String> quantile_fuse_name_mapping = {
{NameQuantileExactInclusive::name, NameQuantilesExactInclusive::name},
{NameQuantileExactLow::name, NameQuantilesExactLow::name},
{NameQuantileExactWeighted::name, NameQuantilesExactWeighted::name},
{NameQuantileApproximateWeighted::name, NameQuantilesApproximateWeighted::name},
{NameQuantileInterpolatedWeighted::name, NameQuantilesInterpolatedWeighted::name},
{NameQuantileTDigest::name, NameQuantilesTDigest::name},
{NameQuantileTDigestWeighted::name, NameQuantilesTDigestWeighted::name},
{NameQuantileTiming::name, NameQuantilesTiming::name},
@ -56,7 +56,7 @@ void GatherFunctionQuantileData::FuseQuantileAggregatesData::addFuncNode(ASTPtr
bool need_two_args = func->name == NameQuantileDeterministic::name
|| func->name == NameQuantileExactWeighted::name
|| func->name == NameQuantileApproximateWeighted::name
|| func->name == NameQuantileInterpolatedWeighted::name
|| func->name == NameQuantileTimingWeighted::name
|| func->name == NameQuantileTDigestWeighted::name
|| func->name == NameQuantileBFloat16Weighted::name;

View File

@ -1,4 +1,4 @@
SELECT quantileExactWeighted(0.5)(x, 1) AS q5, quantilesExactWeighted(0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1)(x, 1) AS qs FROM (SELECT arrayJoin([1, 1, 1, 10, 10, 10, 10, 100, 100, 100]) AS x);
SELECT quantileApproximateWeighted(0.5)(x, 1) AS q5, quantilesApproximateWeighted(0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1)(x, 1) AS qs FROM (SELECT arrayJoin([1, 1, 1, 10, 10, 10, 10, 100, 100, 100]) AS x);
SELECT quantileInterpolatedWeighted(0.5)(x, 1) AS q5, quantilesInterpolatedWeighted(0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1)(x, 1) AS qs FROM (SELECT arrayJoin([1, 1, 1, 10, 10, 10, 10, 100, 100, 100]) AS x);
SELECT quantileExact(0)(x), quantileTiming(0)(x) FROM (SELECT number + 100 AS x FROM system.numbers LIMIT 10000);
SELECT quantileExact(x), quantileTiming(x) FROM (SELECT number % 123 AS x FROM system.numbers LIMIT 10000);

View File

@ -15,8 +15,8 @@ SELECT quantilesExact(0.2)(d) FROM datetime;
SELECT quantileExactWeighted(0.2)(d, 1) FROM datetime;
SELECT quantilesExactWeighted(0.2)(d, 1) FROM datetime;
SELECT quantileApproximateWeighted(0.2)(d, 1) FROM datetime;
SELECT quantilesApproximateWeighted(0.2)(d, 1) FROM datetime;
SELECT quantileInterpolatedWeighted(0.2)(d, 1) FROM datetime;
SELECT quantilesInterpolatedWeighted(0.2)(d, 1) FROM datetime;
SELECT quantileTiming(0.2)(d) FROM datetime;
SELECT quantilesTiming(0.2)(d) FROM datetime;

View File

@ -1,41 +0,0 @@
DROP TABLE IF EXISTS decimal;
CREATE TABLE decimal
(
a Decimal32(4),
b Decimal64(8),
c Decimal128(8)
) ENGINE = Memory;
INSERT INTO decimal (a, b, c)
SELECT toDecimal32(number - 50, 4), toDecimal64(number - 50, 8) / 3, toDecimal128(number - 50, 8) / 5
FROM system.numbers LIMIT 101;
SELECT 'quantileExactWeighted';
SELECT medianExactWeighted(a, 1), medianExactWeighted(b, 2), medianExactWeighted(c, 3) as x, toTypeName(x) FROM decimal;
SELECT quantileExactWeighted(a, 1), quantileExactWeighted(b, 2), quantileExactWeighted(c, 3) as x, toTypeName(x) FROM decimal WHERE a < 0;
SELECT quantileExactWeighted(0.0)(a, 1), quantileExactWeighted(0.0)(b, 2), quantileExactWeighted(0.0)(c, 3) FROM decimal WHERE a >= 0;
SELECT quantileExactWeighted(0.2)(a, 1), quantileExactWeighted(0.2)(b, 2), quantileExactWeighted(0.2)(c, 3) FROM decimal WHERE a >= 0;
SELECT quantileExactWeighted(0.4)(a, 1), quantileExactWeighted(0.4)(b, 2), quantileExactWeighted(0.4)(c, 3) FROM decimal WHERE a >= 0;
SELECT quantileExactWeighted(0.6)(a, 1), quantileExactWeighted(0.6)(b, 2), quantileExactWeighted(0.6)(c, 3) FROM decimal WHERE a >= 0;
SELECT quantileExactWeighted(0.8)(a, 1), quantileExactWeighted(0.8)(b, 2), quantileExactWeighted(0.8)(c, 3) FROM decimal WHERE a >= 0;
SELECT quantileExactWeighted(1.0)(a, 1), quantileExactWeighted(1.0)(b, 2), quantileExactWeighted(1.0)(c, 3) FROM decimal WHERE a >= 0;
SELECT quantilesExactWeighted(0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0)(a, 1) FROM decimal;
SELECT quantilesExactWeighted(0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0)(b, 2) FROM decimal;
SELECT quantilesExactWeighted(0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0)(c, 3) FROM decimal;
SELECT 'quantileApproximateWeighted';
SELECT medianApproximateWeighted(a, 1), medianApproximateWeighted(b, 2), medianApproximateWeighted(c, 3) as x, toTypeName(x) FROM decimal;
SELECT quantileApproximateWeighted(a, 1), quantileApproximateWeighted(b, 2), quantileApproximateWeighted(c, 3) as x, toTypeName(x) FROM decimal WHERE a < 0;
SELECT quantileApproximateWeighted(0.0)(a, 1), quantileApproximateWeighted(0.0)(b, 2), quantileApproximateWeighted(0.0)(c, 3) FROM decimal WHERE a >= 0;
SELECT quantileApproximateWeighted(0.2)(a, 1), quantileApproximateWeighted(0.2)(b, 2), quantileApproximateWeighted(0.2)(c, 3) FROM decimal WHERE a >= 0;
SELECT quantileApproximateWeighted(0.4)(a, 1), quantileApproximateWeighted(0.4)(b, 2), quantileApproximateWeighted(0.4)(c, 3) FROM decimal WHERE a >= 0;
SELECT quantileApproximateWeighted(0.6)(a, 1), quantileApproximateWeighted(0.6)(b, 2), quantileApproximateWeighted(0.6)(c, 3) FROM decimal WHERE a >= 0;
SELECT quantileApproximateWeighted(0.8)(a, 1), quantileApproximateWeighted(0.8)(b, 2), quantileApproximateWeighted(0.8)(c, 3) FROM decimal WHERE a >= 0;
SELECT quantileApproximateWeighted(1.0)(a, 1), quantileApproximateWeighted(1.0)(b, 2), quantileApproximateWeighted(1.0)(c, 3) FROM decimal WHERE a >= 0;
SELECT quantilesApproximateWeighted(0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0)(a, 1) FROM decimal;
SELECT quantilesApproximateWeighted(0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0)(b, 2) FROM decimal;
SELECT quantilesApproximateWeighted(0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0)(c, 3) FROM decimal;
DROP TABLE IF EXISTS decimal;

View File

@ -1,16 +1,4 @@
quantileExactWeighted
0 0 0 Decimal(38, 8)
-26 -8.66666666 -5.2 Decimal(38, 8)
0 0 0
10 3.33333333 2
20 6.66666666 4
30 10 6
40 13.33333333 8
50 16.66666666 10
[-50,-40,-30,-20,-10,0,10,20,30,40,50]
[-16.66666666,-13.33333333,-10,-6.66666666,-3.33333333,0,3.33333333,6.66666666,10,13.33333333,16.66666666]
[-10,-8,-6,-4,-2,0,2,4,6,8,10]
quantileApproximateWeighted
quantileInterpolatedWeighted
0 0 0 Decimal(38, 8)
-25.5 -8.49999999 -5.1 Decimal(38, 8)
0 0 0

View File

@ -0,0 +1,27 @@
DROP TABLE IF EXISTS decimal;
CREATE TABLE decimal
(
a Decimal32(4),
b Decimal64(8),
c Decimal128(8)
) ENGINE = Memory;
INSERT INTO decimal (a, b, c)
SELECT toDecimal32(number - 50, 4), toDecimal64(number - 50, 8) / 3, toDecimal128(number - 50, 8) / 5
FROM system.numbers LIMIT 101;
SELECT 'quantileInterpolatedWeighted';
SELECT medianInterpolatedWeighted(a, 1), medianInterpolatedWeighted(b, 2), medianInterpolatedWeighted(c, 3) as x, toTypeName(x) FROM decimal;
SELECT quantileInterpolatedWeighted(a, 1), quantileInterpolatedWeighted(b, 2), quantileInterpolatedWeighted(c, 3) as x, toTypeName(x) FROM decimal WHERE a < 0;
SELECT quantileInterpolatedWeighted(0.0)(a, 1), quantileInterpolatedWeighted(0.0)(b, 2), quantileInterpolatedWeighted(0.0)(c, 3) FROM decimal WHERE a >= 0;
SELECT quantileInterpolatedWeighted(0.2)(a, 1), quantileInterpolatedWeighted(0.2)(b, 2), quantileInterpolatedWeighted(0.2)(c, 3) FROM decimal WHERE a >= 0;
SELECT quantileInterpolatedWeighted(0.4)(a, 1), quantileInterpolatedWeighted(0.4)(b, 2), quantileInterpolatedWeighted(0.4)(c, 3) FROM decimal WHERE a >= 0;
SELECT quantileInterpolatedWeighted(0.6)(a, 1), quantileInterpolatedWeighted(0.6)(b, 2), quantileInterpolatedWeighted(0.6)(c, 3) FROM decimal WHERE a >= 0;
SELECT quantileInterpolatedWeighted(0.8)(a, 1), quantileInterpolatedWeighted(0.8)(b, 2), quantileInterpolatedWeighted(0.8)(c, 3) FROM decimal WHERE a >= 0;
SELECT quantileInterpolatedWeighted(1.0)(a, 1), quantileInterpolatedWeighted(1.0)(b, 2), quantileInterpolatedWeighted(1.0)(c, 3) FROM decimal WHERE a >= 0;
SELECT quantilesInterpolatedWeighted(0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0)(a, 1) FROM decimal;
SELECT quantilesInterpolatedWeighted(0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0)(b, 2) FROM decimal;
SELECT quantilesInterpolatedWeighted(0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0)(c, 3) FROM decimal;
DROP TABLE IF EXISTS decimal;