| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
| <!-- NewPage --> |
| <html lang="en"> |
| <head> |
| <!-- Generated by javadoc --> |
| <title>TDigestQuantiles (Apache Beam 2.38.0-SNAPSHOT)</title> |
| <link rel="stylesheet" type="text/css" href="../../../../../../stylesheet.css" title="Style"> |
| <script type="text/javascript" src="../../../../../../script.js"></script> |
| </head> |
| <body> |
| <script type="text/javascript"><!-- |
| try { |
| if (location.href.indexOf('is-external=true') == -1) { |
| parent.document.title="TDigestQuantiles (Apache Beam 2.38.0-SNAPSHOT)"; |
| } |
| } |
| catch(err) { |
| } |
| //--> |
| var methods = {"i0":9,"i1":9}; |
| var tabs = {65535:["t0","All Methods"],1:["t1","Static Methods"],8:["t4","Concrete Methods"]}; |
| var altColor = "altColor"; |
| var rowColor = "rowColor"; |
| var tableTab = "tableTab"; |
| var activeTableTab = "activeTableTab"; |
| </script> |
| <noscript> |
| <div>JavaScript is disabled on your browser.</div> |
| </noscript> |
| <!-- ========= START OF TOP NAVBAR ======= --> |
| <div class="topNav"><a name="navbar.top"> |
| <!-- --> |
| </a> |
| <div class="skipNav"><a href="#skip.navbar.top" title="Skip navigation links">Skip navigation links</a></div> |
| <a name="navbar.top.firstrow"> |
| <!-- --> |
| </a> |
| <ul class="navList" title="Navigation"> |
| <li><a href="../../../../../../overview-summary.html">Overview</a></li> |
| <li><a href="package-summary.html">Package</a></li> |
| <li class="navBarCell1Rev">Class</li> |
| <li><a href="package-tree.html">Tree</a></li> |
| <li><a href="../../../../../../deprecated-list.html">Deprecated</a></li> |
| <li><a href="../../../../../../index-all.html">Index</a></li> |
| <li><a href="../../../../../../help-doc.html">Help</a></li> |
| </ul> |
| </div> |
| <div class="subNav"> |
| <ul class="navList"> |
| <li><a href="../../../../../../org/apache/beam/sdk/extensions/sketching/SketchFrequencies.Sketch.html" title="class in org.apache.beam.sdk.extensions.sketching"><span class="typeNameLink">Prev Class</span></a></li> |
| <li><a href="../../../../../../org/apache/beam/sdk/extensions/sketching/TDigestQuantiles.GlobalDigest.html" title="class in org.apache.beam.sdk.extensions.sketching"><span class="typeNameLink">Next Class</span></a></li> |
| </ul> |
| <ul class="navList"> |
| <li><a href="../../../../../../index.html?org/apache/beam/sdk/extensions/sketching/TDigestQuantiles.html" target="_top">Frames</a></li> |
| <li><a href="TDigestQuantiles.html" target="_top">No Frames</a></li> |
| </ul> |
| <ul class="navList" id="allclasses_navbar_top"> |
| <li><a href="../../../../../../allclasses-noframe.html">All Classes</a></li> |
| </ul> |
| <div> |
| <script type="text/javascript"><!-- |
| allClassesLink = document.getElementById("allclasses_navbar_top"); |
| if(window==top) { |
| allClassesLink.style.display = "block"; |
| } |
| else { |
| allClassesLink.style.display = "none"; |
| } |
| //--> |
| </script> |
| </div> |
| <div> |
| <ul class="subNavList"> |
| <li>Summary: </li> |
| <li><a href="#nested.class.summary">Nested</a> | </li> |
| <li>Field | </li> |
| <li><a href="#constructor.summary">Constr</a> | </li> |
| <li><a href="#method.summary">Method</a></li> |
| </ul> |
| <ul class="subNavList"> |
| <li>Detail: </li> |
| <li>Field | </li> |
| <li><a href="#constructor.detail">Constr</a> | </li> |
| <li><a href="#method.detail">Method</a></li> |
| </ul> |
| </div> |
| <a name="skip.navbar.top"> |
| <!-- --> |
| </a></div> |
| <!-- ========= END OF TOP NAVBAR ========= --> |
| <!-- ======== START OF CLASS DATA ======== --> |
| <div class="header"> |
| <div class="subTitle">org.apache.beam.sdk.extensions.sketching</div> |
| <h2 title="Class TDigestQuantiles" class="title">Class TDigestQuantiles</h2> |
| </div> |
| <div class="contentContainer"> |
| <ul class="inheritance"> |
| <li>java.lang.Object</li> |
| <li> |
| <ul class="inheritance"> |
| <li>org.apache.beam.sdk.extensions.sketching.TDigestQuantiles</li> |
| </ul> |
| </li> |
| </ul> |
| <div class="description"> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <hr> |
| <br> |
| <pre><a href="../../../../../../org/apache/beam/sdk/annotations/Experimental.html" title="annotation in org.apache.beam.sdk.annotations">@Experimental</a> |
| public final class <span class="typeNameLabel">TDigestQuantiles</span> |
| extends java.lang.Object</pre> |
| <div class="block"><code>PTransform</code>s for getting information about quantiles in a stream. |
| |
| <p>This class uses the T-Digest structure introduced by Ted Dunning, and more precisely the |
| <code>MergingDigest</code> implementation. |
| |
| <h2>References</h2> |
| |
| <p>The paper and implementation are available on Ted Dunning's <a |
| href="https://github.com/tdunning/t-digest">Github profile</a> |
| |
| <h2>Parameters</h2> |
| |
| <p>Only one parameter can be tuned in order to control the tradeoff between the estimation |
| accuracy and the memory use. <br> |
| |
| <p>Stream elements are compressed into a linked list of centroids. The compression factor <code>cf</code> is used to limit the number of elements represented by each centroid as well as the total |
| number of centroids. <br> |
| The relative error will always be a small fraction of 1% for values at extreme quantiles and |
| always be less than 3/cf at middle quantiles. <br> |
| |
| <p>By default the compression factor is set to 100, which guarantees a relative error less than |
| 3%. |
| |
| <h2>Examples</h2> |
| |
| <p>There are 2 ways of using this class: |
| |
| <ul> |
| <li>Use the <a href="../../../../../../org/apache/beam/sdk/transforms/PTransform.html" title="class in org.apache.beam.sdk.transforms"><code>PTransform</code></a>s that return a <a href="../../../../../../org/apache/beam/sdk/values/PCollection.html" title="class in org.apache.beam.sdk.values"><code>PCollection</code></a> which contains a <code>MergingDigest</code> for querying the value at a given quantile or the approximate quantile |
| position of an element. |
| <li>Use the <a href="../../../../../../org/apache/beam/sdk/extensions/sketching/TDigestQuantiles.TDigestQuantilesFn.html" title="class in org.apache.beam.sdk.extensions.sketching"><code>TDigestQuantiles.TDigestQuantilesFn</code></a> <code>CombineFn</code> that is exposed in order to make |
| advanced processing involving the <code>MergingDigest</code>. |
| </ul> |
| |
| <h3>Example 1: Default use</h3> |
| |
| <p>The simplest use is to call the <a href="../../../../../../org/apache/beam/sdk/extensions/sketching/TDigestQuantiles.html#globally--"><code>globally()</code></a> or <a href="../../../../../../org/apache/beam/sdk/extensions/sketching/TDigestQuantiles.html#perKey--"><code>perKey()</code></a> method in order to |
| retrieve the digest, and then to query the structure. |
| |
| <pre><code> |
| PCollection<Double> pc = ...; |
| PCollection<MergingDigest> countMinSketch = pc.apply(TDigestQuantiles |
| .globally()); // .perKey() |
| </code></pre> |
| |
| <h3>Example 2: tune accuracy parameters</h3> |
| |
| <p>One can tune the compression factor <code>cf</code> in order to control accuracy and memory. <br> |
| This tuning works exactly the same for <a href="../../../../../../org/apache/beam/sdk/extensions/sketching/TDigestQuantiles.html#globally--"><code>globally()</code></a> and <a href="../../../../../../org/apache/beam/sdk/extensions/sketching/TDigestQuantiles.html#perKey--"><code>perKey()</code></a>. |
| |
| <pre><code> |
| double cf = 500; |
| PCollection<Double> pc = ...; |
| PCollection<MergingDigest> countMinSketch = pc.apply(TDigestQuantiles |
| .globally() // .perKey() |
| .withCompression(cf); |
| </code></pre> |
| |
| <h3>Example 3 : Query the resulting structure</h3> |
| |
| <p>This example shows how to query the resulting structure, for example to build <code>PCollection</code> of <a href="../../../../../../org/apache/beam/sdk/values/KV.html" title="class in org.apache.beam.sdk.values"><code>KV</code></a>s with each pair corresponding to a couple (quantile, value). |
| |
| <pre><code> |
| PCollection<MergingDigest> pc = ...; |
| PCollection<KV<Double, Double>> quantiles = pc.apply(ParDo.of( |
| new DoFn<MergingDigest, KV<Double, Double>>() { |
| @ProcessElement |
| public void processElement(ProcessContext c) { |
| double[] quantiles = {0.01, 0.25, 0.5, 0.75, 0.99} |
| for (double q : quantiles) { |
| c.output(KV.of(q, c.element().quantile(q)); |
| } |
| }})); |
| </code></pre> |
| |
| <p>One can also retrieve the approximate quantile position of a given element in the stream using |
| <code>cdf(double)</code> method instead of <code>quantile(double)</code>. |
| |
| <h3>Example 4: Using the CombineFn</h3> |
| |
| <p>The <code>CombineFn</code> does the same thing as the <code>PTransform</code>s but it can be used for |
| doing stateful processing or in <a href="../../../../../../org/apache/beam/sdk/transforms/CombineFns.ComposedCombineFn.html" title="class in org.apache.beam.sdk.transforms"><code>CombineFns.ComposedCombineFn</code></a>. |
| |
| <p>This example is not really interesting but it shows how one can properly create a <a href="../../../../../../org/apache/beam/sdk/extensions/sketching/TDigestQuantiles.TDigestQuantilesFn.html" title="class in org.apache.beam.sdk.extensions.sketching"><code>TDigestQuantiles.TDigestQuantilesFn</code></a>. |
| |
| <pre><code> |
| double cf = 250; |
| PCollection<Double> input = ...; |
| PCollection<MergingDigest> output = input.apply(Combine |
| .globally(TDigestQuantilesFn.create(cf))); |
| </code></pre> |
| |
| <p><b>Warning: this class is experimental.</b> <br> |
| Its API is subject to change in future versions of Beam.</div> |
| </li> |
| </ul> |
| </div> |
| <div class="summary"> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <!-- ======== NESTED CLASS SUMMARY ======== --> |
| <ul class="blockList"> |
| <li class="blockList"><a name="nested.class.summary"> |
| <!-- --> |
| </a> |
| <h3>Nested Class Summary</h3> |
| <table class="memberSummary" border="0" cellpadding="3" cellspacing="0" summary="Nested Class Summary table, listing nested classes, and an explanation"> |
| <caption><span>Nested Classes</span><span class="tabEnd"> </span></caption> |
| <tr> |
| <th class="colFirst" scope="col">Modifier and Type</th> |
| <th class="colLast" scope="col">Class and Description</th> |
| </tr> |
| <tr class="altColor"> |
| <td class="colFirst"><code>static class </code></td> |
| <td class="colLast"><code><span class="memberNameLink"><a href="../../../../../../org/apache/beam/sdk/extensions/sketching/TDigestQuantiles.GlobalDigest.html" title="class in org.apache.beam.sdk.extensions.sketching">TDigestQuantiles.GlobalDigest</a></span></code> |
| <div class="block">Implementation of <a href="../../../../../../org/apache/beam/sdk/extensions/sketching/TDigestQuantiles.html#globally--"><code>globally()</code></a>.</div> |
| </td> |
| </tr> |
| <tr class="rowColor"> |
| <td class="colFirst"><code>static class </code></td> |
| <td class="colLast"><code><span class="memberNameLink"><a href="../../../../../../org/apache/beam/sdk/extensions/sketching/TDigestQuantiles.PerKeyDigest.html" title="class in org.apache.beam.sdk.extensions.sketching">TDigestQuantiles.PerKeyDigest</a><<a href="../../../../../../org/apache/beam/sdk/extensions/sketching/TDigestQuantiles.PerKeyDigest.html" title="type parameter in TDigestQuantiles.PerKeyDigest">K</a>></span></code> |
| <div class="block">Implementation of <a href="../../../../../../org/apache/beam/sdk/extensions/sketching/TDigestQuantiles.html#perKey--"><code>perKey()</code></a>.</div> |
| </td> |
| </tr> |
| <tr class="altColor"> |
| <td class="colFirst"><code>static class </code></td> |
| <td class="colLast"><code><span class="memberNameLink"><a href="../../../../../../org/apache/beam/sdk/extensions/sketching/TDigestQuantiles.TDigestQuantilesFn.html" title="class in org.apache.beam.sdk.extensions.sketching">TDigestQuantiles.TDigestQuantilesFn</a></span></code> |
| <div class="block">Implements the <code>Combine.CombineFn</code> of <a href="../../../../../../org/apache/beam/sdk/extensions/sketching/TDigestQuantiles.html" title="class in org.apache.beam.sdk.extensions.sketching"><code>TDigestQuantiles</code></a> transforms.</div> |
| </td> |
| </tr> |
| </table> |
| </li> |
| </ul> |
| <!-- ======== CONSTRUCTOR SUMMARY ======== --> |
| <ul class="blockList"> |
| <li class="blockList"><a name="constructor.summary"> |
| <!-- --> |
| </a> |
| <h3>Constructor Summary</h3> |
| <table class="memberSummary" border="0" cellpadding="3" cellspacing="0" summary="Constructor Summary table, listing constructors, and an explanation"> |
| <caption><span>Constructors</span><span class="tabEnd"> </span></caption> |
| <tr> |
| <th class="colOne" scope="col">Constructor and Description</th> |
| </tr> |
| <tr class="altColor"> |
| <td class="colOne"><code><span class="memberNameLink"><a href="../../../../../../org/apache/beam/sdk/extensions/sketching/TDigestQuantiles.html#TDigestQuantiles--">TDigestQuantiles</a></span>()</code> </td> |
| </tr> |
| </table> |
| </li> |
| </ul> |
| <!-- ========== METHOD SUMMARY =========== --> |
| <ul class="blockList"> |
| <li class="blockList"><a name="method.summary"> |
| <!-- --> |
| </a> |
| <h3>Method Summary</h3> |
| <table class="memberSummary" border="0" cellpadding="3" cellspacing="0" summary="Method Summary table, listing methods, and an explanation"> |
| <caption><span id="t0" class="activeTableTab"><span>All Methods</span><span class="tabEnd"> </span></span><span id="t1" class="tableTab"><span><a href="javascript:show(1);">Static Methods</a></span><span class="tabEnd"> </span></span><span id="t4" class="tableTab"><span><a href="javascript:show(8);">Concrete Methods</a></span><span class="tabEnd"> </span></span></caption> |
| <tr> |
| <th class="colFirst" scope="col">Modifier and Type</th> |
| <th class="colLast" scope="col">Method and Description</th> |
| </tr> |
| <tr id="i0" class="altColor"> |
| <td class="colFirst"><code>static <a href="../../../../../../org/apache/beam/sdk/extensions/sketching/TDigestQuantiles.GlobalDigest.html" title="class in org.apache.beam.sdk.extensions.sketching">TDigestQuantiles.GlobalDigest</a></code></td> |
| <td class="colLast"><code><span class="memberNameLink"><a href="../../../../../../org/apache/beam/sdk/extensions/sketching/TDigestQuantiles.html#globally--">globally</a></span>()</code> |
| <div class="block">Compute the stream in order to build a T-Digest structure (MergingDigest) for keeping track of |
| the stream distribution and returns a <code>PCollection<MergingDigest></code>.</div> |
| </td> |
| </tr> |
| <tr id="i1" class="rowColor"> |
| <td class="colFirst"><code>static <K> <a href="../../../../../../org/apache/beam/sdk/extensions/sketching/TDigestQuantiles.PerKeyDigest.html" title="class in org.apache.beam.sdk.extensions.sketching">TDigestQuantiles.PerKeyDigest</a><K></code></td> |
| <td class="colLast"><code><span class="memberNameLink"><a href="../../../../../../org/apache/beam/sdk/extensions/sketching/TDigestQuantiles.html#perKey--">perKey</a></span>()</code> |
| <div class="block">Like <a href="../../../../../../org/apache/beam/sdk/extensions/sketching/TDigestQuantiles.html#globally--"><code>globally()</code></a>, but builds a digest for each key in the stream.</div> |
| </td> |
| </tr> |
| </table> |
| <ul class="blockList"> |
| <li class="blockList"><a name="methods.inherited.from.class.java.lang.Object"> |
| <!-- --> |
| </a> |
| <h3>Methods inherited from class java.lang.Object</h3> |
| <code>clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait</code></li> |
| </ul> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| </div> |
| <div class="details"> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <!-- ========= CONSTRUCTOR DETAIL ======== --> |
| <ul class="blockList"> |
| <li class="blockList"><a name="constructor.detail"> |
| <!-- --> |
| </a> |
| <h3>Constructor Detail</h3> |
| <a name="TDigestQuantiles--"> |
| <!-- --> |
| </a> |
| <ul class="blockListLast"> |
| <li class="blockList"> |
| <h4>TDigestQuantiles</h4> |
| <pre>public TDigestQuantiles()</pre> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| <!-- ============ METHOD DETAIL ========== --> |
| <ul class="blockList"> |
| <li class="blockList"><a name="method.detail"> |
| <!-- --> |
| </a> |
| <h3>Method Detail</h3> |
| <a name="globally--"> |
| <!-- --> |
| </a> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <h4>globally</h4> |
| <pre>public static <a href="../../../../../../org/apache/beam/sdk/extensions/sketching/TDigestQuantiles.GlobalDigest.html" title="class in org.apache.beam.sdk.extensions.sketching">TDigestQuantiles.GlobalDigest</a> globally()</pre> |
| <div class="block">Compute the stream in order to build a T-Digest structure (MergingDigest) for keeping track of |
| the stream distribution and returns a <code>PCollection<MergingDigest></code>. <br> |
| The resulting structure can be queried in order to retrieve the approximate value at a given |
| quantile or the approximate quantile position of a given element.</div> |
| </li> |
| </ul> |
| <a name="perKey--"> |
| <!-- --> |
| </a> |
| <ul class="blockListLast"> |
| <li class="blockList"> |
| <h4>perKey</h4> |
| <pre>public static <K> <a href="../../../../../../org/apache/beam/sdk/extensions/sketching/TDigestQuantiles.PerKeyDigest.html" title="class in org.apache.beam.sdk.extensions.sketching">TDigestQuantiles.PerKeyDigest</a><K> perKey()</pre> |
| <div class="block">Like <a href="../../../../../../org/apache/beam/sdk/extensions/sketching/TDigestQuantiles.html#globally--"><code>globally()</code></a>, but builds a digest for each key in the stream.</div> |
| <dl> |
| <dt><span class="paramLabel">Type Parameters:</span></dt> |
| <dd><code>K</code> - the type of the keys</dd> |
| </dl> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| </div> |
| </div> |
| <!-- ========= END OF CLASS DATA ========= --> |
| <!-- ======= START OF BOTTOM NAVBAR ====== --> |
| <div class="bottomNav"><a name="navbar.bottom"> |
| <!-- --> |
| </a> |
| <div class="skipNav"><a href="#skip.navbar.bottom" title="Skip navigation links">Skip navigation links</a></div> |
| <a name="navbar.bottom.firstrow"> |
| <!-- --> |
| </a> |
| <ul class="navList" title="Navigation"> |
| <li><a href="../../../../../../overview-summary.html">Overview</a></li> |
| <li><a href="package-summary.html">Package</a></li> |
| <li class="navBarCell1Rev">Class</li> |
| <li><a href="package-tree.html">Tree</a></li> |
| <li><a href="../../../../../../deprecated-list.html">Deprecated</a></li> |
| <li><a href="../../../../../../index-all.html">Index</a></li> |
| <li><a href="../../../../../../help-doc.html">Help</a></li> |
| </ul> |
| </div> |
| <div class="subNav"> |
| <ul class="navList"> |
| <li><a href="../../../../../../org/apache/beam/sdk/extensions/sketching/SketchFrequencies.Sketch.html" title="class in org.apache.beam.sdk.extensions.sketching"><span class="typeNameLink">Prev Class</span></a></li> |
| <li><a href="../../../../../../org/apache/beam/sdk/extensions/sketching/TDigestQuantiles.GlobalDigest.html" title="class in org.apache.beam.sdk.extensions.sketching"><span class="typeNameLink">Next Class</span></a></li> |
| </ul> |
| <ul class="navList"> |
| <li><a href="../../../../../../index.html?org/apache/beam/sdk/extensions/sketching/TDigestQuantiles.html" target="_top">Frames</a></li> |
| <li><a href="TDigestQuantiles.html" target="_top">No Frames</a></li> |
| </ul> |
| <ul class="navList" id="allclasses_navbar_bottom"> |
| <li><a href="../../../../../../allclasses-noframe.html">All Classes</a></li> |
| </ul> |
| <div> |
| <script type="text/javascript"><!-- |
| allClassesLink = document.getElementById("allclasses_navbar_bottom"); |
| if(window==top) { |
| allClassesLink.style.display = "block"; |
| } |
| else { |
| allClassesLink.style.display = "none"; |
| } |
| //--> |
| </script> |
| </div> |
| <div> |
| <ul class="subNavList"> |
| <li>Summary: </li> |
| <li><a href="#nested.class.summary">Nested</a> | </li> |
| <li>Field | </li> |
| <li><a href="#constructor.summary">Constr</a> | </li> |
| <li><a href="#method.summary">Method</a></li> |
| </ul> |
| <ul class="subNavList"> |
| <li>Detail: </li> |
| <li>Field | </li> |
| <li><a href="#constructor.detail">Constr</a> | </li> |
| <li><a href="#method.detail">Method</a></li> |
| </ul> |
| </div> |
| <a name="skip.navbar.bottom"> |
| <!-- --> |
| </a></div> |
| <!-- ======== END OF BOTTOM NAVBAR ======= --> |
| </body> |
| </html> |