[Bug-Fix] Fix the bug of PERCENTILE_APPROX return error result nan and add PERCENTILE_APPROX UT (#5172)

This commit is contained in:
HappenLee
2021-01-03 15:45:22 +08:00
committed by GitHub
parent 9e19b6b133
commit f2cf8d2c5e
2 changed files with 28 additions and 2 deletions

View File

@ -177,9 +177,10 @@ public:
PercentileApproxState() : digest(new TDigest()) {}
PercentileApproxState(double compression) : digest(new TDigest(compression)) {}
~PercentileApproxState() { delete digest; }
static constexpr double INIT_QUANTILE = -1.0;
TDigest* digest = nullptr;
double targetQuantile = -1.0;
double targetQuantile = INIT_QUANTILE;
};
void AggregateFunctions::percentile_approx_init(FunctionContext* ctx, StringVal* dst) {
@ -255,7 +256,12 @@ void AggregateFunctions::percentile_approx_merge(FunctionContext* ctx, const Str
PercentileApproxState* dst_percentile = reinterpret_cast<PercentileApproxState*>(dst->ptr);
dst_percentile->digest->merge(src_percentile->digest);
dst_percentile->targetQuantile = quantile;
// dst_percentile->targetQuantile only need set once from child result
// for example:
// child result targetQuantile is (0.5, -1), we should set 0.5 once to make sure correct result
if (dst_percentile->targetQuantile == PercentileApproxState::INIT_QUANTILE) {
dst_percentile->targetQuantile = quantile;
}
delete src_percentile;
}