blob: 5d5cbffeab5525adc0e0b39024fae717026cbc3e [file] [log] [blame]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Apache Druid">
<meta name="keywords" content="druid,kafka,database,analytics,streaming,real-time,real time,apache,open source">
<meta name="author" content="Apache Software Foundation">
<title>Druid | </title>
<link rel="alternate" type="application/atom+xml" href="/feed">
<link rel="shortcut icon" href="/img/favicon.png">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr" crossorigin="anonymous">
<link href='//fonts.googleapis.com/css?family=Open+Sans+Condensed:300,700,300italic|Open+Sans:300italic,400italic,600italic,400,300,600,700' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="/css/bootstrap-pure.css?v=1.1">
<link rel="stylesheet" href="/css/base.css?v=1.1">
<link rel="stylesheet" href="/css/header.css?v=1.1">
<link rel="stylesheet" href="/css/footer.css?v=1.1">
<link rel="stylesheet" href="/css/syntax.css?v=1.1">
<link rel="stylesheet" href="/css/docs.css?v=1.1">
<script>
(function() {
var cx = '000162378814775985090:molvbm0vggm';
var gcse = document.createElement('script');
gcse.type = 'text/javascript';
gcse.async = true;
gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
'//cse.google.com/cse.js?cx=' + cx;
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(gcse, s);
})();
</script>
</head>
<body>
<!-- Start page_header include -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<div class="top-navigator">
<div class="container">
<div class="left-cont">
<a class="logo" href="/"><span class="druid-logo"></span></a>
</div>
<div class="right-cont">
<ul class="links">
<li class=""><a href="/technology">Technology</a></li>
<li class=""><a href="/use-cases">Use Cases</a></li>
<li class=""><a href="/druid-powered">Powered By</a></li>
<li class=""><a href="/docs/latest/design/">Docs</a></li>
<li class=""><a href="/community/">Community</a></li>
<li class="header-dropdown">
<a>Apache</a>
<div class="header-dropdown-menu">
<a href="https://www.apache.org/" target="_blank">Foundation</a>
<a href="https://www.apache.org/events/current-event" target="_blank">Events</a>
<a href="https://www.apache.org/licenses/" target="_blank">License</a>
<a href="https://www.apache.org/foundation/thanks.html" target="_blank">Thanks</a>
<a href="https://www.apache.org/security/" target="_blank">Security</a>
<a href="https://www.apache.org/foundation/sponsorship.html" target="_blank">Sponsorship</a>
</div>
</li>
<li class=" button-link"><a href="/downloads.html">Download</a></li>
</ul>
</div>
</div>
<div class="action-button menu-icon">
<span class="fa fa-bars"></span> MENU
</div>
<div class="action-button menu-icon-close">
<span class="fa fa-times"></span> MENU
</div>
</div>
<script type="text/javascript">
var $menu = $('.right-cont');
var $menuIcon = $('.menu-icon');
var $menuIconClose = $('.menu-icon-close');
function showMenu() {
$menu.fadeIn(100);
$menuIcon.fadeOut(100);
$menuIconClose.fadeIn(100);
}
$menuIcon.click(showMenu);
function hideMenu() {
$menu.fadeOut(100);
$menuIconClose.fadeOut(100);
$menuIcon.fadeIn(100);
}
$menuIconClose.click(hideMenu);
$(window).resize(function() {
if ($(window).width() >= 840) {
$menu.fadeIn(100);
$menuIcon.fadeOut(100);
$menuIconClose.fadeOut(100);
}
else {
$menu.fadeOut(100);
$menuIcon.fadeIn(100);
$menuIconClose.fadeOut(100);
}
});
</script>
<!-- Stop page_header include -->
<div class="container doc-container">
<p> Looking for the <a href="/docs/0.23.0/">latest stable documentation</a>?</p>
<div class="row">
<div class="col-md-9 doc-content">
<p>
<a class="btn btn-default btn-xs visible-xs-inline-block visible-sm-inline-block" href="#toc">Table of Contents</a>
</p>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one
~ or more contributor license agreements. See the NOTICE file
~ distributed with this work for additional information
~ regarding copyright ownership. The ASF licenses this file
~ to you under the Apache License, Version 2.0 (the
~ "License"); you may not use this file except in compliance
~ with the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->
<h1 id="moving-average-queries">Moving Average Queries</h1>
<h2 id="overview">Overview</h2>
<p><strong>Moving Average Query</strong> is an extension which provides support for <a href="https://en.wikipedia.org/wiki/Moving_average">Moving Average</a> and other Aggregate <a href="https://en.wikibooks.org/wiki/Structured_Query_Language/Window_functions">Window Functions</a> in Druid queries.</p>
<p>These Aggregate Window Functions consume standard Druid Aggregators and outputs additional windowed aggregates called <a href="#averagers">Averagers</a>.</p>
<h4 id="high-level-algorithm">High level algorithm</h4>
<p>Moving Average encapsulates the <a href="../../querying/groupbyquery.html">groupBy query</a> (Or <a href="../../querying/timeseriesquery.html">timeseries</a> in case of no dimensions) in order to rely on the maturity of these query types.</p>
<p>It runs the query in two main phases:</p>
<ol>
<li>Runs an inner <a href="../../querying/groupbyquery.html">groupBy</a> or <a href="../../querying/timeseriesquery.html">timeseries</a> query to compute Aggregators (i.e. daily count of events).</li>
<li>Passes over aggregated results in Broker, in order to compute Averagers (i.e. moving 7 day average of the daily count).</li>
</ol>
<h4 id="main-enhancements-provided-by-this-extension">Main enhancements provided by this extension:</h4>
<ol>
<li>Functionality: Extending druid query functionality (i.e. initial introduction of Window Functions).</li>
<li>Performance: Improving performance of such moving aggregations by eliminating multiple segment scans.</li>
</ol>
<h4 id="further-reading">Further reading</h4>
<p><a href="https://en.wikipedia.org/wiki/Moving_average">Moving Average</a></p>
<p><a href="https://en.wikibooks.org/wiki/Structured_Query_Language/Window_functions">Window Functions</a></p>
<p><a href="https://cloud.google.com/bigquery/docs/reference/standard-sql/analytic-function-concepts">Analytic Functions</a></p>
<h2 id="operations">Operations</h2>
<p>To use this extension, make sure to <a href="../../operations/including-extensions.html">load</a> <code>druid-moving-average-query</code> only to the Broker.</p>
<h2 id="configuration">Configuration</h2>
<p>There are currently no configuration properties specific to Moving Average.</p>
<h2 id="limitations">Limitations</h2>
<ul>
<li>movingAverage is missing support for the following groupBy properties: <code>subtotalsSpec</code>, <code>virtualColumns</code>.</li>
<li>movingAverage is missing support for the following timeseries properties: <code>descending</code>.</li>
<li>movingAverage is missing support for <a href="https://github.com/apache/incubator-druid/issues/4349">SQL-compatible null handling</a> (So setting druid.generic.useDefaultValueForNull in configuration will give an error). </li>
</ul>
<h2 id="query-spec">Query spec:</h2>
<ul>
<li>Most properties in the query spec derived from <a href="../../querying/groupbyquery.html">groupBy query</a> / <a href="../../querying/timeseriesquery.html">timeseries</a>, see documentation for these query types.</li>
</ul>
<table><thead>
<tr>
<th>property</th>
<th>description</th>
<th>required?</th>
</tr>
</thead><tbody>
<tr>
<td>queryType</td>
<td>This String should always be &quot;movingAverage&quot;; this is the first thing Druid looks at to figure out how to interpret the query.</td>
<td>yes</td>
</tr>
<tr>
<td>dataSource</td>
<td>A String or Object defining the data source to query, very similar to a table in a relational database. See <a href="../../querying/datasource.html">DataSource</a> for more information.</td>
<td>yes</td>
</tr>
<tr>
<td>dimensions</td>
<td>A JSON list of <a href="../../querying/dimensionspecs.html">DimensionSpec</a> (Notice that property is optional)</td>
<td>no</td>
</tr>
<tr>
<td>limitSpec</td>
<td>See <a href="../../querying/limitspec.html">LimitSpec</a></td>
<td>no</td>
</tr>
<tr>
<td>having</td>
<td>See <a href="../../querying/having.html">Having</a></td>
<td>no</td>
</tr>
<tr>
<td>granularity</td>
<td>A period granilarity; See <a href="../../querying/granularities.html#period-granularities">Period Granularities</a></td>
<td>yes</td>
</tr>
<tr>
<td>filter</td>
<td>See <a href="../../querying/filters.html">Filters</a></td>
<td>no</td>
</tr>
<tr>
<td>aggregations</td>
<td>Aggregations forms the input to Averagers; See <a href="../../querying/aggregations.html">Aggregations</a></td>
<td>yes</td>
</tr>
<tr>
<td>postAggregations</td>
<td>Supports only aggregations as input; See <a href="../../querying/post-aggregations.html">Post Aggregations</a></td>
<td>no</td>
</tr>
<tr>
<td>intervals</td>
<td>A JSON Object representing ISO-8601 Intervals. This defines the time ranges to run the query over.</td>
<td>yes</td>
</tr>
<tr>
<td>context</td>
<td>An additional JSON Object which can be used to specify certain flags.</td>
<td>no</td>
</tr>
<tr>
<td>averagers</td>
<td>Defines the moving average function; See <a href="#averagers">Averagers</a></td>
<td>yes</td>
</tr>
<tr>
<td>postAveragers</td>
<td>Support input of both averagers and aggregations; Syntax is identical to postAggregations (See <a href="../../querying/post-aggregations.html">Post Aggregations</a>)</td>
<td>no</td>
</tr>
</tbody></table>
<h2 id="averagers">Averagers</h2>
<p>Averagers are used to define the Moving-Average function. Averagers are not limited to an average - they can also provide other types of window functions such as MAX()/MIN().</p>
<h3 id="properties">Properties</h3>
<p>These are properties which are common to all Averagers:</p>
<table><thead>
<tr>
<th>property</th>
<th>description</th>
<th>required?</th>
</tr>
</thead><tbody>
<tr>
<td>type</td>
<td>Averager type; See <a href="#averager-types">Averager types</a></td>
<td>yes</td>
</tr>
<tr>
<td>name</td>
<td>Averager name</td>
<td>yes</td>
</tr>
<tr>
<td>fieldName</td>
<td>Input name (An aggregation name)</td>
<td>yes</td>
</tr>
<tr>
<td>buckets</td>
<td>Number of lookback buckets (time periods), including current one. Must be &gt;0</td>
<td>yes</td>
</tr>
<tr>
<td>cycleSize</td>
<td>Cycle size; Used to calculate day-of-week option; See <a href="#cycle-size-day-of-week">Cycle size (Day of Week)</a></td>
<td>no, defaults to 1</td>
</tr>
</tbody></table>
<h3 id="averager-types">Averager types:</h3>
<ul>
<li><a href="#standard-averagers">Standard averagers</a>:
<ul>
<li>doubleMean</li>
<li>doubleMeanNoNulls</li>
<li>doubleMax</li>
<li>doubleMin</li>
<li>longMean</li>
<li>longMeanNoNulls</li>
<li>longMax</li>
<li>longMin</li>
</ul></li>
</ul>
<h4 id="standard-averagers">Standard averagers</h4>
<p>These averagers offer four functions:</p>
<ul>
<li>Mean (Average)</li>
<li>MeanNoNulls (Ignores empty buckets).</li>
<li>Max</li>
<li>Min</li>
</ul>
<p><strong>Ignoring nulls</strong>:
Using a MeanNoNulls averager is useful when the interval starts at the dataset beginning time.
In that case, the first records will ignore missing buckets and average won&#39;t be artificially low.
However, this also means that empty days in a sparse dataset will also be ignored.</p>
<p>Example of usage:</p>
<div class="highlight"><pre><code class="language-json" data-lang="json"><span></span><span class="p">{</span> <span class="nt">&quot;type&quot;</span> <span class="p">:</span> <span class="s2">&quot;doubleMean&quot;</span><span class="p">,</span> <span class="nt">&quot;name&quot;</span> <span class="p">:</span> <span class="err">&lt;ou</span><span class="kc">t</span><span class="err">pu</span><span class="kc">t</span><span class="err">_</span><span class="kc">na</span><span class="err">me&gt;</span><span class="p">,</span> <span class="nt">&quot;fieldName&quot;</span><span class="p">:</span> <span class="err">&lt;i</span><span class="kc">n</span><span class="err">pu</span><span class="kc">t</span><span class="err">_</span><span class="kc">na</span><span class="err">me&gt;</span> <span class="p">}</span>
</code></pre></div>
<h3 id="cycle-size-day-of-week">Cycle size (Day of Week)</h3>
<p>This optional parameter is used to calculate over a single bucket within each cycle instead of all buckets.
A prime example would be weekly buckets, resulting in a Day of Week calculation. (Other examples: Month of year, Hour of day).</p>
<p>I.e. when using these parameters:</p>
<ul>
<li><em>granularity</em>: period=P1D (daily)</li>
<li><em>buckets</em>: 28</li>
<li><em>cycleSize</em>: 7</li>
</ul>
<p>Within each output record, the averager will compute the result over the following buckets: current (#0), #7, #14, #21.
Whereas without specifying cycleSize it would have computed over all 28 buckets.</p>
<h2 id="examples">Examples</h2>
<p>All examples are based on the Wikipedia dataset provided in the Druid <a href="../../tutorials/index.html">tutorials</a>.</p>
<h3 id="basic-example">Basic example</h3>
<p>Calculating a 7-buckets moving average for Wikipedia edit deltas.</p>
<p>Query syntax:</p>
<div class="highlight"><pre><code class="language-json" data-lang="json"><span></span><span class="p">{</span>
<span class="nt">&quot;queryType&quot;</span><span class="p">:</span> <span class="s2">&quot;movingAverage&quot;</span><span class="p">,</span>
<span class="nt">&quot;dataSource&quot;</span><span class="p">:</span> <span class="s2">&quot;wikipedia&quot;</span><span class="p">,</span>
<span class="nt">&quot;granularity&quot;</span><span class="p">:</span> <span class="p">{</span>
<span class="nt">&quot;type&quot;</span><span class="p">:</span> <span class="s2">&quot;period&quot;</span><span class="p">,</span>
<span class="nt">&quot;period&quot;</span><span class="p">:</span> <span class="s2">&quot;PT30M&quot;</span>
<span class="p">},</span>
<span class="nt">&quot;intervals&quot;</span><span class="p">:</span> <span class="p">[</span>
<span class="s2">&quot;2015-09-12T00:00:00Z/2015-09-13T00:00:00Z&quot;</span>
<span class="p">],</span>
<span class="nt">&quot;aggregations&quot;</span><span class="p">:</span> <span class="p">[</span>
<span class="p">{</span>
<span class="nt">&quot;name&quot;</span><span class="p">:</span> <span class="s2">&quot;delta30Min&quot;</span><span class="p">,</span>
<span class="nt">&quot;fieldName&quot;</span><span class="p">:</span> <span class="s2">&quot;delta&quot;</span><span class="p">,</span>
<span class="nt">&quot;type&quot;</span><span class="p">:</span> <span class="s2">&quot;longSum&quot;</span>
<span class="p">}</span>
<span class="p">],</span>
<span class="nt">&quot;averagers&quot;</span><span class="p">:</span> <span class="p">[</span>
<span class="p">{</span>
<span class="nt">&quot;name&quot;</span><span class="p">:</span> <span class="s2">&quot;trailing30MinChanges&quot;</span><span class="p">,</span>
<span class="nt">&quot;fieldName&quot;</span><span class="p">:</span> <span class="s2">&quot;delta30Min&quot;</span><span class="p">,</span>
<span class="nt">&quot;type&quot;</span><span class="p">:</span> <span class="s2">&quot;longMean&quot;</span><span class="p">,</span>
<span class="nt">&quot;buckets&quot;</span><span class="p">:</span> <span class="mi">7</span>
<span class="p">}</span>
<span class="p">]</span>
<span class="p">}</span>
</code></pre></div>
<p>Result:</p>
<div class="highlight"><pre><code class="language-json" data-lang="json"><span></span><span class="p">[</span> <span class="p">{</span>
<span class="nt">&quot;version&quot;</span> <span class="p">:</span> <span class="s2">&quot;v1&quot;</span><span class="p">,</span>
<span class="nt">&quot;timestamp&quot;</span> <span class="p">:</span> <span class="s2">&quot;2015-09-12T00:30:00.000Z&quot;</span><span class="p">,</span>
<span class="nt">&quot;event&quot;</span> <span class="p">:</span> <span class="p">{</span>
<span class="nt">&quot;delta30Min&quot;</span> <span class="p">:</span> <span class="mi">30490</span><span class="p">,</span>
<span class="nt">&quot;trailing30MinChanges&quot;</span> <span class="p">:</span> <span class="mf">4355.714285714285</span>
<span class="p">}</span>
<span class="p">},</span> <span class="p">{</span>
<span class="nt">&quot;version&quot;</span> <span class="p">:</span> <span class="s2">&quot;v1&quot;</span><span class="p">,</span>
<span class="nt">&quot;timestamp&quot;</span> <span class="p">:</span> <span class="s2">&quot;2015-09-12T01:00:00.000Z&quot;</span><span class="p">,</span>
<span class="nt">&quot;event&quot;</span> <span class="p">:</span> <span class="p">{</span>
<span class="nt">&quot;delta30Min&quot;</span> <span class="p">:</span> <span class="mi">96526</span><span class="p">,</span>
<span class="nt">&quot;trailing30MinChanges&quot;</span> <span class="p">:</span> <span class="mf">18145.14285714286</span>
<span class="p">}</span>
<span class="p">},</span> <span class="p">{</span>
<span class="err">...</span>
<span class="err">...</span>
<span class="err">...</span>
<span class="p">},</span> <span class="p">{</span>
<span class="nt">&quot;version&quot;</span> <span class="p">:</span> <span class="s2">&quot;v1&quot;</span><span class="p">,</span>
<span class="nt">&quot;timestamp&quot;</span> <span class="p">:</span> <span class="s2">&quot;2015-09-12T23:00:00.000Z&quot;</span><span class="p">,</span>
<span class="nt">&quot;event&quot;</span> <span class="p">:</span> <span class="p">{</span>
<span class="nt">&quot;delta30Min&quot;</span> <span class="p">:</span> <span class="mi">119100</span><span class="p">,</span>
<span class="nt">&quot;trailing30MinChanges&quot;</span> <span class="p">:</span> <span class="mf">198697.2857142857</span>
<span class="p">}</span>
<span class="p">},</span> <span class="p">{</span>
<span class="nt">&quot;version&quot;</span> <span class="p">:</span> <span class="s2">&quot;v1&quot;</span><span class="p">,</span>
<span class="nt">&quot;timestamp&quot;</span> <span class="p">:</span> <span class="s2">&quot;2015-09-12T23:30:00.000Z&quot;</span><span class="p">,</span>
<span class="nt">&quot;event&quot;</span> <span class="p">:</span> <span class="p">{</span>
<span class="nt">&quot;delta30Min&quot;</span> <span class="p">:</span> <span class="mi">177882</span><span class="p">,</span>
<span class="nt">&quot;trailing30MinChanges&quot;</span> <span class="p">:</span> <span class="mf">193890.0</span>
<span class="p">}</span>
<span class="p">}</span>
</code></pre></div>
<h3 id="post-averager-example">Post averager example</h3>
<p>Calculating a 7-buckets moving average for Wikipedia edit deltas, plus a ratio between the current period and the moving average.</p>
<p>Query syntax:</p>
<div class="highlight"><pre><code class="language-json" data-lang="json"><span></span><span class="p">{</span>
<span class="nt">&quot;queryType&quot;</span><span class="p">:</span> <span class="s2">&quot;movingAverage&quot;</span><span class="p">,</span>
<span class="nt">&quot;dataSource&quot;</span><span class="p">:</span> <span class="s2">&quot;wikipedia&quot;</span><span class="p">,</span>
<span class="nt">&quot;granularity&quot;</span><span class="p">:</span> <span class="p">{</span>
<span class="nt">&quot;type&quot;</span><span class="p">:</span> <span class="s2">&quot;period&quot;</span><span class="p">,</span>
<span class="nt">&quot;period&quot;</span><span class="p">:</span> <span class="s2">&quot;PT30M&quot;</span>
<span class="p">},</span>
<span class="nt">&quot;intervals&quot;</span><span class="p">:</span> <span class="p">[</span>
<span class="s2">&quot;2015-09-12T22:00:00Z/2015-09-13T00:00:00Z&quot;</span>
<span class="p">],</span>
<span class="nt">&quot;aggregations&quot;</span><span class="p">:</span> <span class="p">[</span>
<span class="p">{</span>
<span class="nt">&quot;name&quot;</span><span class="p">:</span> <span class="s2">&quot;delta30Min&quot;</span><span class="p">,</span>
<span class="nt">&quot;fieldName&quot;</span><span class="p">:</span> <span class="s2">&quot;delta&quot;</span><span class="p">,</span>
<span class="nt">&quot;type&quot;</span><span class="p">:</span> <span class="s2">&quot;longSum&quot;</span>
<span class="p">}</span>
<span class="p">],</span>
<span class="nt">&quot;averagers&quot;</span><span class="p">:</span> <span class="p">[</span>
<span class="p">{</span>
<span class="nt">&quot;name&quot;</span><span class="p">:</span> <span class="s2">&quot;trailing30MinChanges&quot;</span><span class="p">,</span>
<span class="nt">&quot;fieldName&quot;</span><span class="p">:</span> <span class="s2">&quot;delta30Min&quot;</span><span class="p">,</span>
<span class="nt">&quot;type&quot;</span><span class="p">:</span> <span class="s2">&quot;longMean&quot;</span><span class="p">,</span>
<span class="nt">&quot;buckets&quot;</span><span class="p">:</span> <span class="mi">7</span>
<span class="p">}</span>
<span class="p">],</span>
<span class="nt">&quot;postAveragers&quot;</span> <span class="p">:</span> <span class="p">[</span>
<span class="p">{</span>
<span class="nt">&quot;name&quot;</span><span class="p">:</span> <span class="s2">&quot;ratioTrailing30MinChanges&quot;</span><span class="p">,</span>
<span class="nt">&quot;type&quot;</span><span class="p">:</span> <span class="s2">&quot;arithmetic&quot;</span><span class="p">,</span>
<span class="nt">&quot;fn&quot;</span><span class="p">:</span> <span class="s2">&quot;/&quot;</span><span class="p">,</span>
<span class="nt">&quot;fields&quot;</span><span class="p">:</span> <span class="p">[</span>
<span class="p">{</span>
<span class="nt">&quot;type&quot;</span><span class="p">:</span> <span class="s2">&quot;fieldAccess&quot;</span><span class="p">,</span>
<span class="nt">&quot;fieldName&quot;</span><span class="p">:</span> <span class="s2">&quot;delta30Min&quot;</span>
<span class="p">},</span>
<span class="p">{</span>
<span class="nt">&quot;type&quot;</span><span class="p">:</span> <span class="s2">&quot;fieldAccess&quot;</span><span class="p">,</span>
<span class="nt">&quot;fieldName&quot;</span><span class="p">:</span> <span class="s2">&quot;trailing30MinChanges&quot;</span>
<span class="p">}</span>
<span class="p">]</span>
<span class="p">}</span>
<span class="p">]</span>
<span class="p">}</span>
</code></pre></div>
<p>Result:</p>
<div class="highlight"><pre><code class="language-json" data-lang="json"><span></span><span class="p">[</span> <span class="p">{</span>
<span class="nt">&quot;version&quot;</span> <span class="p">:</span> <span class="s2">&quot;v1&quot;</span><span class="p">,</span>
<span class="nt">&quot;timestamp&quot;</span> <span class="p">:</span> <span class="s2">&quot;2015-09-12T22:00:00.000Z&quot;</span><span class="p">,</span>
<span class="nt">&quot;event&quot;</span> <span class="p">:</span> <span class="p">{</span>
<span class="nt">&quot;delta30Min&quot;</span> <span class="p">:</span> <span class="mi">144269</span><span class="p">,</span>
<span class="nt">&quot;trailing30MinChanges&quot;</span> <span class="p">:</span> <span class="mf">204088.14285714287</span><span class="p">,</span>
<span class="nt">&quot;ratioTrailing30MinChanges&quot;</span> <span class="p">:</span> <span class="mf">0.7068955500319539</span>
<span class="p">}</span>
<span class="p">},</span> <span class="p">{</span>
<span class="nt">&quot;version&quot;</span> <span class="p">:</span> <span class="s2">&quot;v1&quot;</span><span class="p">,</span>
<span class="nt">&quot;timestamp&quot;</span> <span class="p">:</span> <span class="s2">&quot;2015-09-12T22:30:00.000Z&quot;</span><span class="p">,</span>
<span class="nt">&quot;event&quot;</span> <span class="p">:</span> <span class="p">{</span>
<span class="nt">&quot;delta30Min&quot;</span> <span class="p">:</span> <span class="mi">242860</span><span class="p">,</span>
<span class="nt">&quot;trailing30MinChanges&quot;</span> <span class="p">:</span> <span class="mf">214031.57142857142</span><span class="p">,</span>
<span class="nt">&quot;ratioTrailing30MinChanges&quot;</span> <span class="p">:</span> <span class="mf">1.134692411867141</span>
<span class="p">}</span>
<span class="p">},</span> <span class="p">{</span>
<span class="nt">&quot;version&quot;</span> <span class="p">:</span> <span class="s2">&quot;v1&quot;</span><span class="p">,</span>
<span class="nt">&quot;timestamp&quot;</span> <span class="p">:</span> <span class="s2">&quot;2015-09-12T23:00:00.000Z&quot;</span><span class="p">,</span>
<span class="nt">&quot;event&quot;</span> <span class="p">:</span> <span class="p">{</span>
<span class="nt">&quot;delta30Min&quot;</span> <span class="p">:</span> <span class="mi">119100</span><span class="p">,</span>
<span class="nt">&quot;trailing30MinChanges&quot;</span> <span class="p">:</span> <span class="mf">198697.2857142857</span><span class="p">,</span>
<span class="nt">&quot;ratioTrailing30MinChanges&quot;</span> <span class="p">:</span> <span class="mf">0.5994042624782422</span>
<span class="p">}</span>
<span class="p">},</span> <span class="p">{</span>
<span class="nt">&quot;version&quot;</span> <span class="p">:</span> <span class="s2">&quot;v1&quot;</span><span class="p">,</span>
<span class="nt">&quot;timestamp&quot;</span> <span class="p">:</span> <span class="s2">&quot;2015-09-12T23:30:00.000Z&quot;</span><span class="p">,</span>
<span class="nt">&quot;event&quot;</span> <span class="p">:</span> <span class="p">{</span>
<span class="nt">&quot;delta30Min&quot;</span> <span class="p">:</span> <span class="mi">177882</span><span class="p">,</span>
<span class="nt">&quot;trailing30MinChanges&quot;</span> <span class="p">:</span> <span class="mf">193890.0</span><span class="p">,</span>
<span class="nt">&quot;ratioTrailing30MinChanges&quot;</span> <span class="p">:</span> <span class="mf">0.9174377224199288</span>
<span class="p">}</span>
<span class="p">}</span> <span class="p">]</span>
</code></pre></div>
<h3 id="cycle-size-example">Cycle size example</h3>
<p>Calculating an average of every first 10-minutes of the last 3 hours:</p>
<p>Query syntax:</p>
<div class="highlight"><pre><code class="language-json" data-lang="json"><span></span><span class="p">{</span>
<span class="nt">&quot;queryType&quot;</span><span class="p">:</span> <span class="s2">&quot;movingAverage&quot;</span><span class="p">,</span>
<span class="nt">&quot;dataSource&quot;</span><span class="p">:</span> <span class="s2">&quot;wikipedia&quot;</span><span class="p">,</span>
<span class="nt">&quot;granularity&quot;</span><span class="p">:</span> <span class="p">{</span>
<span class="nt">&quot;type&quot;</span><span class="p">:</span> <span class="s2">&quot;period&quot;</span><span class="p">,</span>
<span class="nt">&quot;period&quot;</span><span class="p">:</span> <span class="s2">&quot;PT10M&quot;</span>
<span class="p">},</span>
<span class="nt">&quot;intervals&quot;</span><span class="p">:</span> <span class="p">[</span>
<span class="s2">&quot;2015-09-12T00:00:00Z/2015-09-13T00:00:00Z&quot;</span>
<span class="p">],</span>
<span class="nt">&quot;aggregations&quot;</span><span class="p">:</span> <span class="p">[</span>
<span class="p">{</span>
<span class="nt">&quot;name&quot;</span><span class="p">:</span> <span class="s2">&quot;delta10Min&quot;</span><span class="p">,</span>
<span class="nt">&quot;fieldName&quot;</span><span class="p">:</span> <span class="s2">&quot;delta&quot;</span><span class="p">,</span>
<span class="nt">&quot;type&quot;</span><span class="p">:</span> <span class="s2">&quot;doubleSum&quot;</span>
<span class="p">}</span>
<span class="p">],</span>
<span class="nt">&quot;averagers&quot;</span><span class="p">:</span> <span class="p">[</span>
<span class="p">{</span>
<span class="nt">&quot;name&quot;</span><span class="p">:</span> <span class="s2">&quot;trailing10MinPerHourChanges&quot;</span><span class="p">,</span>
<span class="nt">&quot;fieldName&quot;</span><span class="p">:</span> <span class="s2">&quot;delta10Min&quot;</span><span class="p">,</span>
<span class="nt">&quot;type&quot;</span><span class="p">:</span> <span class="s2">&quot;doubleMeanNoNulls&quot;</span><span class="p">,</span>
<span class="nt">&quot;buckets&quot;</span><span class="p">:</span> <span class="mi">18</span><span class="p">,</span>
<span class="nt">&quot;cycleSize&quot;</span><span class="p">:</span> <span class="mi">6</span>
<span class="p">}</span>
<span class="p">]</span>
<span class="p">}</span>
</code></pre></div>
</div>
<div class="col-md-3">
<div class="searchbox">
<gcse:searchbox-only></gcse:searchbox-only>
</div>
<div id="toc" class="nav toc hidden-print">
</div>
</div>
</div>
</div>
<!-- Start page_footer include -->
<footer class="druid-footer">
<div class="container">
<div class="text-center">
<p>
<a href="/technology">Technology</a>&ensp;·&ensp;
<a href="/use-cases">Use Cases</a>&ensp;·&ensp;
<a href="/druid-powered">Powered by Druid</a>&ensp;·&ensp;
<a href="/docs/latest/">Docs</a>&ensp;·&ensp;
<a href="/community/">Community</a>&ensp;·&ensp;
<a href="/downloads.html">Download</a>&ensp;·&ensp;
<a href="/faq">FAQ</a>
</p>
</div>
<div class="text-center">
<a title="Join the user group" href="https://groups.google.com/forum/#!forum/druid-user" target="_blank"><span class="fa fa-comments"></span></a>&ensp;·&ensp;
<a title="Follow Druid" href="https://twitter.com/druidio" target="_blank"><span class="fab fa-twitter"></span></a>&ensp;·&ensp;
<a title="GitHub" href="https://github.com/apache/druid" target="_blank"><span class="fab fa-github"></span></a>
</div>
<div class="text-center license">
Copyright © 2020 <a href="https://www.apache.org/" target="_blank">Apache Software Foundation</a>.<br>
Except where otherwise noted, licensed under <a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/">CC BY-SA 4.0</a>.<br>
Apache Druid, Druid, and the Druid logo are either registered trademarks or trademarks of The Apache Software Foundation in the United States and other countries.
</div>
</div>
</footer>
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-131010415-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-131010415-1');
</script>
<script>
function trackDownload(type, url) {
ga('send', 'event', 'download', type, url);
}
</script>
<script src="//code.jquery.com/jquery.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<script src="/assets/js/druid.js"></script>
<!-- stop page_footer include -->
<script>
$(function() {
$(".toc").load("/docs/0.15.1-incubating/toc.html");
// There is no way to tell when .gsc-input will be async loaded into the page so just try to set a placeholder until it works
var tries = 0;
var timer = setInterval(function() {
tries++;
if (tries > 300) clearInterval(timer);
var searchInput = $('input.gsc-input');
if (searchInput.length) {
searchInput.attr('placeholder', 'Search');
clearInterval(timer);
}
}, 100);
});
</script>
</body>
</html>