Skip to content

Commit

Permalink
Implement TDigestHistogram#toString
Browse files Browse the repository at this point in the history
  • Loading branch information
rzeyde-varada authored and sopel39 committed Nov 25, 2021
1 parent ef5084c commit 9a824be
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@

import java.util.Base64;

import static com.google.common.base.MoreObjects.ToStringHelper;
import static com.google.common.base.MoreObjects.toStringHelper;
import static io.airlift.slice.Slices.wrappedBuffer;
import static java.lang.String.format;

public class TDigestHistogram
implements Distribution<TDigestHistogram>
Expand Down Expand Up @@ -66,6 +69,16 @@ public double getPercentile(double percentile)
return digest.valueAt(percentile / 100.0);
}

@Override
public String toString()
{
ToStringHelper helper = toStringHelper(this).add("count", digest.getCount());
for (int q = 0; q <= 100; q += 10) {
helper.add(format("p%d", q), getPercentile(q));
}
return helper.toString();
}

public static class TDigestToBase64Converter
extends StdConverter<TDigest, String>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public void testMergeHistogram()
assertThat(merged.getTotal()).isEqualTo(3L);
assertThat(merged.getPercentile(0)).isEqualTo(5.0);
assertThat(merged.getPercentile(100)).isEqualTo(10.0);
assertThat(merged.toString()).matches("TDigestHistogram\\{count=3.0, p0=5\\.0, p10=5\\.0, .*, p90=10\\.0, p100=10\\.0\\}");
}

@Test
Expand Down

0 comments on commit 9a824be

Please sign in to comment.