Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BucketQuantile return NaN when count is ZERO #2131

Closed
yancl opened this Issue Oct 28, 2016 · 3 comments

Comments

Projects
None yet
2 participants
@yancl
Copy link

yancl commented Oct 28, 2016

Hi,

When testing our service with quantile, we found that the return value is NaN when there is
no request, that means the first bucket's count is zero, so will you please return the first bucket's upperBound or zero when the count is zero ?

// change
if count == 0 {
    return bucketEnd // or 0
}
return bucketStart + (bucketEnd-bucketStart)*float64(rank/count)
//source
func bucketQuantile(q model.SampleValue, buckets buckets) float64 {
    if q < 0 {
        return math.Inf(-1)
    }
    if q > 1 {
        return math.Inf(+1)
    }
    if len(buckets) < 2 {
        return math.NaN()
    }
    sort.Sort(buckets)
    if !math.IsInf(buckets[len(buckets)-1].upperBound, +1) {
        return math.NaN()
    }

    rank := q * buckets[len(buckets)-1].count
    b := sort.Search(len(buckets)-1, func(i int) bool { return buckets[i].count >= rank })

    if b == len(buckets)-1 {
        return buckets[len(buckets)-2].upperBound
    }
    if b == 0 && buckets[0].upperBound <= 0 {
        return buckets[0].upperBound
    }
    var (
        bucketStart float64
        bucketEnd   = buckets[b].upperBound
        count       = buckets[b].count
    )
    if b > 0 {
        bucketStart = buckets[b-1].upperBound
        count -= buckets[b-1].count
        rank -= buckets[b-1].count
    }
    return bucketStart + (bucketEnd-bucketStart)*float64(rank/count)
}
@brian-brazil

This comment has been minimized.

Copy link
Member

brian-brazil commented Oct 28, 2016

NaN is the correct result when there is no data. This is in line with _sum / _count which also returns NaN in that case.

@yancl

This comment has been minimized.

Copy link
Author

yancl commented Oct 28, 2016

ok, thanks:)

@yancl yancl closed this Oct 28, 2016

@lock

This comment has been minimized.

Copy link

lock bot commented Mar 24, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked and limited conversation to collaborators Mar 24, 2019

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.