blob: 302359143e86c299e3a644486b0939c5cc85714c [file] [log] [blame]
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SQL Lab &mdash; Apache Superset documentation</title>
<script type="text/javascript" src="_static/js/modernizr.min.js"></script>
<script type="text/javascript" id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<script type="text/javascript" src="_static/language_data.js"></script>
<script type="text/javascript" src="_static/js/theme.js"></script>
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="Visualizations Gallery" href="gallery.html" />
<link rel="prev" title="Security" href="security.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="index.html" class="icon icon-home"> Apache Superset
</a>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="installation.html">Installation &amp; Configuration</a></li>
<li class="toctree-l1"><a class="reference internal" href="tutorial.html">Tutorial - Creating your first dashboard</a></li>
<li class="toctree-l1"><a class="reference internal" href="security.html">Security</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">SQL Lab</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#feature-overview">Feature Overview</a></li>
<li class="toctree-l2"><a class="reference internal" href="#extra-features">Extra features</a></li>
<li class="toctree-l2"><a class="reference internal" href="#templating-with-jinja">Templating with Jinja</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#available-macros">Available macros</a></li>
<li class="toctree-l3"><a class="reference internal" href="#extending-macros">Extending macros</a></li>
<li class="toctree-l3"><a class="reference internal" href="#query-cost-estimation">Query cost estimation</a></li>
<li class="toctree-l3"><a class="reference internal" href="#create-table-as-ctas">Create Table As (CTAS)</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="gallery.html">Visualizations Gallery</a></li>
<li class="toctree-l1"><a class="reference internal" href="druid.html">Druid</a></li>
<li class="toctree-l1"><a class="reference internal" href="misc.html">Misc</a></li>
<li class="toctree-l1"><a class="reference internal" href="faq.html">FAQ</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="index.html">Apache Superset</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="index.html">Docs</a> &raquo;</li>
<li>SQL Lab</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<div class="section" id="sql-lab">
<h1>SQL Lab<a class="headerlink" href="#sql-lab" title="Permalink to this headline"></a></h1>
<p>SQL Lab is a modern, feature-rich SQL IDE written in
<a class="reference external" href="https://facebook.github.io/react/">React</a>.</p>
<hr class="docutils" />
<img alt="_images/sqllab.png" src="_images/sqllab.png" />
<hr class="docutils" />
<div class="section" id="feature-overview">
<h2>Feature Overview<a class="headerlink" href="#feature-overview" title="Permalink to this headline"></a></h2>
<ul class="simple">
<li><p>Connects to just about any database backend</p></li>
<li><p>A multi-tab environment to work on multiple queries at a time</p></li>
<li><p>A smooth flow to visualize your query results using Superset’s rich
visualization capabilities</p></li>
<li><p>Browse database metadata: tables, columns, indexes, partitions</p></li>
<li><p>Support for long-running queries</p>
<ul>
<li><p>uses the <a class="reference external" href="http://www.celeryproject.org/">Celery distributed queue</a>
to dispatch query handling to workers</p></li>
<li><p>supports defining a “results backend” to persist query results</p></li>
</ul>
</li>
<li><p>A search engine to find queries executed in the past</p></li>
<li><p>Supports templating using the
<a class="reference external" href="http://jinja.pocoo.org/docs/dev/">Jinja templating language</a>
which allows for using macros in your SQL code</p></li>
</ul>
</div>
<div class="section" id="extra-features">
<h2>Extra features<a class="headerlink" href="#extra-features" title="Permalink to this headline"></a></h2>
<ul class="simple">
<li><p>Hit <code class="docutils literal notranslate"><span class="pre">alt</span> <span class="pre">+</span> <span class="pre">enter</span></code> as a keyboard shortcut to run your query</p></li>
</ul>
</div>
<div class="section" id="templating-with-jinja">
<h2>Templating with Jinja<a class="headerlink" href="#templating-with-jinja" title="Permalink to this headline"></a></h2>
<div class="highlight-sql notranslate"><div class="highlight"><pre><span></span><span class="k">SELECT</span> <span class="o">*</span>
<span class="k">FROM</span> <span class="n">some_table</span>
<span class="k">WHERE</span> <span class="n">partition_key</span> <span class="o">=</span> <span class="s1">&#39;{{ presto.first_latest_partition(&#39;</span><span class="n">some_table</span><span class="s1">&#39;) }}&#39;</span>
</pre></div>
</div>
<p>Templating unleashes the power and capabilities of a
programming language within your SQL code.</p>
<p>Templates can also be used to write generic queries that are
parameterized so they can be re-used easily.</p>
<div class="section" id="available-macros">
<h3>Available macros<a class="headerlink" href="#available-macros" title="Permalink to this headline"></a></h3>
<p>We expose certain modules from Python’s standard library in
Superset’s Jinja context:</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">time</span></code>: <code class="docutils literal notranslate"><span class="pre">time</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">datetime</span></code>: <code class="docutils literal notranslate"><span class="pre">datetime.datetime</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">uuid</span></code>: <code class="docutils literal notranslate"><span class="pre">uuid</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">random</span></code>: <code class="docutils literal notranslate"><span class="pre">random</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">relativedelta</span></code>: <code class="docutils literal notranslate"><span class="pre">dateutil.relativedelta.relativedelta</span></code></p></li>
</ul>
<p><a class="reference external" href="http://jinja.pocoo.org/docs/dev/templates/">Jinja’s builtin filters</a> can be also be applied where needed.</p>
</div>
<div class="section" id="extending-macros">
<h3>Extending macros<a class="headerlink" href="#extending-macros" title="Permalink to this headline"></a></h3>
<p>As mentioned in the <a class="reference external" href="https://superset.incubator.apache.org/installation.html#installation-configuration">Installation &amp; Configuration</a> documentation,
it’s possible for administrators to expose more more macros in their
environment using the configuration variable <code class="docutils literal notranslate"><span class="pre">JINJA_CONTEXT_ADDONS</span></code>.
All objects referenced in this dictionary will become available for users
to integrate in their queries in <strong>SQL Lab</strong>.</p>
</div>
<div class="section" id="query-cost-estimation">
<h3>Query cost estimation<a class="headerlink" href="#query-cost-estimation" title="Permalink to this headline"></a></h3>
<p>Some databases support <code class="docutils literal notranslate"><span class="pre">EXPLAIN</span></code> queries that allow users to estimate the cost
of queries before executing this. Currently, Presto is supported in SQL Lab. To
enable query cost estimation, add the following keys to the “Extra” field in the
database configuration:</p>
<div class="highlight-json notranslate"><div class="highlight"><pre><span></span>{
&quot;version&quot;: &quot;0.319&quot;,
&quot;cost_estimate_enabled&quot;: true,
...
}
</pre></div>
</div>
<p>Here, “version” should be the version of your Presto cluster. Support for this
functionality was introduced in Presto 0.319.</p>
</div>
<div class="section" id="create-table-as-ctas">
<span id="ref-ctas-engine-config"></span><h3>Create Table As (CTAS)<a class="headerlink" href="#create-table-as-ctas" title="Permalink to this headline"></a></h3>
<p>You can use <code class="docutils literal notranslate"><span class="pre">CREATE</span> <span class="pre">TABLE</span> <span class="pre">AS</span> <span class="pre">SELECT</span> <span class="pre">...</span></code> statements on SQLLab. This feature can be toggled on
and off at the database configuration level.</p>
<p>Note that since <code class="docutils literal notranslate"><span class="pre">CREATE</span> <span class="pre">TABLE..</span></code> belongs to a SQL DDL category. Specifically on PostgreSQL, DDL is transactional,
this means that to properly use this feature you have to set <code class="docutils literal notranslate"><span class="pre">autocommit</span></code> to true on your engine parameters:</p>
<div class="highlight-json notranslate"><div class="highlight"><pre><span></span>{
...
&quot;engine_params&quot;: {&quot;isolation_level&quot;:&quot;AUTOCOMMIT&quot;},
...
}
</pre></div>
</div>
</div>
</div>
</div>
</div>
</div>
<footer>
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
<a href="gallery.html" class="btn btn-neutral float-right" title="Visualizations Gallery" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a>
<a href="security.html" class="btn btn-neutral float-left" title="Security" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
</div>
<hr/>
<div role="contentinfo">
<p>
</p>
</div>
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>