miller/docs6/docs/_build/html/reference-dsl.html

127 lines
No EOL
7.6 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>DSL reference: overview &#8212; Miller 6.0.0-alpha documentation</title>
<link rel="stylesheet" href="_static/scrolls.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="_static/print.css" type="text/css" />
<script id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
<script src="_static/jquery.js"></script>
<script src="_static/underscore.js"></script>
<script src="_static/doctools.js"></script>
<script src="_static/language_data.js"></script>
<script src="_static/theme_extras.js"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="DSL reference: syntax" href="reference-dsl-syntax.html" />
<link rel="prev" title="Reference: online help" href="reference-main-online-help.html" />
</head><body>
<div id="content">
<div class="header">
<h1 class="heading"><a href="index.html"
title="back to the documentation overview"><span>DSL reference: overview</span></a></h1>
</div>
<div class="relnav" role="navigation" aria-label="related navigation">
<a href="reference-main-online-help.html">&laquo; Reference: online help</a> |
<a href="#">DSL reference: overview</a>
| <a href="reference-dsl-syntax.html">DSL reference: syntax &raquo;</a>
</div>
<div id="contentwrapper">
<div id="toc" role="navigation" aria-label="table of contents navigation">
<h3>Table of Contents</h3>
<ul>
<li><a class="reference internal" href="#">DSL reference: overview</a><ul>
<li><a class="reference internal" href="#overview">Overview</a></li>
</ul>
</li>
</ul>
</div>
<div role="main">
<div class="section" id="dsl-reference-overview">
<h1>DSL reference: overview<a class="headerlink" href="#dsl-reference-overview" title="Permalink to this headline"></a></h1>
<div class="section" id="overview">
<h2>Overview<a class="headerlink" href="#overview" title="Permalink to this headline"></a></h2>
<p>Heres comparison of verbs and <code class="docutils literal notranslate"><span class="pre">put</span></code>/<code class="docutils literal notranslate"><span class="pre">filter</span></code> DSL expressions:</p>
<p>Example:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> mlr stats1 -a sum -f x -g a data/small
</span> a=pan,x_sum=0.3467901443380824
a=eks,x_sum=1.1400793586611044
a=wye,x_sum=0.7778922255683036
</pre></div>
</div>
<ul class="simple">
<li><p>Verbs are coded in Go</p></li>
<li><p>They run a bit faster</p></li>
<li><p>They take fewer keystrokes</p></li>
<li><p>There is less to learn</p></li>
<li><p>Their customization is limited to each verbs options</p></li>
</ul>
<p>Example:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> mlr put -q &#39;@x_sum[$a] += $x; end{emit @x_sum, &quot;a&quot;}&#39; data/small
</span> a=pan,x_sum=0.3467901443380824
a=eks,x_sum=1.1400793586611044
a=wye,x_sum=0.7778922255683036
</pre></div>
</div>
<ul class="simple">
<li><p>You get to write your own DSL expressions</p></li>
<li><p>They run a bit slower</p></li>
<li><p>They take more keystrokes</p></li>
<li><p>There is more to learn</p></li>
<li><p>They are highly customizable</p></li>
</ul>
<p>Please see <a class="reference internal" href="reference-verbs.html"><span class="doc">Reference: list of verbs</span></a> for information on verbs other than <code class="docutils literal notranslate"><span class="pre">put</span></code> and <code class="docutils literal notranslate"><span class="pre">filter</span></code>.</p>
<p>The essential usages of <code class="docutils literal notranslate"><span class="pre">mlr</span> <span class="pre">filter</span></code> and <code class="docutils literal notranslate"><span class="pre">mlr</span> <span class="pre">put</span></code> are for record-selection and record-updating expressions, respectively. For example, given the following input data:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> cat data/small
</span> a=pan,b=pan,i=1,x=0.3467901443380824,y=0.7268028627434533
a=eks,b=pan,i=2,x=0.7586799647899636,y=0.5221511083334797
a=wye,b=wye,i=3,x=0.20460330576630303,y=0.33831852551664776
a=eks,b=wye,i=4,x=0.38139939387114097,y=0.13418874328430463
a=wye,b=pan,i=5,x=0.5732889198020006,y=0.8636244699032729
</pre></div>
</div>
<p>you might retain only the records whose <code class="docutils literal notranslate"><span class="pre">a</span></code> field has value <code class="docutils literal notranslate"><span class="pre">eks</span></code>:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> mlr filter &#39;$a == &quot;eks&quot;&#39; data/small
</span> a=eks,b=pan,i=2,x=0.7586799647899636,y=0.5221511083334797
a=eks,b=wye,i=4,x=0.38139939387114097,y=0.13418874328430463
</pre></div>
</div>
<p>or you might add a new field which is a function of existing fields:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span><span class="hll"> mlr put &#39;$ab = $a . &quot;_&quot; . $b &#39; data/small
</span> a=pan,b=pan,i=1,x=0.3467901443380824,y=0.7268028627434533,ab=pan_pan
a=eks,b=pan,i=2,x=0.7586799647899636,y=0.5221511083334797,ab=eks_pan
a=wye,b=wye,i=3,x=0.20460330576630303,y=0.33831852551664776,ab=wye_wye
a=eks,b=wye,i=4,x=0.38139939387114097,y=0.13418874328430463,ab=eks_wye
a=wye,b=pan,i=5,x=0.5732889198020006,y=0.8636244699032729,ab=wye_pan
</pre></div>
</div>
<p>The two verbs <code class="docutils literal notranslate"><span class="pre">mlr</span> <span class="pre">filter</span></code> and <code class="docutils literal notranslate"><span class="pre">mlr</span> <span class="pre">put</span></code> are essentially the same. The only differences are:</p>
<ul class="simple">
<li><p>Expressions sent to <code class="docutils literal notranslate"><span class="pre">mlr</span> <span class="pre">filter</span></code> must end with a boolean expression, which is the filtering criterion;</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">mlr</span> <span class="pre">filter</span></code> expressions may not reference the <code class="docutils literal notranslate"><span class="pre">filter</span></code> keyword within them; and</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">mlr</span> <span class="pre">filter</span></code> expressions may not use <code class="docutils literal notranslate"><span class="pre">tee</span></code>, <code class="docutils literal notranslate"><span class="pre">emit</span></code>, <code class="docutils literal notranslate"><span class="pre">emitp</span></code>, or <code class="docutils literal notranslate"><span class="pre">emitf</span></code>.</p></li>
</ul>
<p>All the rest is the same: in particular, you can define and invoke functions and subroutines to help produce the final boolean statement, and record fields may be assigned to in the statements preceding the final boolean statement.</p>
<p>There are more details and more choices, of course, as detailed in the following sections.</p>
</div>
</div>
</div>
</div>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2021, John Kerl.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.2.1.
</div>
</body>
</html>