MCPcopy Index your code
hub / github.com/DataDog/sketches-java

github.com/DataDog/sketches-java @v0.8.3

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.8.3 ↗ · + Follow
755 symbols 2,187 edges 87 files 107 documented · 14% 2 cross-repo links updated 2mo agov0.8.3 · 2024-05-16★ 1323 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

sketches-java

This repo contains Java implementations of the distributed quantile sketch algorithm DDSketch [1]. DDSketch is mergeable, meaning that multiple sketches from distributed systems can be combined in a central node.

Quick start guide

sketches-java is available in the Maven Central Repository. See this page for easily adding it as a dependency to your project. You should then be able to import com.datadoghq.sketch.ddsketch.DDSketch.

The following code snippet shows the most basic features of DDSketch:

// Creating an initially empty sketch, with low memory footprint
double relativeAccuracy = 0.01;
DDSketch sketch = DDSketches.unboundedDense(relativeAccuracy);

// Adding values to the sketch
sketch.accept(3.2); // adds a single value
sketch.accept(2.1, 3); // adds multiple times the same value

// Querying the sketch
sketch.getValueAtQuantile(0.5); // returns the median value
sketch.getMinValue();
sketch.getMaxValue();

// Merging another sketch into the sketch, in-place
DDSketch anotherSketch = DDSketch.unboundedDense(relativeAccuracy);
DoubleStream.of(3.4, 7.6, 2.8).forEach(anotherSketch);
sketch.mergeWith(anotherSketch);

DDSketch

DDSketch has relative error guarantees: it computes quantiles with a controlled relative error.

For instance, using DDSketch with a relative accuracy guarantee set to 1%, if the expected quantile value is 100, the computed quantile value is guaranteed to be between 99 and 101. If the expected quantile value is 1000, the computed quantile value is guaranteed to be between 990 and 1010.

DDSketch works by mapping floating-point input values to bins and counting the number of values for each bin. The mapping to bins is handled by IndexMapping, while the underlying structure that keeps track of bin counts is Store. DDSketches.unboundedDense() constructs a sketch whose bin counts are backed by an array, therefore offering constant-time insertion. The array is grown as necessary to accommodate for the range of input values.

The size of the sketch can be upper-bounded by using collapsing stores. For instance, DDSketches.logarithmicCollapsingLowestDense() is the version of DDSketch described in the DDSketch paper. It collapses lowest bins when the maximum number of buckets is reached. See the DDSketches for more preset sketches and more details.

The memory size of the sketch depends on the range that is covered by the input values: the larger that range, the more bins are needed to keep track of the input values. As a rough estimate, if working on durations using DDSketches.unboundedDense(0.02) (relative accuracy of 2%), about 2kB (275 bins) are needed to cover values between 1 millisecond and 1 minute, and about 6kB (802 bins) to cover values between 1 nanosecond and 1 day. The number of bins that are maintained can be upper-bounded using collapsing stores (see for example DDSketches.collapsingLowestDense() and DDSketches.collapsingHighestDense()).

References

[1] Charles Masson, Jee E. Rim and Homin K. Lee. DDSketch: A Fast and Fully-Mergeable Quantile Sketch with Relative-Error Guarantees. 2019.

Extension points exported contracts — how you extend this code

Store (Interface)
An object that maps integers to counters. It can be seen as a collection of Bin, which are pairs of indices and [3 implementers]
src/main/java/com/datadoghq/sketch/ddsketch/store/Store.java
Distribution (Interface)
(no doc) [2 implementers]
src/jmh/java/com/datadoghq/sketch/ddsketch/Distribution.java
Distribution (Interface)
(no doc) [2 implementers]
src/test/java/com/datadoghq/sketch/ddsketch/footprint/Distribution.java
IndexMapping (Interface)
A mapping between double positive values and int values that imposes relative guarantees on the composit [2 implementers]
src/main/java/com/datadoghq/sketch/ddsketch/mapping/IndexMapping.java
BinAcceptor (Interface)
(no doc) [4 implementers]
src/main/java/com/datadoghq/sketch/ddsketch/store/BinAcceptor.java
Input (Interface)
A generic interface for reading data from a stream or an object. [1 implementers]
src/main/java/com/datadoghq/sketch/ddsketch/encoding/Input.java
Output (Interface)
A generic interface for writing to a stream or an object. [1 implementers]
src/main/java/com/datadoghq/sketch/ddsketch/encoding/Output.java

Core symbols most depended-on inside this repo

forEach
called by 37
src/main/java/com/datadoghq/sketch/ddsketch/store/Store.java
wrap
called by 26
src/main/java/com/datadoghq/sketch/ddsketch/encoding/ByteArrayInput.java
withDefaultInitialCapacity
called by 24
src/main/java/com/datadoghq/sketch/ddsketch/encoding/GrowingByteArrayOutput.java
max
called by 23
src/main/java/com/datadoghq/sketch/WithExactSummaryStatistics.java
isEmpty
called by 23
src/main/java/com/datadoghq/sketch/ddsketch/store/Store.java
encode
called by 21
src/main/java/com/datadoghq/sketch/ddsketch/store/Store.java
getCount
called by 19
src/main/java/com/datadoghq/sketch/QuantileSketch.java
backingArray
called by 19
src/main/java/com/datadoghq/sketch/ddsketch/encoding/GrowingByteArrayOutput.java

Shape

Method 649
Class 85
Interface 11
Enum 10

Languages

Java100%

Modules by API surface

src/test/java/com/datadoghq/sketch/QuantileSketchTest.java44 symbols
src/main/java/com/datadoghq/sketch/ddsketch/DDSketch.java41 symbols
src/main/java/com/datadoghq/sketch/ddsketch/store/PaginatedStore.java31 symbols
src/test/java/com/datadoghq/sketch/ddsketch/store/StoreTest.java30 symbols
src/main/java/com/datadoghq/sketch/ddsketch/store/DenseStore.java27 symbols
src/test/java/com/datadoghq/sketch/ddsketch/DDSketchTest.java26 symbols
src/main/java/com/datadoghq/sketch/ddsketch/mapping/LogLikeIndexMapping.java24 symbols
src/main/java/com/datadoghq/sketch/WithExactSummaryStatistics.java24 symbols
src/test/java/com/datadoghq/sketch/WithExactSummaryStatisticsTest.java22 symbols
src/main/java/com/datadoghq/sketch/ddsketch/Serializer.java21 symbols
src/main/java/com/datadoghq/sketch/ddsketch/store/Store.java19 symbols
src/main/java/com/datadoghq/sketch/ddsketch/mapping/BitwiseLinearlyInterpolatedMapping.java17 symbols

Used by 2 indexed graphs manifest dependencies, hub-wide

For agents

$ claude mcp add sketches-java \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact