blob: dff08df761f15fa74090c1d029b97ce4388c7a04 [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 | Compaction Task</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.20.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="compaction-task">Compaction Task</h1>
<p>Compaction tasks merge all segments of the given interval. The syntax is:</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;compact&quot;</span><span class="p">,</span>
<span class="nt">&quot;id&quot;</span><span class="p">:</span> <span class="err">&lt;task_id&gt;</span><span class="p">,</span>
<span class="nt">&quot;dataSource&quot;</span><span class="p">:</span> <span class="err">&lt;task_datasource&gt;</span><span class="p">,</span>
<span class="nt">&quot;interval&quot;</span><span class="p">:</span> <span class="err">&lt;interval</span> <span class="err">to</span> <span class="err">specify</span> <span class="err">segments</span> <span class="err">to</span> <span class="err">be</span> <span class="err">merged&gt;</span><span class="p">,</span>
<span class="nt">&quot;dimensions&quot;</span> <span class="err">&lt;custom</span> <span class="err">dimensionsSpec&gt;</span><span class="p">,</span>
<span class="nt">&quot;keepSegmentGranularity&quot;</span><span class="p">:</span> <span class="err">&lt;</span><span class="kc">true</span> <span class="err">or</span> <span class="kc">false</span><span class="err">&gt;</span><span class="p">,</span>
<span class="nt">&quot;segmentGranularity&quot;</span><span class="p">:</span> <span class="err">&lt;segment</span> <span class="err">granularity</span> <span class="err">after</span> <span class="err">compaction&gt;</span><span class="p">,</span>
<span class="nt">&quot;targetCompactionSizeBytes&quot;</span><span class="p">:</span> <span class="err">&lt;target</span> <span class="err">size</span> <span class="err">of</span> <span class="err">compacted</span> <span class="err">segments&gt;</span>
<span class="s2">&quot;tuningConfig&quot;</span> <span class="err">&lt;index</span> <span class="err">task</span> <span class="err">tuningConfig&gt;</span><span class="p">,</span>
<span class="nt">&quot;context&quot;</span><span class="p">:</span> <span class="err">&lt;task</span> <span class="err">context&gt;</span>
<span class="p">}</span>
</code></pre></div>
<table><thead>
<tr>
<th>Field</th>
<th>Description</th>
<th>Required</th>
</tr>
</thead><tbody>
<tr>
<td><code>type</code></td>
<td>Task type. Should be <code>compact</code></td>
<td>Yes</td>
</tr>
<tr>
<td><code>id</code></td>
<td>Task id</td>
<td>No</td>
</tr>
<tr>
<td><code>dataSource</code></td>
<td>DataSource name to be compacted</td>
<td>Yes</td>
</tr>
<tr>
<td><code>interval</code></td>
<td>Interval of segments to be compacted</td>
<td>Yes</td>
</tr>
<tr>
<td><code>dimensionsSpec</code></td>
<td>Custom dimensionsSpec. Compaction task will use this dimensionsSpec if exist instead of generating one. See below for more details.</td>
<td>No</td>
</tr>
<tr>
<td><code>metricsSpec</code></td>
<td>Custom metricsSpec. Compaction task will use this metricsSpec if specified rather than generating one.</td>
<td>No</td>
</tr>
<tr>
<td><code>segmentGranularity</code></td>
<td>If this is set, compactionTask will change the segment granularity for the given interval. See <a href="./ingestion-spec.html#uniform-granularity-spec">segmentGranularity of Uniform Granularity Spec</a> for more details. See the below table for the behavior.</td>
<td>No</td>
</tr>
<tr>
<td><code>keepSegmentGranularity</code></td>
<td>Deprecated. Please use <code>segmentGranularity</code> instead. See the below table for its behavior.</td>
<td>No</td>
</tr>
<tr>
<td><code>targetCompactionSizeBytes</code></td>
<td>Target segment size after comapction. Cannot be used with <code>maxRowsPerSegment</code>, <code>maxTotalRows</code>, and <code>numShards</code> in tuningConfig.</td>
<td>No</td>
</tr>
<tr>
<td><code>tuningConfig</code></td>
<td><a href="../ingestion/native_tasks.html#tuningconfig">Index task tuningConfig</a></td>
<td>No</td>
</tr>
<tr>
<td><code>context</code></td>
<td><a href="../ingestion/locking-and-priority.html#task-context">Task context</a></td>
<td>No</td>
</tr>
</tbody></table>
<h3 id="used-segmentgranularity-based-on-segmentgranularity-and-keepsegmentgranularity">Used segmentGranularity based on <code>segmentGranularity</code> and <code>keepSegmentGranularity</code></h3>
<table><thead>
<tr>
<th>SegmentGranularity</th>
<th>keepSegmentGranularity</th>
<th>Used SegmentGranularity</th>
</tr>
</thead><tbody>
<tr>
<td>Non-null</td>
<td>True</td>
<td>Error</td>
</tr>
<tr>
<td>Non-null</td>
<td>False</td>
<td>Given segmentGranularity</td>
</tr>
<tr>
<td>Non-null</td>
<td>Null</td>
<td>Given segmentGranularity</td>
</tr>
<tr>
<td>Null</td>
<td>True</td>
<td>Original segmentGranularity</td>
</tr>
<tr>
<td>Null</td>
<td>False</td>
<td>ALL segmentGranularity. All events will fall into the single time chunk.</td>
</tr>
<tr>
<td>Null</td>
<td>Null</td>
<td>Original segmentGranularity</td>
</tr>
</tbody></table>
<p>An example of compaction task is</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;compact&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;interval&quot;</span> <span class="p">:</span> <span class="s2">&quot;2017-01-01/2018-01-01&quot;</span>
<span class="p">}</span>
</code></pre></div>
<p>This compaction task reads <em>all segments</em> of the interval <code>2017-01-01/2018-01-01</code> and results in new segments.
Since both <code>segmentGranularity</code> and <code>keepSegmentGranularity</code> are null, the original segment granularity will be remained and not changed after compaction.
To control the number of result segments per time chunk, you can set <a href="../configuration/index.html#compaction-dynamic-configuration">maxRowsPerSegment</a> or <a href="../ingestion/native_tasks.html#tuningconfig">numShards</a>.
Please note that you can run multiple compactionTasks at the same time. For example, you can run 12 compactionTasks per month instead of running a single task for the entire year.</p>
<p>A compaction task internally generates an <code>index</code> task spec for performing compaction work with some fixed parameters.
For example, its <code>firehose</code> is always the <a href="./firehose.html#ingestsegmentfirehose">ingestSegmentSpec</a>, and <code>dimensionsSpec</code> and <code>metricsSpec</code>
include all dimensions and metrics of the input segments by default.</p>
<p>Compaction tasks will exit with a failure status code, without doing anything, if the interval you specify has no
data segments loaded in it (or if the interval you specify is empty).</p>
<p>The output segment can have different metadata from the input segments unless all input segments have the same metadata.</p>
<ul>
<li>Dimensions: since Apache Druid (incubating) supports schema change, the dimensions can be different across segments even if they are a part of the same dataSource.
If the input segments have different dimensions, the output segment basically includes all dimensions of the input segments.
However, even if the input segments have the same set of dimensions, the dimension order or the data type of dimensions can be different. For example, the data type of some dimensions can be
changed from <code>string</code> to primitive types, or the order of dimensions can be changed for better locality.
In this case, the dimensions of recent segments precede that of old segments in terms of data types and the ordering.
This is because more recent segments are more likely to have the new desired order and data types. If you want to use
your own ordering and types, you can specify a custom <code>dimensionsSpec</code> in the compaction task spec.</li>
<li>Roll-up: the output segment is rolled up only when <code>rollup</code> is set for all input segments.
See <a href="../ingestion/index.html#rollup">Roll-up</a> for more details.
You can check that your segments are rolled up or not by using <a href="../querying/segmentmetadataquery.html#analysistypes">Segment Metadata Queries</a>.</li>
</ul>
</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.14.2-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>