Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions ddsketch/ddsketch.go
Original file line number Diff line number Diff line change
Expand Up @@ -613,11 +613,11 @@ func (s *DDSketchWithExactSummaryStatistics) GetMaxValue() (float64, error) {
func (s *DDSketchWithExactSummaryStatistics) GetValueAtQuantile(quantile float64) (float64, error) {
value, err := s.DDSketch.GetValueAtQuantile(quantile)
min := s.summaryStatistics.Min()
if value < min {
if quantile == 0 || quantile < 1 && value < min {
return min, err
}
max := s.summaryStatistics.Max()
if value > max {
if quantile == 1 || value > max {
return max, err
}
return value, err
Expand All @@ -628,9 +628,9 @@ func (s *DDSketchWithExactSummaryStatistics) GetValuesAtQuantiles(quantiles []fl
min := s.summaryStatistics.Min()
max := s.summaryStatistics.Max()
for i := range values {
if values[i] < min {
if quantiles[i] == 0 || quantiles[i] < 1 && values[i] < min {
values[i] = min
} else if values[i] > max {
} else if quantiles[i] == 1 || values[i] > max {
values[i] = max
}
}
Expand Down
9 changes: 8 additions & 1 deletion ddsketch/ddsketch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package ddsketch

import (
"bytes"
"github.com/stretchr/testify/require"
"math"
"math/rand"
"testing"
Expand All @@ -22,6 +21,7 @@ import (

fuzz "github.com/google/gofuzz"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

const (
Expand Down Expand Up @@ -179,6 +179,13 @@ func assertSketchesAccurate(t *testing.T, data *dataset.Dataset, sketch quantile
assertRelativelyAccurate(assert, alpha, lowerQuantile, upperQuantile, quantile)
assert.LessOrEqual(minValue, quantile)
assert.GreaterOrEqual(maxValue, quantile)
if exactSummaryStatistics {
if q == 0 {
assert.Equal(expectedMinValue, quantile)
} else if q == 1 {
assert.Equal(expectedMaxValue, quantile)
}
}
quantiles, quantilesErr := sketch.GetValuesAtQuantiles([]float64{q, q})
assert.Nil(quantilesErr)
assert.Len(quantiles, 2)
Expand Down