blob: a07df50ebd12c67e72aa444fd453cda471477290 [file] [log] [blame]
import{_ as r,r as o,o as i,c as d,d as a,e,b as t,f as n}from"./app-1758c693.js";const p={},l=n(`<h1 id="一、元数据操作" tabindex="-1"><a class="header-anchor" href="#一、元数据操作" aria-hidden="true">#</a> 一、元数据操作</h1><h2 id="_1、数据库管理" tabindex="-1"><a class="header-anchor" href="#_1、数据库管理" aria-hidden="true">#</a> 1、数据库管理</h2><h3 id="创建数据库" tabindex="-1"><a class="header-anchor" href="#创建数据库" aria-hidden="true">#</a> 创建数据库</h3><div class="language-sql line-numbers-mode" data-ext="sql"><pre class="language-sql"><code><span class="token keyword">CREATE</span> <span class="token keyword">DATABASE</span> root<span class="token punctuation">.</span>ln
<span class="token keyword">CREATE</span> <span class="token keyword">DATABASE</span> root<span class="token punctuation">.</span>ln<span class="token punctuation">.</span>wf01
<span class="token operator">&gt;</span> Msg: <span class="token number">300</span>: root<span class="token punctuation">.</span>ln has already been created <span class="token keyword">as</span> <span class="token keyword">database</span><span class="token punctuation">.</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="查看数据库" tabindex="-1"><a class="header-anchor" href="#查看数据库" aria-hidden="true">#</a> 查看数据库</h3><div class="language-sql line-numbers-mode" data-ext="sql"><pre class="language-sql"><code><span class="token keyword">show</span> <span class="token keyword">databases</span>
<span class="token keyword">show</span> <span class="token keyword">databases</span> root<span class="token punctuation">.</span><span class="token operator">*</span>
<span class="token keyword">show</span> <span class="token keyword">databases</span> root<span class="token punctuation">.</span><span class="token operator">*</span><span class="token operator">*</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="删除数据库" tabindex="-1"><a class="header-anchor" href="#删除数据库" aria-hidden="true">#</a> 删除数据库</h3><div class="language-sql line-numbers-mode" data-ext="sql"><pre class="language-sql"><code><span class="token keyword">DELETE</span> <span class="token keyword">DATABASE</span> root<span class="token punctuation">.</span>ln
<span class="token keyword">DELETE</span> <span class="token keyword">DATABASE</span> root<span class="token punctuation">.</span>sgcc
<span class="token keyword">DELETE</span> <span class="token keyword">DATABASE</span> root<span class="token punctuation">.</span><span class="token operator">*</span><span class="token operator">*</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="统计数据库数量" tabindex="-1"><a class="header-anchor" href="#统计数据库数量" aria-hidden="true">#</a> 统计数据库数量</h3><div class="language-sql line-numbers-mode" data-ext="sql"><pre class="language-sql"><code>count <span class="token keyword">databases</span>
count <span class="token keyword">databases</span> root<span class="token punctuation">.</span><span class="token operator">*</span>
count <span class="token keyword">databases</span> root<span class="token punctuation">.</span>sgcc<span class="token punctuation">.</span><span class="token operator">*</span>
count <span class="token keyword">databases</span> root<span class="token punctuation">.</span>sgcc
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h2 id="_2、时间序列管理" tabindex="-1"><a class="header-anchor" href="#_2、时间序列管理" aria-hidden="true">#</a> 2、时间序列管理</h2><h3 id="创建时间序列" tabindex="-1"><a class="header-anchor" href="#创建时间序列" aria-hidden="true">#</a> 创建时间序列</h3><div class="language-sql line-numbers-mode" data-ext="sql"><pre class="language-sql"><code><span class="token keyword">create</span> timeseries root<span class="token punctuation">.</span>ln<span class="token punctuation">.</span>wf01<span class="token punctuation">.</span>wt01<span class="token punctuation">.</span><span class="token keyword">status</span> <span class="token keyword">with</span> datatype<span class="token operator">=</span><span class="token keyword">BOOLEAN</span><span class="token punctuation">,</span>encoding<span class="token operator">=</span>PLAIN
<span class="token keyword">create</span> timeseries root<span class="token punctuation">.</span>ln<span class="token punctuation">.</span>wf01<span class="token punctuation">.</span>wt01<span class="token punctuation">.</span>temperature <span class="token keyword">with</span> datatype<span class="token operator">=</span><span class="token keyword">FLOAT</span><span class="token punctuation">,</span>encoding<span class="token operator">=</span>RLE
<span class="token keyword">create</span> timeseries root<span class="token punctuation">.</span>ln<span class="token punctuation">.</span>wf02<span class="token punctuation">.</span>wt02<span class="token punctuation">.</span>hardware <span class="token keyword">with</span> datatype<span class="token operator">=</span><span class="token keyword">TEXT</span><span class="token punctuation">,</span>encoding<span class="token operator">=</span>PLAIN
<span class="token keyword">create</span> timeseries root<span class="token punctuation">.</span>ln<span class="token punctuation">.</span>wf02<span class="token punctuation">.</span>wt02<span class="token punctuation">.</span><span class="token keyword">status</span> <span class="token keyword">with</span> datatype<span class="token operator">=</span><span class="token keyword">BOOLEAN</span><span class="token punctuation">,</span>encoding<span class="token operator">=</span>PLAIN
<span class="token keyword">create</span> timeseries root<span class="token punctuation">.</span>sgcc<span class="token punctuation">.</span>wf03<span class="token punctuation">.</span>wt01<span class="token punctuation">.</span><span class="token keyword">status</span> <span class="token keyword">with</span> datatype<span class="token operator">=</span><span class="token keyword">BOOLEAN</span><span class="token punctuation">,</span>encoding<span class="token operator">=</span>PLAIN
<span class="token keyword">create</span> timeseries root<span class="token punctuation">.</span>sgcc<span class="token punctuation">.</span>wf03<span class="token punctuation">.</span>wt01<span class="token punctuation">.</span>temperature <span class="token keyword">with</span> datatype<span class="token operator">=</span><span class="token keyword">FLOAT</span><span class="token punctuation">,</span>encoding<span class="token operator">=</span>RLE
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><ul><li>简化版</li></ul><div class="language-sql line-numbers-mode" data-ext="sql"><pre class="language-sql"><code><span class="token keyword">create</span> timeseries root<span class="token punctuation">.</span>ln<span class="token punctuation">.</span>wf01<span class="token punctuation">.</span>wt01<span class="token punctuation">.</span><span class="token keyword">status</span> <span class="token keyword">BOOLEAN</span> encoding<span class="token operator">=</span>PLAIN
<span class="token keyword">create</span> timeseries root<span class="token punctuation">.</span>ln<span class="token punctuation">.</span>wf01<span class="token punctuation">.</span>wt01<span class="token punctuation">.</span>temperature <span class="token keyword">FLOAT</span> encoding<span class="token operator">=</span>RLE
<span class="token keyword">create</span> timeseries root<span class="token punctuation">.</span>ln<span class="token punctuation">.</span>wf02<span class="token punctuation">.</span>wt02<span class="token punctuation">.</span>hardware <span class="token keyword">TEXT</span> encoding<span class="token operator">=</span>PLAIN
<span class="token keyword">create</span> timeseries root<span class="token punctuation">.</span>ln<span class="token punctuation">.</span>wf02<span class="token punctuation">.</span>wt02<span class="token punctuation">.</span><span class="token keyword">status</span> <span class="token keyword">BOOLEAN</span> encoding<span class="token operator">=</span>PLAIN
<span class="token keyword">create</span> timeseries root<span class="token punctuation">.</span>sgcc<span class="token punctuation">.</span>wf03<span class="token punctuation">.</span>wt01<span class="token punctuation">.</span><span class="token keyword">status</span> <span class="token keyword">BOOLEAN</span> encoding<span class="token operator">=</span>PLAIN
<span class="token keyword">create</span> timeseries root<span class="token punctuation">.</span>sgcc<span class="token punctuation">.</span>wf03<span class="token punctuation">.</span>wt01<span class="token punctuation">.</span>temperature <span class="token keyword">FLOAT</span> encoding<span class="token operator">=</span>RLE
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><ul><li>错误提示</li></ul><div class="language-sql line-numbers-mode" data-ext="sql"><pre class="language-sql"><code><span class="token keyword">create</span> timeseries root<span class="token punctuation">.</span>ln<span class="token punctuation">.</span>wf02<span class="token punctuation">.</span>wt02<span class="token punctuation">.</span><span class="token keyword">status</span> <span class="token keyword">WITH</span> DATATYPE<span class="token operator">=</span><span class="token keyword">BOOLEAN</span><span class="token punctuation">,</span> ENCODING<span class="token operator">=</span>TS_2DIFF
<span class="token operator">&gt;</span> error: encoding TS_2DIFF does <span class="token operator">not</span> support <span class="token keyword">BOOLEAN</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="创建对齐时间序列" tabindex="-1"><a class="header-anchor" href="#创建对齐时间序列" aria-hidden="true">#</a> 创建对齐时间序列</h3><div class="language-sql line-numbers-mode" data-ext="sql"><pre class="language-sql"><code><span class="token keyword">CREATE</span> ALIGNED TIMESERIES root<span class="token punctuation">.</span>ln<span class="token punctuation">.</span>wf01<span class="token punctuation">.</span>GPS<span class="token punctuation">(</span>latitude <span class="token keyword">FLOAT</span> encoding<span class="token operator">=</span>PLAIN compressor<span class="token operator">=</span>SNAPPY<span class="token punctuation">,</span> longitude <span class="token keyword">FLOAT</span> encoding<span class="token operator">=</span>PLAIN compressor<span class="token operator">=</span>SNAPPY<span class="token punctuation">)</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><h3 id="删除时间序列" tabindex="-1"><a class="header-anchor" href="#删除时间序列" aria-hidden="true">#</a> 删除时间序列</h3><div class="language-sql line-numbers-mode" data-ext="sql"><pre class="language-sql"><code><span class="token keyword">delete</span> timeseries root<span class="token punctuation">.</span>ln<span class="token punctuation">.</span>wf01<span class="token punctuation">.</span>wt01<span class="token punctuation">.</span><span class="token keyword">status</span>
<span class="token keyword">delete</span> timeseries root<span class="token punctuation">.</span>ln<span class="token punctuation">.</span>wf01<span class="token punctuation">.</span>wt01<span class="token punctuation">.</span>temperature<span class="token punctuation">,</span> root<span class="token punctuation">.</span>ln<span class="token punctuation">.</span>wf02<span class="token punctuation">.</span>wt02<span class="token punctuation">.</span>hardware
<span class="token keyword">delete</span> timeseries root<span class="token punctuation">.</span>ln<span class="token punctuation">.</span>wf02<span class="token punctuation">.</span><span class="token operator">*</span>
<span class="token keyword">drop</span> timeseries root<span class="token punctuation">.</span>ln<span class="token punctuation">.</span>wf02<span class="token punctuation">.</span><span class="token operator">*</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="查看时间序列" tabindex="-1"><a class="header-anchor" href="#查看时间序列" aria-hidden="true">#</a> 查看时间序列</h3><div class="language-sql line-numbers-mode" data-ext="sql"><pre class="language-sql"><code><span class="token keyword">SHOW</span> TIMESERIES
<span class="token keyword">SHOW</span> TIMESERIES <span class="token operator">&lt;</span>Path<span class="token operator">&gt;</span>
<span class="token keyword">show</span> timeseries root<span class="token punctuation">.</span><span class="token operator">*</span><span class="token operator">*</span>
<span class="token keyword">show</span> timeseries root<span class="token punctuation">.</span>ln<span class="token punctuation">.</span><span class="token operator">*</span><span class="token operator">*</span>
<span class="token keyword">show</span> timeseries root<span class="token punctuation">.</span>ln<span class="token punctuation">.</span><span class="token operator">*</span><span class="token operator">*</span> <span class="token keyword">limit</span> <span class="token number">10</span> <span class="token keyword">offset</span> <span class="token number">10</span>
<span class="token keyword">show</span> timeseries root<span class="token punctuation">.</span>ln<span class="token punctuation">.</span><span class="token operator">*</span><span class="token operator">*</span> <span class="token keyword">where</span> timeseries <span class="token keyword">contains</span> <span class="token string">&#39;wf01.wt&#39;</span>
<span class="token keyword">show</span> timeseries root<span class="token punctuation">.</span>ln<span class="token punctuation">.</span><span class="token operator">*</span><span class="token operator">*</span> <span class="token keyword">where</span> dataType<span class="token operator">=</span><span class="token keyword">FLOAT</span>
<span class="token keyword">SHOW</span> LATEST TIMESERIES
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="统计时间序列数量" tabindex="-1"><a class="header-anchor" href="#统计时间序列数量" aria-hidden="true">#</a> 统计时间序列数量</h3><div class="language-sql line-numbers-mode" data-ext="sql"><pre class="language-sql"><code>COUNT TIMESERIES root<span class="token punctuation">.</span><span class="token operator">*</span><span class="token operator">*</span>
COUNT TIMESERIES root<span class="token punctuation">.</span>ln<span class="token punctuation">.</span><span class="token operator">*</span><span class="token operator">*</span>
COUNT TIMESERIES root<span class="token punctuation">.</span>ln<span class="token punctuation">.</span><span class="token operator">*</span><span class="token punctuation">.</span><span class="token operator">*</span><span class="token punctuation">.</span><span class="token keyword">status</span>
COUNT TIMESERIES root<span class="token punctuation">.</span>ln<span class="token punctuation">.</span>wf01<span class="token punctuation">.</span>wt01<span class="token punctuation">.</span><span class="token keyword">status</span>
COUNT TIMESERIES root<span class="token punctuation">.</span><span class="token operator">*</span><span class="token operator">*</span> <span class="token keyword">WHERE</span> TIMESERIES <span class="token keyword">contains</span> <span class="token string">&#39;sgcc&#39;</span>
COUNT TIMESERIES root<span class="token punctuation">.</span><span class="token operator">*</span><span class="token operator">*</span> <span class="token keyword">WHERE</span> DATATYPE <span class="token operator">=</span> INT64
COUNT TIMESERIES root<span class="token punctuation">.</span><span class="token operator">*</span><span class="token operator">*</span> <span class="token keyword">WHERE</span> TAGS<span class="token punctuation">(</span>unit<span class="token punctuation">)</span> <span class="token keyword">contains</span> <span class="token string">&#39;c&#39;</span>
COUNT TIMESERIES root<span class="token punctuation">.</span><span class="token operator">*</span><span class="token operator">*</span> <span class="token keyword">WHERE</span> TAGS<span class="token punctuation">(</span>unit<span class="token punctuation">)</span> <span class="token operator">=</span> <span class="token string">&#39;c&#39;</span>
COUNT TIMESERIES root<span class="token punctuation">.</span><span class="token operator">*</span><span class="token operator">*</span> <span class="token keyword">WHERE</span> TIMESERIES <span class="token keyword">contains</span> <span class="token string">&#39;sgcc&#39;</span> <span class="token keyword">group</span> <span class="token keyword">by</span> <span class="token keyword">level</span> <span class="token operator">=</span> <span class="token number">1</span>
COUNT TIMESERIES root<span class="token punctuation">.</span><span class="token operator">*</span><span class="token operator">*</span> <span class="token keyword">GROUP</span> <span class="token keyword">BY</span> <span class="token keyword">LEVEL</span><span class="token operator">=</span><span class="token number">1</span>
COUNT TIMESERIES root<span class="token punctuation">.</span>ln<span class="token punctuation">.</span><span class="token operator">*</span><span class="token operator">*</span> <span class="token keyword">GROUP</span> <span class="token keyword">BY</span> <span class="token keyword">LEVEL</span><span class="token operator">=</span><span class="token number">2</span>
COUNT TIMESERIES root<span class="token punctuation">.</span>ln<span class="token punctuation">.</span>wf01<span class="token punctuation">.</span><span class="token operator">*</span> <span class="token keyword">GROUP</span> <span class="token keyword">BY</span> <span class="token keyword">LEVEL</span><span class="token operator">=</span><span class="token number">2</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="标签点管理" tabindex="-1"><a class="header-anchor" href="#标签点管理" aria-hidden="true">#</a> 标签点管理</h3><div class="language-sql line-numbers-mode" data-ext="sql"><pre class="language-sql"><code><span class="token keyword">create</span> timeseries root<span class="token punctuation">.</span>turbine<span class="token punctuation">.</span>d1<span class="token punctuation">.</span>s1<span class="token punctuation">(</span>temprature<span class="token punctuation">)</span> <span class="token keyword">with</span> datatype<span class="token operator">=</span><span class="token keyword">FLOAT</span><span class="token punctuation">,</span> encoding<span class="token operator">=</span>RLE<span class="token punctuation">,</span> compression<span class="token operator">=</span>SNAPPY tags<span class="token punctuation">(</span>tag1<span class="token operator">=</span>v1<span class="token punctuation">,</span> tag2<span class="token operator">=</span>v2<span class="token punctuation">)</span> attributes<span class="token punctuation">(</span>attr1<span class="token operator">=</span>v1<span class="token punctuation">,</span> attr2<span class="token operator">=</span>v2<span class="token punctuation">)</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><ul><li>重命名标签或属性</li></ul><div class="language-sql line-numbers-mode" data-ext="sql"><pre class="language-sql"><code><span class="token keyword">ALTER</span> timeseries root<span class="token punctuation">.</span>turbine<span class="token punctuation">.</span>d1<span class="token punctuation">.</span>s1 <span class="token keyword">RENAME</span> tag1 <span class="token keyword">TO</span> newTag1
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><ul><li>重新设置标签或属性的值</li></ul><div class="language-sql line-numbers-mode" data-ext="sql"><pre class="language-sql"><code><span class="token keyword">ALTER</span> timeseries root<span class="token punctuation">.</span>turbine<span class="token punctuation">.</span>d1<span class="token punctuation">.</span>s1 <span class="token keyword">SET</span> newTag1<span class="token operator">=</span>newV1<span class="token punctuation">,</span> attr1<span class="token operator">=</span>newV1
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><ul><li>删除已经存在的标签或属性</li></ul><div class="language-sql line-numbers-mode" data-ext="sql"><pre class="language-sql"><code><span class="token keyword">ALTER</span> timeseries root<span class="token punctuation">.</span>turbine<span class="token punctuation">.</span>d1<span class="token punctuation">.</span>s1 <span class="token keyword">DROP</span> tag1<span class="token punctuation">,</span> tag2
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><ul><li>添加新的标签</li></ul><div class="language-sql line-numbers-mode" data-ext="sql"><pre class="language-sql"><code><span class="token keyword">ALTER</span> timeseries root<span class="token punctuation">.</span>turbine<span class="token punctuation">.</span>d1<span class="token punctuation">.</span>s1 <span class="token keyword">ADD</span> TAGS tag3<span class="token operator">=</span>v3<span class="token punctuation">,</span> tag4<span class="token operator">=</span>v4
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><ul><li>添加新的属性</li></ul><div class="language-sql line-numbers-mode" data-ext="sql"><pre class="language-sql"><code><span class="token keyword">ALTER</span> timeseries root<span class="token punctuation">.</span>turbine<span class="token punctuation">.</span>d1<span class="token punctuation">.</span>s1 <span class="token keyword">ADD</span> ATTRIBUTES attr3<span class="token operator">=</span>v3<span class="token punctuation">,</span> attr4<span class="token operator">=</span>v4
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><ul><li>更新插入别名,标签和属性</li></ul><div class="language-sql line-numbers-mode" data-ext="sql"><pre class="language-sql"><code><span class="token keyword">ALTER</span> timeseries root<span class="token punctuation">.</span>turbine<span class="token punctuation">.</span>d1<span class="token punctuation">.</span>s1 UPSERT ALIAS<span class="token operator">=</span>newAlias TAGS<span class="token punctuation">(</span>tag2<span class="token operator">=</span>newV2<span class="token punctuation">,</span> tag3<span class="token operator">=</span>v3<span class="token punctuation">)</span> ATTRIBUTES<span class="token punctuation">(</span>attr3<span class="token operator">=</span>v3<span class="token punctuation">,</span> attr4<span class="token operator">=</span>v4<span class="token punctuation">)</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><ul><li>使用标签作为过滤条件查询时间序列</li></ul><div class="language-sql line-numbers-mode" data-ext="sql"><pre class="language-sql"><code><span class="token keyword">SHOW</span> TIMESERIES <span class="token punctuation">(</span><span class="token operator">&lt;</span><span class="token identifier"><span class="token punctuation">\`</span>PathPattern<span class="token punctuation">\`</span></span><span class="token operator">&gt;</span><span class="token punctuation">)</span>? timeseriesWhereClause
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p>返回给定路径的下的所有满足条件的时间序列信息:</p><div class="language-sql line-numbers-mode" data-ext="sql"><pre class="language-sql"><code><span class="token keyword">ALTER</span> timeseries root<span class="token punctuation">.</span>ln<span class="token punctuation">.</span>wf02<span class="token punctuation">.</span>wt02<span class="token punctuation">.</span>hardware <span class="token keyword">ADD</span> TAGS unit<span class="token operator">=</span>c
<span class="token keyword">ALTER</span> timeseries root<span class="token punctuation">.</span>ln<span class="token punctuation">.</span>wf02<span class="token punctuation">.</span>wt02<span class="token punctuation">.</span><span class="token keyword">status</span> <span class="token keyword">ADD</span> TAGS description<span class="token operator">=</span>test1
<span class="token keyword">show</span> timeseries root<span class="token punctuation">.</span>ln<span class="token punctuation">.</span><span class="token operator">*</span><span class="token operator">*</span> <span class="token keyword">where</span> TAGS<span class="token punctuation">(</span>unit<span class="token punctuation">)</span><span class="token operator">=</span><span class="token string">&#39;c&#39;</span>
<span class="token keyword">show</span> timeseries root<span class="token punctuation">.</span>ln<span class="token punctuation">.</span><span class="token operator">*</span><span class="token operator">*</span> <span class="token keyword">where</span> TAGS<span class="token punctuation">(</span>description<span class="token punctuation">)</span> <span class="token keyword">contains</span> <span class="token string">&#39;test1&#39;</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><ul><li>使用标签作为过滤条件统计时间序列数量</li></ul><div class="language-sql line-numbers-mode" data-ext="sql"><pre class="language-sql"><code>COUNT TIMESERIES <span class="token punctuation">(</span><span class="token operator">&lt;</span><span class="token identifier"><span class="token punctuation">\`</span>PathPattern<span class="token punctuation">\`</span></span><span class="token operator">&gt;</span><span class="token punctuation">)</span>? timeseriesWhereClause
COUNT TIMESERIES <span class="token punctuation">(</span><span class="token operator">&lt;</span><span class="token identifier"><span class="token punctuation">\`</span>PathPattern<span class="token punctuation">\`</span></span><span class="token operator">&gt;</span><span class="token punctuation">)</span>? timeseriesWhereClause <span class="token keyword">GROUP</span> <span class="token keyword">BY</span> <span class="token keyword">LEVEL</span><span class="token operator">=</span><span class="token operator">&lt;</span><span class="token keyword">INTEGER</span><span class="token operator">&gt;</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div></div></div><p>返回给定路径的下的所有满足条件的时间序列的数量:</p><div class="language-sql line-numbers-mode" data-ext="sql"><pre class="language-sql"><code>count timeseries
count timeseries root<span class="token punctuation">.</span><span class="token operator">*</span><span class="token operator">*</span> <span class="token keyword">where</span> TAGS<span class="token punctuation">(</span>unit<span class="token punctuation">)</span><span class="token operator">=</span><span class="token string">&#39;c&#39;</span>
count timeseries root<span class="token punctuation">.</span><span class="token operator">*</span><span class="token operator">*</span> <span class="token keyword">where</span> TAGS<span class="token punctuation">(</span>unit<span class="token punctuation">)</span><span class="token operator">=</span><span class="token string">&#39;c&#39;</span> <span class="token keyword">group</span> <span class="token keyword">by</span> <span class="token keyword">level</span> <span class="token operator">=</span> <span class="token number">2</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>创建对齐时间序列:</p><div class="language-sql line-numbers-mode" data-ext="sql"><pre class="language-sql"><code><span class="token keyword">create</span> aligned timeseries root<span class="token punctuation">.</span>sg1<span class="token punctuation">.</span>d1<span class="token punctuation">(</span>s1 INT32 tags<span class="token punctuation">(</span>tag1<span class="token operator">=</span>v1<span class="token punctuation">,</span> tag2<span class="token operator">=</span>v2<span class="token punctuation">)</span> attributes<span class="token punctuation">(</span>attr1<span class="token operator">=</span>v1<span class="token punctuation">,</span> attr2<span class="token operator">=</span>v2<span class="token punctuation">)</span><span class="token punctuation">,</span> s2 <span class="token keyword">DOUBLE</span> tags<span class="token punctuation">(</span>tag3<span class="token operator">=</span>v3<span class="token punctuation">,</span> tag4<span class="token operator">=</span>v4<span class="token punctuation">)</span> attributes<span class="token punctuation">(</span>attr3<span class="token operator">=</span>v3<span class="token punctuation">,</span> attr4<span class="token operator">=</span>v4<span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p>支持查询:</p><div class="language-sql line-numbers-mode" data-ext="sql"><pre class="language-sql"><code><span class="token keyword">show</span> timeseries <span class="token keyword">where</span> TAGS<span class="token punctuation">(</span>tag1<span class="token punctuation">)</span><span class="token operator">=</span><span class="token string">&#39;v1&#39;</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><h2 id="_3、时间序列路径管理" tabindex="-1"><a class="header-anchor" href="#_3、时间序列路径管理" aria-hidden="true">#</a> 3、时间序列路径管理</h2><h3 id="查看路径的所有子路径" tabindex="-1"><a class="header-anchor" href="#查看路径的所有子路径" aria-hidden="true">#</a> 查看路径的所有子路径</h3><p>SHOW CHILD PATHS pathPattern</p><ul><li>查询 root.ln 的下一层:show child paths root.ln</li><li>查询形如 root.xx.xx.xx 的路径:show child paths root.<em>.</em></li></ul><h3 id="查看路径的所有子节点" tabindex="-1"><a class="header-anchor" href="#查看路径的所有子节点" aria-hidden="true">#</a> 查看路径的所有子节点</h3><p>SHOW CHILD NODES pathPattern</p><ul><li>查询 root 的下一层:show child nodes root</li><li>查询 root.ln 的下一层 :show child nodes root.ln</li></ul><h3 id="查看设备" tabindex="-1"><a class="header-anchor" href="#查看设备" aria-hidden="true">#</a> 查看设备</h3><p>IoTDB&gt; show devices</p><p>IoTDB&gt; show devices root.ln.**</p><h4 id="查看设备及其-database-信息" tabindex="-1"><a class="header-anchor" href="#查看设备及其-database-信息" aria-hidden="true">#</a> 查看设备及其 database 信息</h4><p>IoTDB&gt; show devices with database</p><p>IoTDB&gt; show devices root.ln.** with database</p><h3 id="统计节点数" tabindex="-1"><a class="header-anchor" href="#统计节点数" aria-hidden="true">#</a> 统计节点数</h3><p>IoTDB &gt; COUNT NODES root.** LEVEL=2</p><p>IoTDB &gt; COUNT NODES root.ln.** LEVEL=2</p><p>IoTDB &gt; COUNT NODES root.ln.wf01.* LEVEL=3</p><p>IoTDB &gt; COUNT NODES root.**.temperature LEVEL=3</p><h3 id="统计设备数量" tabindex="-1"><a class="header-anchor" href="#统计设备数量" aria-hidden="true">#</a> 统计设备数量</h3><p>IoTDB&gt; show devices</p><p>IoTDB&gt; count devices</p><p>IoTDB&gt; count devices root.ln.**</p><h2 id="_4、设备模板管理" tabindex="-1"><a class="header-anchor" href="#_4、设备模板管理" aria-hidden="true">#</a> 4、设备模板管理</h2><figure><img src="https://timechor.feishu.cn/space/api/box/stream/download/asynccode/?code=NzhkYzkzZDM0MjQxNDJlNmU5YWVhNWJkM2E3NzZmYWZfcllzQUZWYVpQMk1FRWVhSTlpQmRtblhYZmtQbnZqUGxfVG9rZW46VEJXbGJOWWJub0V5OWV4Sk1wZ2N6YmVXbkRlXzE2ODU0MzI4MDM6MTY4NTQzNjQwM19WNA" alt="img" tabindex="0" loading="lazy"><figcaption>img</figcaption></figure>`,75),c={href:"http://root.sg",target:"_blank",rel:"noopener noreferrer"},h=n(`<p>Create device root.sg.d1</p><figure><img src="https://timechor.feishu.cn/space/api/box/stream/download/asynccode/?code=Y2ZkMzUyMTAwMTJkZmZjOTdiODZmZmM4YjE1NzUzYWFfTGZ0T3lkOG1BSTJTY3ZMRWtsMElQcWdNYk01MVpBTDJfVG9rZW46Rllua2JBZDlDb3Y0RTJ4Nk14d2NITE9jbkNoXzE2ODU0MzI4MDM6MTY4NTQzNjQwM19WNA" alt="img" tabindex="0" loading="lazy"><figcaption>img</figcaption></figure><h3 id="创建元数据模板" tabindex="-1"><a class="header-anchor" href="#创建元数据模板" aria-hidden="true">#</a> 创建元数据模板</h3><div class="language-Go line-numbers-mode" data-ext="Go"><pre class="language-Go"><code>CREATE SCHEMA TEMPLATE &lt;templateName&gt; ALIGNED? &#39;(&#39; &lt;measurementId&gt; &lt;attributeClauses&gt; [&#39;,&#39; &lt;measurementId&gt; &lt;attributeClauses&gt;]+ &#39;)&#39;
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p>创建包含两个非对齐序列的元数据模板</p><p>IoTDB&gt; create schema template t1 (temperature FLOAT encoding=RLE, status BOOLEAN encoding=PLAIN compression=SNAPPY)</p><p>创建包含一组对齐序列的元数据模板</p><p>IoTDB&gt; create schema template t2 aligned (lat FLOAT encoding=Gorilla, lon FLOAT encoding=Gorilla)</p><h3 id="挂载元数据模板" tabindex="-1"><a class="header-anchor" href="#挂载元数据模板" aria-hidden="true">#</a> 挂载元数据模板</h3><p>IoTDB&gt; set SCHEMA TEMPLATE t1 to root.sg1</p><h3 id="激活元数据模板" tabindex="-1"><a class="header-anchor" href="#激活元数据模板" aria-hidden="true">#</a> 激活元数据模板</h3><p>IoTDB&gt; create timeseries using SCHEMA TEMPLATE on root.sg1.d1</p><p>IoTDB&gt; set SCHEMA TEMPLATE t1 to root.sg1.d1</p><p>IoTDB&gt; set SCHEMA TEMPLATE t2 to root.sg1.d2</p><p>IoTDB&gt; create timeseries using schema template on root.sg1.d1</p><p>IoTDB&gt; create timeseries using schema template on root.sg1.d2</p><h3 id="查看元数据模板" tabindex="-1"><a class="header-anchor" href="#查看元数据模板" aria-hidden="true">#</a> 查看元数据模板</h3><p>IoTDB&gt; show schema templates</p><ul><li>查看某个元数据模板下的物理量</li></ul><p>IoTDB&gt; show nodes in schema template t1</p><ul><li>查看挂载了某个元数据模板的路径</li></ul><p>IoTDB&gt; show paths set schema template t1</p><ul><li>查看使用了某个元数据模板的路径(即模板在该路径上已激活,序列已创建)</li></ul><p>IoTDB&gt; show paths using schema template t1</p><p>IoTDB&gt; show devices using schema template t1</p><h3 id="解除元数据模板" tabindex="-1"><a class="header-anchor" href="#解除元数据模板" aria-hidden="true">#</a> 解除元数据模板</h3><p>IoTDB&gt; delete timeseries of schema template t1 from root.sg1.d1</p><p>IoTDB&gt; deactivate schema template t1 from root.sg1.d1</p><p>批量处理</p><p>IoTDB&gt; delete timeseries of schema template t1 from root.sg1.<em>, root.sg2.</em></p><p>IoTDB&gt; deactivate schema template t1 from root.sg1.<em>, root.sg2.</em></p><h3 id="卸载元数据模板" tabindex="-1"><a class="header-anchor" href="#卸载元数据模板" aria-hidden="true">#</a> 卸载元数据模板</h3><p>IoTDB&gt; unset schema template t1 from root.sg1.d1</p><h3 id="删除元数据模板" tabindex="-1"><a class="header-anchor" href="#删除元数据模板" aria-hidden="true">#</a> 删除元数据模板</h3><p>IoTDB&gt; drop schema template t1</p><h2 id="_5、数据存活时间管理" tabindex="-1"><a class="header-anchor" href="#_5、数据存活时间管理" aria-hidden="true">#</a> 5、数据存活时间管理</h2><h3 id="设置-ttl" tabindex="-1"><a class="header-anchor" href="#设置-ttl" aria-hidden="true">#</a> 设置 TTL</h3><p>IoTDB&gt; set ttl to root.ln 3600000</p><p>IoTDB&gt; set ttl to root.sgcc.** 3600000</p><p>IoTDB&gt; set ttl to root.** 3600000</p><h3 id="取消-ttl" tabindex="-1"><a class="header-anchor" href="#取消-ttl" aria-hidden="true">#</a> 取消 TTL</h3><p>IoTDB&gt; unset ttl to root.ln</p><p>IoTDB&gt; unset ttl to root.sgcc.**</p><p>IoTDB&gt; unset ttl to root.**</p><h3 id="显示-ttl" tabindex="-1"><a class="header-anchor" href="#显示-ttl" aria-hidden="true">#</a> 显示 TTL</h3><p>IoTDB&gt; SHOW ALL TTL</p><p>IoTDB&gt; SHOW TTL ON StorageGroupNames</p><h1 id="写入数据" tabindex="-1"><a class="header-anchor" href="#写入数据" aria-hidden="true">#</a> 写入数据</h1><h2 id="_1、写入单列数据" tabindex="-1"><a class="header-anchor" href="#_1、写入单列数据" aria-hidden="true">#</a> 1、写入单列数据</h2><p>IoTDB &gt; insert into root.ln.wf02.wt02(timestamp,status) values(1,true)</p><p>IoTDB &gt; insert into root.ln.wf02.wt02(timestamp,hardware) values(1, &#39;v1&#39;),(2, &#39;v1&#39;)</p><h2 id="_2、写入多列数据" tabindex="-1"><a class="header-anchor" href="#_2、写入多列数据" aria-hidden="true">#</a> 2、写入多列数据</h2><p>IoTDB &gt; insert into root.ln.wf02.wt02(timestamp, status, hardware) values (2, false, &#39;v2&#39;)</p><p>IoTDB &gt; insert into root.ln.wf02.wt02(timestamp, status, hardware) VALUES (3, false, &#39;v3&#39;),(4, true, &#39;v4&#39;)</p><h2 id="_3、使用服务器时间戳" tabindex="-1"><a class="header-anchor" href="#_3、使用服务器时间戳" aria-hidden="true">#</a> 3、使用服务器时间戳</h2><p>IoTDB &gt; insert into root.ln.wf02.wt02(status, hardware) values (false, &#39;v2&#39;)</p><h2 id="_4、写入对齐时间序列数据" tabindex="-1"><a class="header-anchor" href="#_4、写入对齐时间序列数据" aria-hidden="true">#</a> 4、写入对齐时间序列数据</h2><p>IoTDB &gt; create aligned timeseries root.sg1.d1(s1 INT32, s2 DOUBLE)</p><p>IoTDB &gt; insert into root.sg1.d1(timestamp, s1, s2) aligned values(1, 1, 1)</p><p>IoTDB &gt; insert into root.sg1.d1(timestamp, s1, s2) aligned values(2, 2, 2), (3, 3, 3)</p><p>IoTDB &gt; select * from root.sg1.d1</p><h2 id="_5、加载-tsfile-文件数据" tabindex="-1"><a class="header-anchor" href="#_5、加载-tsfile-文件数据" aria-hidden="true">#</a> 5、加载 TsFile 文件数据</h2><p>load &#39;&lt;path/dir&gt;&#39; [sglevel=int][verify=true/false][onSuccess=delete/none]</p><h3 id="通过指定文件路径-绝对路径-加载单-tsfile-文件" tabindex="-1"><a class="header-anchor" href="#通过指定文件路径-绝对路径-加载单-tsfile-文件" aria-hidden="true">#</a> 通过指定文件路径(绝对路径)加载单 tsfile 文件</h3><ul><li><code>load &#39;/Users/Desktop/data/1575028885956-101-0.tsfile&#39;</code></li><li><code>load &#39;/Users/Desktop/data/1575028885956-101-0.tsfile&#39; verify=true</code></li><li><code>load &#39;/Users/Desktop/data/1575028885956-101-0.tsfile&#39; verify=false</code></li><li><code>load &#39;/Users/Desktop/data/1575028885956-101-0.tsfile&#39; sglevel=1</code></li><li><code>load &#39;/Users/Desktop/data/1575028885956-101-0.tsfile&#39; onSuccess=delete</code></li><li><code>load &#39;/Users/Desktop/data/1575028885956-101-0.tsfile&#39; verify=true sglevel=1</code></li><li><code>load &#39;/Users/Desktop/data/1575028885956-101-0.tsfile&#39; verify=false sglevel=1</code></li><li><code>load &#39;/Users/Desktop/data/1575028885956-101-0.tsfile&#39; verify=true onSuccess=none</code></li><li><code>load &#39;/Users/Desktop/data/1575028885956-101-0.tsfile&#39; verify=false sglevel=1 onSuccess=delete</code></li></ul><h3 id="通过指定文件夹路径-绝对路径-批量加载文件" tabindex="-1"><a class="header-anchor" href="#通过指定文件夹路径-绝对路径-批量加载文件" aria-hidden="true">#</a> 通过指定文件夹路径(绝对路径)批量加载文件</h3><ul><li><code>load &#39;/Users/Desktop/data&#39;</code></li><li><code>load &#39;/Users/Desktop/data&#39; verify=false</code></li><li><code>load &#39;/Users/Desktop/data&#39; verify=true</code></li><li><code>load &#39;/Users/Desktop/data&#39; verify=true sglevel=1</code></li><li><code>load &#39;/Users/Desktop/data&#39; verify=false sglevel=1 onSuccess=delete</code></li></ul><h1 id="删除数据" tabindex="-1"><a class="header-anchor" href="#删除数据" aria-hidden="true">#</a> 删除数据</h1><h2 id="_1、删除单列数据" tabindex="-1"><a class="header-anchor" href="#_1、删除单列数据" aria-hidden="true">#</a> 1、删除单列数据</h2><p>delete from root.ln.wf02.wt02.status where time&lt;=2017-11-01T16:26:00;</p><p>delete from root.ln.wf02.wt02.status where time&gt;=2017-01-01T00:00:00 and time&lt;=2017-11-01T16:26:00;</p><p>delete from root.ln.wf02.wt02.status where time &lt; 10</p><p>delete from root.ln.wf02.wt02.status where time &lt;= 10</p><p>delete from root.ln.wf02.wt02.status where time &lt; 20 and time &gt; 10</p><p>delete from root.ln.wf02.wt02.status where time &lt;= 20 and time &gt;= 10</p><p>delete from root.ln.wf02.wt02.status where time &gt; 20</p><p>delete from root.ln.wf02.wt02.status where time &gt;= 20</p><p>delete from root.ln.wf02.wt02.status where time = 20</p><p>出错:</p><p>delete from root.ln.wf02.wt02.status where time &gt; 4 or time &lt; 0</p><p>Msg: 303: Check metadata error: For delete statement, where clause can only contain atomic</p><p>expressions like : time &gt; XXX, time &lt;= XXX, or two atomic expressions connected by &#39;AND&#39;</p><p>删除时间序列中的所有数据:</p><p>delete from root.ln.wf02.wt02.status</p><h2 id="_2、删除多列数据" tabindex="-1"><a class="header-anchor" href="#_2、删除多列数据" aria-hidden="true">#</a> 2、删除多列数据</h2><p>delete from root.ln.wf02.wt02.* where time &lt;= 2017-11-01T16:26:00;</p><p>声明式的编程方式:</p><p>IoTDB&gt; delete from root.ln.wf03.wt02.status where time &lt; now()</p><p>Msg: The statement is executed successfully.</p><h1 id="数据查询" tabindex="-1"><a class="header-anchor" href="#数据查询" aria-hidden="true">#</a> 数据查询</h1><h2 id="_1、基础查询" tabindex="-1"><a class="header-anchor" href="#_1、基础查询" aria-hidden="true">#</a> 1、基础查询</h2><h3 id="时间过滤查询" tabindex="-1"><a class="header-anchor" href="#时间过滤查询" aria-hidden="true">#</a> 时间过滤查询</h3><p>select temperature from root.ln.wf01.wt01 where time &lt; 2017-11-01T00:08:00.000</p><h3 id="根据一个时间区间选择多列数据" tabindex="-1"><a class="header-anchor" href="#根据一个时间区间选择多列数据" aria-hidden="true">#</a> 根据一个时间区间选择多列数据</h3><p>select status, temperature from root.ln.wf01.wt01 where time &gt; 2017-11-01T00:05:00.000 and time &lt; 2017-11-01T00:12:00.000;</p><h3 id="按照多个时间区间选择同一设备的多列数据" tabindex="-1"><a class="header-anchor" href="#按照多个时间区间选择同一设备的多列数据" aria-hidden="true">#</a> 按照多个时间区间选择同一设备的多列数据</h3><p>select status, temperature from root.ln.wf01.wt01 where (time &gt; 2017-11-01T00:05:00.000 and time &lt; 2017-11-01T00:12:00.000) or (time &gt;= 2017-11-01T16:35:00.000 and time &lt;= 2017-11-01T16:37:00.000);</p><h3 id="按照多个时间区间选择不同设备的多列数据" tabindex="-1"><a class="header-anchor" href="#按照多个时间区间选择不同设备的多列数据" aria-hidden="true">#</a> 按照多个时间区间选择不同设备的多列数据</h3><p>select wf01.wt01.status, wf02.wt02.hardware from root.ln where (time &gt; 2017-11-01T00:05:00.000 and time &lt; 2017-11-01T00:12:00.000) or (time &gt;= 2017-11-01T16:35:00.000 and time &lt;= 2017-11-01T16:37:00.000);</p><h3 id="根据时间降序返回结果集" tabindex="-1"><a class="header-anchor" href="#根据时间降序返回结果集" aria-hidden="true">#</a> 根据时间降序返回结果集</h3><p>select * from root.ln.** where time &gt; 1 order by time desc limit 10;</p><h2 id="_2、选择表达式" tabindex="-1"><a class="header-anchor" href="#_2、选择表达式" aria-hidden="true">#</a> 2、选择表达式</h2><h3 id="使用别名" tabindex="-1"><a class="header-anchor" href="#使用别名" aria-hidden="true">#</a> 使用别名</h3><p>select s1 as temperature, s2 as speed from root.ln.wf01.wt01;</p><h3 id="运算符" tabindex="-1"><a class="header-anchor" href="#运算符" aria-hidden="true">#</a> 运算符</h3><h3 id="函数" tabindex="-1"><a class="header-anchor" href="#函数" aria-hidden="true">#</a> 函数</h3><p>不支持:</p><p>select s1, count(s1) from root.sg.d1;</p><p>select sin(s1), count(s1) from root.sg.d1;</p><p>select s1, count(s1) from root.sg.d1 group by ([10,100),10ms);</p><h4 id="时间序列查询嵌套表达式" tabindex="-1"><a class="header-anchor" href="#时间序列查询嵌套表达式" aria-hidden="true">#</a> 时间序列查询嵌套表达式</h4><p>示例 1:</p><p>select a,</p><p>​ b,</p><p>​ ((a + 1) * 2 - 1) % 2 + 1.5,</p><p>​ sin(a + sin(a + sin(b))),</p><p>​ -(a + b) * (sin(a + b) * sin(a + b) + cos(a + b) * cos(a + b)) + 1</p><p>from root.sg1;</p><p>示例 2:</p>`,119),u={href:"http://root.sg",target:"_blank",rel:"noopener noreferrer"},m=a("p",null,"示例 3:",-1),g=a("p",null,"select (a + *) / 2 from root.sg1",-1),f=a("p",null,"示例 4:",-1),E={href:"http://root.sg",target:"_blank",rel:"noopener noreferrer"},b=n(`<h4 id="聚合查询嵌套表达式" tabindex="-1"><a class="header-anchor" href="#聚合查询嵌套表达式" aria-hidden="true">#</a> 聚合查询嵌套表达式</h4><p>示例 1:</p><p>select avg(temperature),</p><p>​ sin(avg(temperature)),</p><p>​ avg(temperature) + 1,</p><p>​ -sum(hardware),</p><p>​ avg(temperature) + sum(hardware)</p><p>from root.ln.wf01.wt01;</p><p>示例 2:</p><p>select avg(*),</p><p>​ (avg(*) + 1) * 3 / 2 -1</p><p>from root.sg1</p><p>示例 3:</p><p>select avg(temperature),</p><p>​ sin(avg(temperature)),</p><p>​ avg(temperature) + 1,</p><p>​ -sum(hardware),</p><p>​ avg(temperature) + sum(hardware) as custom_sum</p><p>from root.ln.wf01.wt01</p><p>GROUP BY([10, 90), 10ms);</p><h2 id="_3、最新点查询" tabindex="-1"><a class="header-anchor" href="#_3、最新点查询" aria-hidden="true">#</a> 3、最新点查询</h2><p>SQL 语法:</p><div class="language-Go line-numbers-mode" data-ext="Go"><pre class="language-Go"><code>select last &lt;Path&gt; [COMMA &lt;Path&gt;]* from &lt; PrefixPath &gt; [COMMA &lt; PrefixPath &gt;]* &lt;whereClause&gt; [ORDER BY TIMESERIES (DESC | ASC)?]
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p>查询 root.ln.wf01.wt01.status 的最新数据点</p><p>IoTDB&gt; select last status from root.ln.wf01.wt01</p><p>查询 root.ln.wf01.wt01 下 status,temperature 时间戳大于等于 2017-11-07T23:50:00 的最新数据点</p><p>IoTDB&gt; select last status, temperature from root.ln.wf01.wt01 where time &gt;= 2017-11-07T23:50:00</p><p>查询 root.ln.wf01.wt01 下所有序列的最新数据点,并按照序列名降序排列</p><p>IoTDB&gt; select last * from root.ln.wf01.wt01 order by timeseries desc;</p><h2 id="_4、查询对齐模式" tabindex="-1"><a class="header-anchor" href="#_4、查询对齐模式" aria-hidden="true">#</a> 4、查询对齐模式</h2><h3 id="按设备对齐" tabindex="-1"><a class="header-anchor" href="#按设备对齐" aria-hidden="true">#</a> 按设备对齐</h3><p>select * from root.ln.** where time &lt;= 2017-11-01T00:01:00 align by device;</p><h3 id="设备对齐模式下的排序" tabindex="-1"><a class="header-anchor" href="#设备对齐模式下的排序" aria-hidden="true">#</a> 设备对齐模式下的排序</h3><h4 id="时间对齐模式下的排序" tabindex="-1"><a class="header-anchor" href="#时间对齐模式下的排序" aria-hidden="true">#</a> 时间对齐模式下的排序</h4><p>select * from root.ln.** where time &lt;= 2017-11-01T00:01:00 order by time desc;</p><h4 id="设备对齐模式下的排序-1" tabindex="-1"><a class="header-anchor" href="#设备对齐模式下的排序-1" aria-hidden="true">#</a> 设备对齐模式下的排序</h4><p>select * from root.ln.** where time &lt;= 2017-11-01T00:01:00 order by device desc,time asc align by device;</p><p>在时间戳相等时按照设备名排序</p><p>select * from root.ln.** where time &lt;= 2017-11-01T00:01:00 order by time asc,device desc align by device;</p><p>没有显式指定时</p><p>select * from root.ln.** where time &lt;= 2017-11-01T00:01:00 align by device;</p><p>对聚合后的结果进行排序</p><p>select count(*) from root.ln.** group by ((2017-11-01T00:00:00.000+08:00,2017-11-01T00:03:00.000+08:00],1m) order by device asc,time asc align by device</p><h2 id="_5、查询过滤条件" tabindex="-1"><a class="header-anchor" href="#_5、查询过滤条件" aria-hidden="true">#</a> 5、查询过滤条件</h2><p>选择时间戳大于 2022-01-01T00:05:00.000 的数据:</p><p>select s1 from root.sg1.d1 where time &gt; 2022-01-01T00:05:00.000;</p><p>选择时间戳等于 2022-01-01T00:05:00.000 的数据:</p><p>select s1 from root.sg1.d1 where time = 2022-01-01T00:05:00.000;</p><p>选择时间区间 [2017-11-01T00:05:00.000, 2017-11-01T00:12:00.000) 内的数据:</p><p>select s1 from root.sg1.d1 where time &gt;= 2022-01-01T00:05:00.000 and time &lt; 2017-11-01T00:12:00.000;</p><h3 id="值过滤条件" tabindex="-1"><a class="header-anchor" href="#值过滤条件" aria-hidden="true">#</a> 值过滤条件</h3><p>选择值大于 36.5 的数据:</p><p>select temperature from root.sg1.d1 where temperature &gt; 36.5;</p><p>选择值等于 true 的数据:</p><p>select status from root.sg1.d1 where status = true;</p><p>选择区间 [36.5,40] 内或之外的数据:</p><p>select temperature from root.sg1.d1 where temperature between 36.5 and 40;</p><p>select temperature from root.sg1.d1 where temperature not between 36.5 and 40;</p><p>选择值在特定范围内的数据:</p><p>select code from root.sg1.d1 where code in (&#39;200&#39;, &#39;300&#39;, &#39;400&#39;, &#39;500&#39;);</p><p>选择值在特定范围外的数据:</p><p>select code from root.sg1.d1 where code not in (&#39;200&#39;, &#39;300&#39;, &#39;400&#39;, &#39;500&#39;);</p><p>选择值为空的数据:</p><p>select code from root.sg1.d1 where temperature is null;</p><p>选择值为非空的数据:</p><p>select code from root.sg1.d1 where temperature is not null;</p><h3 id="模糊查询" tabindex="-1"><a class="header-anchor" href="#模糊查询" aria-hidden="true">#</a> 模糊查询</h3><p>查询 <code>root.sg.d1</code> 下 <code>value</code> 含有<code>&#39;cc&#39;</code>的数据</p><p>IoTDB&gt; select * from root.sg.d1 where value like &#39;%cc%&#39;</p><p>查询 <code>root.sg.d1</code> 下 <code>value</code> 中间为 <code>&#39;b&#39;</code>、前后为任意单个字符的数据</p><p>IoTDB&gt; select * from root.sg.device where value like &#39;<em>b</em>&#39;</p><p>查询 root.sg.d1 下 value 值为26个英文字符组成的字符串</p><p>IoTDB&gt; select * from root.sg.d1 where value regexp &#39;<sup class="footnote-ref"><a href="#footnote1">[1]</a><a class="footnote-anchor" id="footnote-ref1"></a></sup>+$&#39;</p><p>查询 root.sg.d1 下 value 值为26个小写英文字符组成的字符串且时间大于100的</p><p>IoTDB&gt; select * from root.sg.d1 where value regexp &#39;<sup class="footnote-ref"><a href="#footnote2">[2]</a><a class="footnote-anchor" id="footnote-ref2"></a></sup>+$&#39; and time &gt; 100</p><h2 id="_6、分段分组聚合" tabindex="-1"><a class="header-anchor" href="#_6、分段分组聚合" aria-hidden="true">#</a> 6、分段分组聚合</h2><h4 id="未指定滑动步长的时间区间分组聚合查询" tabindex="-1"><a class="header-anchor" href="#未指定滑动步长的时间区间分组聚合查询" aria-hidden="true">#</a> 未指定滑动步长的时间区间分组聚合查询</h4><p>select count(status), max_value(temperature) from root.ln.wf01.wt01 group by ([2017-11-01T00:00:00, 2017-11-07T23:00:00),1d);</p><h4 id="指定滑动步长的时间区间分组聚合查询" tabindex="-1"><a class="header-anchor" href="#指定滑动步长的时间区间分组聚合查询" aria-hidden="true">#</a> 指定滑动步长的时间区间分组聚合查询</h4><p>select count(status), max_value(temperature) from root.ln.wf01.wt01 group by ([2017-11-01 00:00:00, 2017-11-07 23:00:00), 3h, 1d);</p><p>滑动步长可以小于聚合窗口</p><p>select count(status), max_value(temperature) from root.ln.wf01.wt01 group by ([2017-11-01 00:00:00, 2017-11-01 10:00:00), 4h, 2h);</p><h4 id="按照自然月份的时间区间分组聚合查询" tabindex="-1"><a class="header-anchor" href="#按照自然月份的时间区间分组聚合查询" aria-hidden="true">#</a> 按照自然月份的时间区间分组聚合查询</h4><p>select count(status) from root.ln.wf01.wt01 where time &gt; 2017-11-01T01:00:00 group by([2017-11-01T00:00:00, 2019-11-07T23:00:00), 1mo, 2mo);</p><p>每个时间间隔窗口内都有数据</p><p>select count(status) from root.ln.wf01.wt01 group by([2017-10-31T00:00:00, 2019-11-07T23:00:00), 1mo, 2mo);</p><h4 id="左开右闭区间" tabindex="-1"><a class="header-anchor" href="#左开右闭区间" aria-hidden="true">#</a> 左开右闭区间</h4><p>select count(status) from root.ln.wf01.wt01 group by ((2017-11-01T00:00:00, 2017-11-07T23:00:00],1d);</p><h4 id="与分组聚合混合使用" tabindex="-1"><a class="header-anchor" href="#与分组聚合混合使用" aria-hidden="true">#</a> 与分组聚合混合使用</h4><p>统计降采样后的数据点个数</p><p>select count(status) from root.ln.wf01.wt01 group by ((2017-11-01T00:00:00, 2017-11-07T23:00:00],1d), level=1;</p><p>加上滑动 Step 的降采样后的结果也可以汇总</p><p>select count(status) from root.ln.wf01.wt01 group by ([2017-11-01 00:00:00, 2017-11-07 23:00:00), 3h, 1d), level=1;</p><h3 id="路径层级分组聚合" tabindex="-1"><a class="header-anchor" href="#路径层级分组聚合" aria-hidden="true">#</a> 路径层级分组聚合</h3><p>统计不同 database 下 status 序列的数据点个数</p><p>select count(status) from root.** group by level = 1</p><p>统计不同设备下 status 序列的数据点个数</p><p>select count(status) from root.** group by level = 3</p><p>统计不同 database 下的不同设备中 status 序列的数据点个数</p><p>select count(status) from root.** group by level = 1, 3</p><p>查询所有序列下温度传感器 temperature 的最大值</p><p>select max_value(temperature) from root.** group by level = 0</p><p>查询某一层级下所有传感器拥有的总数据点数</p><p>select count(*) from root.ln.** group by level = 2</p><h3 id="标签分组聚合" tabindex="-1"><a class="header-anchor" href="#标签分组聚合" aria-hidden="true">#</a> 标签分组聚合</h3><h4 id="单标签聚合查询" tabindex="-1"><a class="header-anchor" href="#单标签聚合查询" aria-hidden="true">#</a> 单标签聚合查询</h4><p>SELECT AVG(temperature) FROM root.factory1.** GROUP BY TAGS(city);</p><h4 id="多标签聚合查询" tabindex="-1"><a class="header-anchor" href="#多标签聚合查询" aria-hidden="true">#</a> 多标签聚合查询</h4><p>SELECT avg(temperature) FROM root.factory1.** GROUP BY TAGS(city, workshop);</p><h4 id="基于时间区间的标签聚合查询" tabindex="-1"><a class="header-anchor" href="#基于时间区间的标签聚合查询" aria-hidden="true">#</a> 基于时间区间的标签聚合查询</h4><p>SELECT AVG(temperature) FROM root.factory1.** GROUP BY ([1000, 10000), 5s), TAGS(city, workshop);</p><h3 id="差值分段聚合" tabindex="-1"><a class="header-anchor" href="#差值分段聚合" aria-hidden="true">#</a> 差值分段聚合</h3><p>group by variation(controlExpression[,delta][,ignoreNull=true/false])</p><h4 id="delta-0时的等值事件分段" tabindex="-1"><a class="header-anchor" href="#delta-0时的等值事件分段" aria-hidden="true">#</a> delta=0时的等值事件分段</h4><p>select __endTime, avg(s1), count(s2), sum(s3) from root.sg.d group by variation(s6)</p><p>指定ignoreNull为false</p><p>select __endTime, avg(s1), count(s2), sum(s3) from root.sg.d group by variation(s6, ignoreNull=false)</p><h4 id="delta-0时的差值事件分段" tabindex="-1"><a class="header-anchor" href="#delta-0时的差值事件分段" aria-hidden="true">#</a> delta!=0时的差值事件分段</h4><p>select __endTime, avg(s1), count(s2), sum(s3) from root.sg.d group by variation(s6, 4)</p><h3 id="条件分段聚合" tabindex="-1"><a class="header-anchor" href="#条件分段聚合" aria-hidden="true">#</a> 条件分段聚合</h3><p>group by condition(predict,[keep&gt;/&gt;=/=/&lt;=/&lt;]threshold,[,ignoreNull=true/false])</p><p>查询至少连续两行以上的charging_status=1的数据</p><p>select max_time(charging_status),count(vehicle_status),last_value(soc) from root.** group by condition(charging_status=1,KEEP&gt;=2,ignoreNull=true)</p><p>当设置<code>ignoreNull</code>为false时,遇到null值为将其视为一个不满足条件的行,得到结果原先的分组被含null的行拆分</p><p>select max_time(charging_status),count(vehicle_status),last_value(soc) from root.** group by condition(charging_status=1,KEEP&gt;=2,ignoreNull=false)</p><h3 id="会话分段聚合" tabindex="-1"><a class="header-anchor" href="#会话分段聚合" aria-hidden="true">#</a> 会话分段聚合</h3><p>group by session(timeInterval)</p><p>按照不同的时间单位设定时间间隔</p><p>select __endTime,count(*) from root.** group by session(1d)</p><p>和<code>HAVING</code>、<code>ALIGN BY DEVICE</code>共同使用</p><p>select __endTime,sum(hardware) from root.ln.wf02.wt01 group by session(50s) having sum(hardware)&gt;0 align by device</p><h2 id="点数分段聚合" tabindex="-1"><a class="header-anchor" href="#点数分段聚合" aria-hidden="true">#</a> 点数分段聚合</h2><p>group by count(controlExpression, size[,ignoreNull=true/false])</p>`,133),k={href:"http://root.sg",target:"_blank",rel:"noopener noreferrer"},v=a("p",null,"当使用ignoreNull将null值也考虑进来",-1),T={href:"http://root.sg",target:"_blank",rel:"noopener noreferrer"},w=n('<h2 id="_7、聚合结果过滤" tabindex="-1"><a class="header-anchor" href="#_7、聚合结果过滤" aria-hidden="true">#</a> 7、聚合结果过滤</h2><p>不正确的:</p><p>select count(s1) from root.** group by ([1,3),1ms) having sum(s1) &gt; s1</p><p>select count(s1) from root.** group by ([1,3),1ms) having s1 &gt; 1</p><p>select count(s1) from root.** group by ([1,3),1ms), level=1 having sum(d1.s1) &gt; 1</p><p>select count(d1.s1) from root.** group by ([1,3),1ms), level=1 having sum(s1) &gt; 1</p><p>SQL 示例:</p><p>select count(s1) from root.** group by ([1,11),2ms), level=1 having count(s2) &gt; 2;</p><p>select count(s1), count(s2) from root.** group by ([1,11),2ms) having count(s2) &gt; 1 align by device;</p><h2 id="_8、结果集补空值" tabindex="-1"><a class="header-anchor" href="#_8、结果集补空值" aria-hidden="true">#</a> 8、结果集补空值</h2><p>FILL &#39;(&#39; PREVIOUS | LINEAR | constant &#39;)&#39;</p><h4 id="previous-填充" tabindex="-1"><a class="header-anchor" href="#previous-填充" aria-hidden="true">#</a> <code>PREVIOUS</code> 填充</h4><p>select temperature, status from root.sgcc.wf03.wt01 where time &gt;= 2017-11-01T16:37:00.000 and time &lt;= 2017-11-01T16:40:00.000 fill(previous);</p><h4 id="linear-填充" tabindex="-1"><a class="header-anchor" href="#linear-填充" aria-hidden="true">#</a> <code>LINEAR</code> 填充</h4><p>select temperature, status from root.sgcc.wf03.wt01 where time &gt;= 2017-11-01T16:37:00.000 and time &lt;= 2017-11-01T16:40:00.000 fill(linear);</p><h4 id="常量填充" tabindex="-1"><a class="header-anchor" href="#常量填充" aria-hidden="true">#</a> 常量填充</h4><p>select temperature, status from root.sgcc.wf03.wt01 where time &gt;= 2017-11-01T16:37:00.000 and time &lt;= 2017-11-01T16:40:00.000 fill(2.0);</p><p>使用 <code>BOOLEAN</code> 类型的常量填充</p><p>select temperature, status from root.sgcc.wf03.wt01 where time &gt;= 2017-11-01T16:37:00.000 and time &lt;= 2017-11-01T16:40:00.000 fill(true);</p><h2 id="_9、查询结果分页" tabindex="-1"><a class="header-anchor" href="#_9、查询结果分页" aria-hidden="true">#</a> 9、查询结果分页</h2><h3 id="按行分页" tabindex="-1"><a class="header-anchor" href="#按行分页" aria-hidden="true">#</a> 按行分页</h3><p>基本的 <code>LIMIT</code> 子句</p><p>select status, temperature from root.ln.wf01.wt01 limit 10</p><p>带 <code>OFFSET</code> 的 <code>LIMIT</code> 子句</p><p>select status, temperature from root.ln.wf01.wt01 limit 5 offset 3</p><p><code>LIMIT</code> 子句与 <code>WHERE</code> 子句结合</p><p>select status,temperature from root.ln.wf01.wt01 where time &gt; 2017-11-01T00:05:00.000 and time&lt; 2017-11-01T00:12:00.000 limit 5 offset 3</p><p><code>LIMIT</code> 子句与 <code>GROUP BY</code> 子句组合</p><p>select count(status), max_value(temperature) from root.ln.wf01.wt01 group by ([2017-11-01T00:00:00, 2017-11-07T23:00:00),1d) limit 4 offset 3</p><h3 id="按列分页" tabindex="-1"><a class="header-anchor" href="#按列分页" aria-hidden="true">#</a> 按列分页</h3><p>基本的 <code>SLIMIT</code> 子句</p><p>select * from root.ln.wf01.wt01 where time &gt; 2017-11-01T00:05:00.000 and time &lt; 2017-11-01T00:12:00.000 slimit 1</p><p>带 <code>SOFFSET</code> 的 <code>SLIMIT</code> 子句</p><p>select * from root.ln.wf01.wt01 where time &gt; 2017-11-01T00:05:00.000 and time &lt; 2017-11-01T00:12:00.000 slimit 1 soffset 1</p><p><code>SLIMIT</code> 子句与 <code>GROUP BY</code> 子句结合</p><p>select max_value(*) from root.ln.wf01.wt01 group by ([2017-11-01T00:00:00, 2017-11-07T23:00:00),1d) slimit 1 soffset 1</p><p><code>SLIMIT</code> 子句与 <code>LIMIT</code> 子句结合</p><p>select * from root.ln.wf01.wt01 limit 10 offset 100 slimit 2 soffset 0</p><h2 id="_10、查询写回-select-into" tabindex="-1"><a class="header-anchor" href="#_10、查询写回-select-into" aria-hidden="true">#</a> 10、查询写回(SELECT INTO)</h2><h4 id="整体描述" tabindex="-1"><a class="header-anchor" href="#整体描述" aria-hidden="true">#</a> 整体描述</h4><p>selectIntoStatement</p><p>​ : SELECT</p><p>​ resultColumn [, resultColumn] ...</p><p>​ INTO intoItem [, intoItem] ...</p><p>​ FROM prefixPath [, prefixPath] ...</p><p>​ [WHERE whereCondition]</p><p>​ [GROUP BY groupByTimeClause, groupByLevelClause]</p><p>​ [FILL {PREVIOUS | LINEAR | constant}]</p><p>​ [LIMIT rowLimit OFFSET rowOffset]</p><p>​ [ALIGN BY DEVICE]</p><p>​ ;</p><p>intoItem</p><p>​ : [ALIGNED] intoDevicePath &#39;(&#39; intoMeasurementName [&#39;,&#39; intoMeasurementName]* &#39;)&#39;</p><p>​ ;</p><p>按时间对齐,将 <code>root.sg</code> database 下四条序列的查询结果写入到 <code>root.sg_copy</code> database 下指定的四条序列中</p><p>IoTDB&gt; select s1, s2 into root.sg_copy.d1(t1), root.sg_copy.d2(t1, t2), root.sg_copy.d1(t2) from root.sg.d1, root.sg.d2;</p><p>按时间对齐,将聚合查询的结果存储到指定序列中</p><p>IoTDB&gt; select count(s1 + s2), last_value(s2) into root.agg.count(s1_add_s2), root.agg.last_value(s2) from root.sg.d1 group by ([0, 100), 10ms);</p><p>按设备对齐</p><p>IoTDB&gt; select s1, s2 into root.sg_copy.d1(t1, t2), root.sg_copy.d2(t1, t2) from root.sg.d1, root.sg.d2 align by device;</p><p>按设备对齐,将表达式计算的结果存储到指定序列中</p><p>IoTDB&gt; select s1 + s2 into root.expr.add(d1s1_d1s2), root.expr.add(d2s1_d2s2) from root.sg.d1, root.sg.d2 align by device;</p><h4 id="使用变量占位符" tabindex="-1"><a class="header-anchor" href="#使用变量占位符" aria-hidden="true">#</a> 使用变量占位符</h4><h5 id="按时间对齐-默认" tabindex="-1"><a class="header-anchor" href="#按时间对齐-默认" aria-hidden="true">#</a> 按时间对齐(默认)</h5><h6 id="_1-目标设备不使用变量占位符-目标物理量列表使用变量占位符" tabindex="-1"><a class="header-anchor" href="#_1-目标设备不使用变量占位符-目标物理量列表使用变量占位符" aria-hidden="true">#</a> (1)目标设备不使用变量占位符 &amp; 目标物理量列表使用变量占位符</h6><p>select s1, s2</p><p>into root.sg_copy.d1(:😃, root.sg_copy.d2(s1), root.sg_copy.d1(${3}), root.sg_copy.d2(:😃</p><p>from root.sg.d1, root.sg.d2;</p><p>该语句等价于:</p><p>select s1, s2</p><p>into root.sg_copy.d1(s1), root.sg_copy.d2(s1), root.sg_copy.d1(s2), root.sg_copy.d2(s2)</p><p>from root.sg.d1, root.sg.d2;</p><h6 id="_2-目标设备使用变量占位符-目标物理量列表不使用变量占位符" tabindex="-1"><a class="header-anchor" href="#_2-目标设备使用变量占位符-目标物理量列表不使用变量占位符" aria-hidden="true">#</a> (2)目标设备使用变量占位符 &amp; 目标物理量列表不使用变量占位符</h6><p>select d1.s1, d1.s2, d2.s3, d3.s4</p><p>into ::(s1_1, s2_2), root.sg.d2_2(s3_3), root.${2}_copy.::(s4)</p>',75),x={href:"http://root.sg",target:"_blank",rel:"noopener noreferrer"},I=a("h6",{id:"_3-目标设备使用变量占位符-目标物理量列表使用变量占位符",tabindex:"-1"},[a("a",{class:"header-anchor",href:"#_3-目标设备使用变量占位符-目标物理量列表使用变量占位符","aria-hidden":"true"},"#"),e(" (3)目标设备使用变量占位符 & 目标物理量列表使用变量占位符")],-1),_={href:"http://root.sg",target:"_blank",rel:"noopener noreferrer"},S=n('<h5 id="按设备对齐-使用-align-by-device" tabindex="-1"><a class="header-anchor" href="#按设备对齐-使用-align-by-device" aria-hidden="true">#</a> 按设备对齐(使用 <code>ALIGN BY DEVICE</code>)</h5><h6 id="_1-目标设备不使用变量占位符-目标物理量列表使用变量占位符-1" tabindex="-1"><a class="header-anchor" href="#_1-目标设备不使用变量占位符-目标物理量列表使用变量占位符-1" aria-hidden="true">#</a> (1)目标设备不使用变量占位符 &amp; 目标物理量列表使用变量占位符</h6><p>select s1, s2, s3, s4</p><p>into root.backup_sg.d1(s1, s2, s3, s4), root.backup_sg.d2(:😃, root.sg.d3(backup_${4})</p><p>from root.sg.d1, root.sg.d2, root.sg.d3</p><p>align by device;</p><h6 id="_2-目标设备使用变量占位符-目标物理量列表不使用变量占位符-1" tabindex="-1"><a class="header-anchor" href="#_2-目标设备使用变量占位符-目标物理量列表不使用变量占位符-1" aria-hidden="true">#</a> (2)目标设备使用变量占位符 &amp; 目标物理量列表不使用变量占位符</h6><p>select avg(s1), sum(s2) + sum(s3), count(s4)</p><p>into root.agg_${2}.::(avg_s1, sum_s2_add_s3, count_s4)</p><p>from root.**</p><p>align by device;</p><h6 id="_3-目标设备使用变量占位符-目标物理量列表使用变量占位符-1" tabindex="-1"><a class="header-anchor" href="#_3-目标设备使用变量占位符-目标物理量列表使用变量占位符-1" aria-hidden="true">#</a> (3)目标设备使用变量占位符 &amp; 目标物理量列表使用变量占位符</h6>',12),R={href:"http://root.sg",target:"_blank",rel:"noopener noreferrer"},q=n(`<h4 id="指定目标序列为对齐序列" tabindex="-1"><a class="header-anchor" href="#指定目标序列为对齐序列" aria-hidden="true">#</a> 指定目标序列为对齐序列</h4><p>select s1, s2 into root.sg_copy.d1(t1, t2), aligned root.sg_copy.d2(t1, t2) from root.sg.d1, root.sg.d2 align by device;</p><h2 id="_11、连续查询-continuous-query-cq" tabindex="-1"><a class="header-anchor" href="#_11、连续查询-continuous-query-cq" aria-hidden="true">#</a> 11、连续查询(Continuous Query, CQ)</h2><h3 id="语法" tabindex="-1"><a class="header-anchor" href="#语法" aria-hidden="true">#</a> 语法</h3><div class="language-Go line-numbers-mode" data-ext="Go"><pre class="language-Go"><code>CREATE (CONTINUOUS QUERY | CQ) &lt;cq_id&gt;
[RESAMPLE
[EVERY &lt;every_interval&gt;]
[BOUNDARY &lt;execution_boundary_time&gt;]
[RANGE &lt;start_time_offset&gt;[, end_time_offset]]
]
[TIMEOUT POLICY BLOCKED|DISCARD]
BEGIN
SELECT CLAUSE
INTO CLAUSE
FROM CLAUSE
[WHERE CLAUSE]
[GROUP BY(&lt;group_by_interval&gt;[, &lt;sliding_step&gt;]) [, level = &lt;level&gt;]]
[HAVING CLAUSE]
[FILL {PREVIOUS | LINEAR | constant}]
[LIMIT rowLimit OFFSET rowOffset]
[ALIGN BY DEVICE]
END
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h4 id="配置连续查询执行的周期性间隔" tabindex="-1"><a class="header-anchor" href="#配置连续查询执行的周期性间隔" aria-hidden="true">#</a> 配置连续查询执行的周期性间隔</h4><p>CREATE CONTINUOUS QUERY cq1</p><p>RESAMPLE EVERY 20s</p><p>BEGIN</p><p>SELECT max_value(temperature)</p><p>INTO root.ln.wf02.wt02(temperature_max), root.ln.wf02.wt01(temperature_max), root.ln.wf01.wt02(temperature_max), root.ln.wf01.wt01(temperature_max)</p><p>FROM root.ln.<em>.</em></p><p>GROUP BY(10s)</p><p>END</p><p>&gt; SELECT temperature_max from root.ln.<em>.</em>;</p><h4 id="配置连续查询的时间窗口大小" tabindex="-1"><a class="header-anchor" href="#配置连续查询的时间窗口大小" aria-hidden="true">#</a> 配置连续查询的时间窗口大小</h4><p>CREATE CONTINUOUS QUERY cq2</p><p>RESAMPLE RANGE 40s</p><p>BEGIN</p><p>SELECT max_value(temperature)</p><p>INTO root.ln.wf02.wt02(temperature_max), root.ln.wf02.wt01(temperature_max), root.ln.wf01.wt02(temperature_max), root.ln.wf01.wt01(temperature_max)</p><p>FROM root.ln.<em>.</em></p><p>GROUP BY(10s)</p><p>END</p><p>&gt; SELECT temperature_max from root.ln.<em>.</em>;</p><h4 id="同时配置连续查询执行的周期性间隔和时间窗口大小" tabindex="-1"><a class="header-anchor" href="#同时配置连续查询执行的周期性间隔和时间窗口大小" aria-hidden="true">#</a> 同时配置连续查询执行的周期性间隔和时间窗口大小</h4><p>CREATE CONTINUOUS QUERY cq3</p><p>RESAMPLE EVERY 20s RANGE 40s</p><p>BEGIN</p><p>SELECT max_value(temperature)</p><p>INTO root.ln.wf02.wt02(temperature_max), root.ln.wf02.wt01(temperature_max), root.ln.wf01.wt02(temperature_max), root.ln.wf01.wt01(temperature_max)</p><p>FROM root.ln.<em>.</em></p><p>GROUP BY(10s)</p><p>FILL(100.0)</p><p>END</p><p>&gt; SELECT temperature_max from root.ln.<em>.</em>;</p><h4 id="配置连续查询每次查询执行时间窗口的结束时间" tabindex="-1"><a class="header-anchor" href="#配置连续查询每次查询执行时间窗口的结束时间" aria-hidden="true">#</a> 配置连续查询每次查询执行时间窗口的结束时间</h4><p>CREATE CONTINUOUS QUERY cq4</p><p>RESAMPLE EVERY 20s RANGE 40s, 20s</p><p>BEGIN</p><p>SELECT max_value(temperature)</p><p>INTO root.ln.wf02.wt02(temperature_max), root.ln.wf02.wt01(temperature_max), root.ln.wf01.wt02(temperature_max), root.ln.wf01.wt01(temperature_max)</p><p>FROM root.ln.<em>.</em></p><p>GROUP BY(10s)</p><p>FILL(100.0)</p><p>END</p><p>&gt; SELECT temperature_max from root.ln.<em>.</em>;</p><h4 id="没有group-by-time子句的连续查询" tabindex="-1"><a class="header-anchor" href="#没有group-by-time子句的连续查询" aria-hidden="true">#</a> 没有GROUP BY TIME子句的连续查询</h4><p>CREATE CONTINUOUS QUERY cq5</p><p>RESAMPLE EVERY 20s</p><p>BEGIN</p><p>SELECT temperature + 1</p><p>INTO root.precalculated_sg.::(temperature)</p><p>FROM root.ln.<em>.</em></p><p>align by device</p><p>END</p><p>&gt; SELECT temperature from root.precalculated_sg.<em>.</em> align by device;</p><h3 id="连续查询的管理" tabindex="-1"><a class="header-anchor" href="#连续查询的管理" aria-hidden="true">#</a> 连续查询的管理</h3><h4 id="查询系统已有的连续查询" tabindex="-1"><a class="header-anchor" href="#查询系统已有的连续查询" aria-hidden="true">#</a> 查询系统已有的连续查询</h4><p>展示集群中所有的已注册的连续查询</p><p>SHOW (CONTINUOUS QUERIES | CQS)</p><p>SHOW CONTINUOUS QUERIES;</p><h4 id="删除已有的连续查询" tabindex="-1"><a class="header-anchor" href="#删除已有的连续查询" aria-hidden="true">#</a> 删除已有的连续查询</h4><p>删除指定的名为cq_id的连续查询:</p><div class="language-Go line-numbers-mode" data-ext="Go"><pre class="language-Go"><code>DROP (CONTINUOUS QUERY | CQ) &lt;cq_id&gt;
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p>DROP CONTINUOUS QUERY s1_count_cq;</p><h4 id="作为子查询的替代品" tabindex="-1"><a class="header-anchor" href="#作为子查询的替代品" aria-hidden="true">#</a> 作为子查询的替代品</h4><p>\\1. 创建一个连续查询</p><p>CREATE CQ s1_count_cq</p><p>BEGIN</p><p>​ SELECT count(s1)</p><p>​ INTO root.sg_count.d.count_s1</p><p>​ FROM root.sg.d</p><p>​ GROUP BY(30m)</p><p>END</p><ol><li>查询连续查询的结果</li></ol><p>SELECT avg(count_s1) from root.sg_count.d;</p><h1 id="运算符和函数" tabindex="-1"><a class="header-anchor" href="#运算符和函数" aria-hidden="true">#</a> 运算符和函数</h1><h2 id="_1、用户自定义函数" tabindex="-1"><a class="header-anchor" href="#_1、用户自定义函数" aria-hidden="true">#</a> 1、用户自定义函数</h2><h5 id="udfparameters" tabindex="-1"><a class="header-anchor" href="#udfparameters" aria-hidden="true">#</a> UDFParameters</h5><p>SELECT UDF(s1, s2, &#39;key1&#39;=&#39;iotdb&#39;, &#39;key2&#39;=&#39;123.45&#39;) FROM root.sg.d;</p><h3 id="udf-注册" tabindex="-1"><a class="header-anchor" href="#udf-注册" aria-hidden="true">#</a> UDF 注册</h3><div class="language-Go line-numbers-mode" data-ext="Go"><pre class="language-Go"><code>CREATE FUNCTION &lt;UDF-NAME&gt; AS &lt;UDF-CLASS-FULL-PATHNAME&gt; (USING URI URI-STRING)?
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><h5 id="不指定uri" tabindex="-1"><a class="header-anchor" href="#不指定uri" aria-hidden="true">#</a> 不指定URI</h5><p>CREATE FUNCTION example AS &#39;org.apache.iotdb.udf.UDTFExample&#39;</p><h5 id="指定uri" tabindex="-1"><a class="header-anchor" href="#指定uri" aria-hidden="true">#</a> 指定URI</h5>`,86),L={href:"http://jar/example.jar",target:"_blank",rel:"noopener noreferrer"},y=n(`<h3 id="udf-卸载" tabindex="-1"><a class="header-anchor" href="#udf-卸载" aria-hidden="true">#</a> UDF 卸载</h3><div class="language-Go line-numbers-mode" data-ext="Go"><pre class="language-Go"><code>DROP FUNCTION &lt;UDF-NAME&gt;
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p>DROP FUNCTION example</p><h3 id="udf-查询" tabindex="-1"><a class="header-anchor" href="#udf-查询" aria-hidden="true">#</a> UDF 查询</h3><h4 id="带自定义输入参数的查询" tabindex="-1"><a class="header-anchor" href="#带自定义输入参数的查询" aria-hidden="true">#</a> 带自定义输入参数的查询</h4><p>SELECT example(s1, &#39;key1&#39;=&#39;value1&#39;, &#39;key2&#39;=&#39;value2&#39;), example(*, &#39;key3&#39;=&#39;value3&#39;) FROM root.sg.d1;</p><p>SELECT example(s1, s2, &#39;key1&#39;=&#39;value1&#39;, &#39;key2&#39;=&#39;value2&#39;) FROM root.sg.d1;</p><h4 id="与其他查询的嵌套查询" tabindex="-1"><a class="header-anchor" href="#与其他查询的嵌套查询" aria-hidden="true">#</a> 与其他查询的嵌套查询</h4><p>SELECT s1, s2, example(s1, s2) FROM root.sg.d1;</p><p>SELECT <em>, example(</em>) FROM root.sg.d1 DISABLE ALIGN;</p><p>SELECT s1 * example(* / s1 + s2) FROM root.sg.d1;</p><p>SELECT s1, s2, s1 + example(s1, s2), s1 - example(s1 + example(s1, s2) / s2) FROM root.sg.d1;</p><h3 id="查看所有注册的-udf" tabindex="-1"><a class="header-anchor" href="#查看所有注册的-udf" aria-hidden="true">#</a> 查看所有注册的 UDF</h3><p>SHOW FUNCTIONS</p><h2 id="_2、聚合函数" tabindex="-1"><a class="header-anchor" href="#_2、聚合函数" aria-hidden="true">#</a> 2、聚合函数</h2><h3 id="count-if" tabindex="-1"><a class="header-anchor" href="#count-if" aria-hidden="true">#</a> COUNT_IF</h3><p>语法</p><p>count_if(predicate, [keep &gt;=/&gt;/=/!=/&lt;/&lt;=]threshold[, &#39;ignoreNull&#39;=&#39;true/false&#39;])</p><h5 id="不使用ignorenull参数-忽略null" tabindex="-1"><a class="header-anchor" href="#不使用ignorenull参数-忽略null" aria-hidden="true">#</a> 不使用ignoreNull参数(忽略null)</h5><p>select count_if(s1=0 &amp; s2=0, 3), count_if(s1=1 &amp; s2=0, 3) from root.db.d1</p><h5 id="使用ignorenull参数" tabindex="-1"><a class="header-anchor" href="#使用ignorenull参数" aria-hidden="true">#</a> 使用ignoreNull参数</h5><p>select count_if(s1=0 &amp; s2=0, 3, &#39;ignoreNull&#39;=&#39;false&#39;), count_if(s1=1 &amp; s2=0, 3, &#39;ignoreNull&#39;=&#39;false&#39;) from root.db.d1</p><h2 id="time-duration" tabindex="-1"><a class="header-anchor" href="#time-duration" aria-hidden="true">#</a> TIME_DURATION</h2><p>语法</p><p>​ time_duration(Path)</p><p>示例</p><p>select time_duration(s1) from root.db.d1</p><h2 id="_3、算数运算符和函数" tabindex="-1"><a class="header-anchor" href="#_3、算数运算符和函数" aria-hidden="true">#</a> 3、算数运算符和函数</h2><h3 id="算数运算符" tabindex="-1"><a class="header-anchor" href="#算数运算符" aria-hidden="true">#</a> 算数运算符</h3><p>select s1, - s1, s2, + s2, s1 + s2, s1 - s2, s1 * s2, s1 / s2, s1 % s2 from root.sg.d1</p><h3 id="数学函数" tabindex="-1"><a class="header-anchor" href="#数学函数" aria-hidden="true">#</a> 数学函数</h3><p>select s1, sin(s1), cos(s1), tan(s1) from root.sg1.d1 limit 5 offset 1000;</p><h4 id="round" tabindex="-1"><a class="header-anchor" href="#round" aria-hidden="true">#</a> ROUND</h4><p>select s4,round(s4),round(s4,2),round(s4,-1) from root.sg1.d1</p><h2 id="_4、比较运算符和函数" tabindex="-1"><a class="header-anchor" href="#_4、比较运算符和函数" aria-hidden="true">#</a> 4、比较运算符和函数</h2><h3 id="基本比较运算符" tabindex="-1"><a class="header-anchor" href="#基本比较运算符" aria-hidden="true">#</a> 基本比较运算符</h3><p>select a, b, a &gt; 10, a &lt;= b, !(a &lt;= b), a &gt; 10 &amp;&amp; a &gt; b from root.test;</p><h3 id="between-and-运算符" tabindex="-1"><a class="header-anchor" href="#between-and-运算符" aria-hidden="true">#</a> <code>BETWEEN ... AND ...</code> 运算符</h3><p>select temperature from root.sg1.d1 where temperature between 36.5 and 40;</p><p>select temperature from root.sg1.d1 where temperature not between 36.5 and 40;</p><h3 id="模糊匹配运算符" tabindex="-1"><a class="header-anchor" href="#模糊匹配运算符" aria-hidden="true">#</a> 模糊匹配运算符</h3><p>查询 <code>root.sg.d1</code> 下 <code>value</code> 含有<code>&#39;cc&#39;</code>的数据</p><p>select * from root.sg.d1 where value like &#39;%cc%&#39;</p><p>查询 <code>root.sg.d1</code> 下 <code>value</code> 中间为 <code>&#39;b&#39;</code>、前后为任意单个字符的数据</p><p>select * from root.sg.device where value like &#39;<em>b</em>&#39;</p><h4 id="使用-regexp-进行模糊匹配" tabindex="-1"><a class="header-anchor" href="#使用-regexp-进行模糊匹配" aria-hidden="true">#</a> 使用 <code>Regexp</code> 进行模糊匹配</h4><p>查询 root.sg.d1 下 value 值为26个英文字符组成的字符串</p><p>select * from root.sg.d1 where value regexp &#39;<sup class="footnote-ref"><a href="#footnote3">[3]</a><a class="footnote-anchor" id="footnote-ref3"></a></sup>+$&#39;</p><p>查询 root.sg.d1 下 value 值为26个小写英文字符组成的字符串且时间大于100的</p><p>select * from root.sg.d1 where value regexp &#39;<sup class="footnote-ref"><a href="#footnote4">[4]</a><a class="footnote-anchor" id="footnote-ref4"></a></sup>+$&#39; and time &gt; 100</p><p>select b, b like &#39;1%&#39;, b regexp &#39;[0-2]&#39; from root.test</p><p><code>IS NULL</code> 运算符</p><p>选择值为空的数据:</p><p>select code from root.sg1.d1 where temperature is null;</p><p>选择值为非空的数据:</p><p>select code from root.sg1.d1 where temperature is not null;</p><p><code>IN</code> 运算符</p><p>选择值在特定范围内的数据:</p><p>select code from root.sg1.d1 where code in (&#39;200&#39;, &#39;300&#39;, &#39;400&#39;, &#39;500&#39;);</p><p>选择值在特定范围外的数据:</p><p>select code from root.sg1.d1 where code not in (&#39;200&#39;, &#39;300&#39;, &#39;400&#39;, &#39;500&#39;);</p><p>select a, a in (1, 2) from root.test;</p><h3 id="条件函数" tabindex="-1"><a class="header-anchor" href="#条件函数" aria-hidden="true">#</a> 条件函数</h3><p>select ts, on_off(ts, &#39;threshold&#39;=&#39;2&#39;) from root.test;</p><p>select ts, in_range(ts, &#39;lower&#39;=&#39;2&#39;, &#39;upper&#39;=&#39;3.1&#39;) from root.test;</p><h2 id="_5、逻辑运算符" tabindex="-1"><a class="header-anchor" href="#_5、逻辑运算符" aria-hidden="true">#</a> 5、逻辑运算符</h2><p>select a, b, a &gt; 10, a &lt;= b, !(a &lt;= b), a &gt; 10 &amp;&amp; a &gt; b from root.test;</p><h2 id="_6、字符串处理" tabindex="-1"><a class="header-anchor" href="#_6、字符串处理" aria-hidden="true">#</a> 6、字符串处理</h2><h3 id="string-contains" tabindex="-1"><a class="header-anchor" href="#string-contains" aria-hidden="true">#</a> STRING_CONTAINS</h3><p>select s1, string_contains(s1, &#39;s&#39;=&#39;warn&#39;) from root.sg1.d4;</p><h3 id="string-matches" tabindex="-1"><a class="header-anchor" href="#string-matches" aria-hidden="true">#</a> STRING_MATCHES</h3><p>select s1, string_matches(s1, &#39;regex&#39;=&#39;[^\\s]+37229&#39;) from root.sg1.d4;</p><h3 id="length" tabindex="-1"><a class="header-anchor" href="#length" aria-hidden="true">#</a> Length</h3><p>select s1, length(s1) from root.sg1.d1</p><h3 id="locate" tabindex="-1"><a class="header-anchor" href="#locate" aria-hidden="true">#</a> Locate</h3><p>select s1, locate(s1, &quot;target&quot;=&quot;1&quot;) from root.sg1.d1</p><p>select s1, locate(s1, &quot;target&quot;=&quot;1&quot;, &quot;reverse&quot;=&quot;true&quot;) from root.sg1.d1</p><h3 id="startswith" tabindex="-1"><a class="header-anchor" href="#startswith" aria-hidden="true">#</a> StartsWith</h3><p>select s1, startswith(s1, &quot;target&quot;=&quot;1&quot;) from root.sg1.d1</p><h3 id="endswith" tabindex="-1"><a class="header-anchor" href="#endswith" aria-hidden="true">#</a> EndsWith</h3><p>select s1, endswith(s1, &quot;target&quot;=&quot;1&quot;) from root.sg1.d1</p><h3 id="concat" tabindex="-1"><a class="header-anchor" href="#concat" aria-hidden="true">#</a> Concat</h3><p>select s1, s2, concat(s1, s2, &quot;target1&quot;=&quot;IoT&quot;, &quot;target2&quot;=&quot;DB&quot;) from root.sg1.d1</p><p>select s1, s2, concat(s1, s2, &quot;target1&quot;=&quot;IoT&quot;, &quot;target2&quot;=&quot;DB&quot;, &quot;series_behind&quot;=&quot;true&quot;) from root.sg1.d1</p><h3 id="substring" tabindex="-1"><a class="header-anchor" href="#substring" aria-hidden="true">#</a> Substring</h3><p>select s1, substring(s1 from 1 for 2) from root.sg1.d1</p><h3 id="replace" tabindex="-1"><a class="header-anchor" href="#replace" aria-hidden="true">#</a> Replace</h3><p>select s1, replace(s1, &#39;es&#39;, &#39;tt&#39;) from root.sg1.d1</p><h3 id="upper" tabindex="-1"><a class="header-anchor" href="#upper" aria-hidden="true">#</a> Upper</h3><p>select s1, upper(s1) from root.sg1.d1</p><h3 id="lower" tabindex="-1"><a class="header-anchor" href="#lower" aria-hidden="true">#</a> Lower</h3><p>select s1, lower(s1) from root.sg1.d1</p><h3 id="trim" tabindex="-1"><a class="header-anchor" href="#trim" aria-hidden="true">#</a> Trim</h3><p>select s3, trim(s3) from root.sg1.d1</p><h3 id="strcmp" tabindex="-1"><a class="header-anchor" href="#strcmp" aria-hidden="true">#</a> StrCmp</h3><p>select s1, s2, strcmp(s1, s2) from root.sg1.d1</p><h3 id="strreplace" tabindex="-1"><a class="header-anchor" href="#strreplace" aria-hidden="true">#</a> StrReplace</h3><p>select strreplace(s1, &quot;target&quot;=&quot;,&quot;, &quot;replace&quot;=&quot;/&quot;, &quot;limit&quot;=&quot;2&quot;) from root.test.d1</p><p>select strreplace(s1, &quot;target&quot;=&quot;,&quot;, &quot;replace&quot;=&quot;/&quot;, &quot;limit&quot;=&quot;1&quot;, &quot;offset&quot;=&quot;1&quot;, &quot;reverse&quot;=&quot;true&quot;) from root.test.d1</p><h3 id="regexmatch" tabindex="-1"><a class="header-anchor" href="#regexmatch" aria-hidden="true">#</a> RegexMatch</h3><p>select regexmatch(s1, &quot;regex&quot;=&quot;\\d+.\\d+.\\d+.\\d+&quot;, &quot;group&quot;=&quot;0&quot;) from root.test.d1</p><h3 id="regexreplace" tabindex="-1"><a class="header-anchor" href="#regexreplace" aria-hidden="true">#</a> RegexReplace</h3><p>select regexreplace(s1, &quot;regex&quot;=&quot;192.168.0.(\\d+)&quot;, &quot;replace&quot;=&quot;cluster-$1&quot;, &quot;limit&quot;=&quot;1&quot;) from root.test.d1</p><h3 id="regexsplit" tabindex="-1"><a class="header-anchor" href="#regexsplit" aria-hidden="true">#</a> RegexSplit</h3><p>select regexsplit(s1, &quot;regex&quot;=&quot;,&quot;, &quot;index&quot;=&quot;-1&quot;) from root.test.d1</p><p>select regexsplit(s1, &quot;regex&quot;=&quot;,&quot;, &quot;index&quot;=&quot;3&quot;) from root.test.d1</p><h2 id="_7、数据类型转换" tabindex="-1"><a class="header-anchor" href="#_7、数据类型转换" aria-hidden="true">#</a> 7、数据类型转换</h2><h3 id="cast" tabindex="-1"><a class="header-anchor" href="#cast" aria-hidden="true">#</a> CAST</h3>`,108),N={href:"http://root.sg",target:"_blank",rel:"noopener noreferrer"},O=n('<h4 id="使用示例" tabindex="-1"><a class="header-anchor" href="#使用示例" aria-hidden="true">#</a> 使用示例</h4><p>cast BOOLEAN to other types</p><p>select cast(s5 as INT32), cast(s5 as INT64),cast(s5 as FLOAT),cast(s5 as DOUBLE), cast(s5 as TEXT) from root.sg.d1</p><p>cast TEXT to numeric types</p><p>select cast(s6 as INT32), cast(s6 as INT64), cast(s6 as FLOAT), cast(s6 as DOUBLE) from root.sg.d1 where time &lt; 2</p><p>cast TEXT to BOOLEAN</p><p>select cast(s6 as BOOLEAN) from root.sg.d1 where time &gt;= 2</p><h2 id="_8、常序列生成函数" tabindex="-1"><a class="header-anchor" href="#_8、常序列生成函数" aria-hidden="true">#</a> 8、常序列生成函数</h2><p>select s1, s2, const(s1, &#39;value&#39;=&#39;1024&#39;, &#39;type&#39;=&#39;INT64&#39;), pi(s2), e(s1, s2) from root.sg1.d1;</p><h2 id="_9、选择函数" tabindex="-1"><a class="header-anchor" href="#_9、选择函数" aria-hidden="true">#</a> 9、选择函数</h2><p>select s1, top_k(s1, &#39;k&#39;=&#39;2&#39;), bottom_k(s1, &#39;k&#39;=&#39;2&#39;) from root.sg1.d2 where time &gt; 2020-12-10T20:36:15.530+08:00;</p><h2 id="_10、区间查询函数" tabindex="-1"><a class="header-anchor" href="#_10、区间查询函数" aria-hidden="true">#</a> 10、区间查询函数</h2><p>select s1, zero_count(s1), non_zero_count(s2), zero_duration(s3), non_zero_duration(s4) from root.sg.d2;</p><h2 id="_11、趋势计算函数" tabindex="-1"><a class="header-anchor" href="#_11、趋势计算函数" aria-hidden="true">#</a> 11、趋势计算函数</h2><p>select s1, time_difference(s1), difference(s1), non_negative_difference(s1), derivative(s1), non_negative_derivative(s1) from root.sg1.d1 limit 5 offset 1000;</p><h5 id="不使用ignorenull参数-忽略null-1" tabindex="-1"><a class="header-anchor" href="#不使用ignorenull参数-忽略null-1" aria-hidden="true">#</a> 不使用ignoreNull参数(忽略null)</h5><p>SELECT DIFF(s1), DIFF(s2) from root.test;</p><h5 id="使用ignorenull参数-1" tabindex="-1"><a class="header-anchor" href="#使用ignorenull参数-1" aria-hidden="true">#</a> 使用ignoreNull参数</h5><p>SELECT DIFF(s1, &#39;ignoreNull&#39;=&#39;false&#39;), DIFF(s2, &#39;ignoreNull&#39;=&#39;false&#39;) from root.test;</p><h2 id="_12、采样函数" tabindex="-1"><a class="header-anchor" href="#_12、采样函数" aria-hidden="true">#</a> 12、采样函数</h2><h3 id="等数量分桶随机采样" tabindex="-1"><a class="header-anchor" href="#等数量分桶随机采样" aria-hidden="true">#</a> 等数量分桶随机采样</h3><p>select equal_size_bucket_random_sample(temperature,&#39;proportion&#39;=&#39;0.1&#39;) as random_sample from root.ln.wf01.wt01;</p><h3 id="等数量分桶聚合采样" tabindex="-1"><a class="header-anchor" href="#等数量分桶聚合采样" aria-hidden="true">#</a> 等数量分桶聚合采样</h3><p>select equal_size_bucket_agg_sample(temperature, &#39;type&#39;=&#39;avg&#39;,&#39;proportion&#39;=&#39;0.1&#39;) as agg_avg, equal_size_bucket_agg_sample(temperature, &#39;type&#39;=&#39;max&#39;,&#39;proportion&#39;=&#39;0.1&#39;) as agg_max, equal_size_bucket_agg_sample(temperature,&#39;type&#39;=&#39;min&#39;,&#39;proportion&#39;=&#39;0.1&#39;) as agg_min, equal_size_bucket_agg_sample(temperature, &#39;type&#39;=&#39;sum&#39;,&#39;proportion&#39;=&#39;0.1&#39;) as agg_sum, equal_size_bucket_agg_sample(temperature, &#39;type&#39;=&#39;extreme&#39;,&#39;proportion&#39;=&#39;0.1&#39;) as agg_extreme, equal_size_bucket_agg_sample(temperature, &#39;type&#39;=&#39;variance&#39;,&#39;proportion&#39;=&#39;0.1&#39;) as agg_variance from root.ln.wf01.wt01;</p><h3 id="等数量分桶-m4-采样" tabindex="-1"><a class="header-anchor" href="#等数量分桶-m4-采样" aria-hidden="true">#</a> 等数量分桶 M4 采样</h3><p>select equal_size_bucket_m4_sample(temperature, &#39;proportion&#39;=&#39;0.1&#39;) as M4_sample from root.ln.wf01.wt01;</p><h3 id="等数量分桶离群值采样" tabindex="-1"><a class="header-anchor" href="#等数量分桶离群值采样" aria-hidden="true">#</a> 等数量分桶离群值采样</h3><p>select equal_size_bucket_outlier_sample(temperature, &#39;proportion&#39;=&#39;0.1&#39;, &#39;type&#39;=&#39;avg&#39;, &#39;number&#39;=&#39;2&#39;) as outlier_avg_sample, equal_size_bucket_outlier_sample(temperature, &#39;proportion&#39;=&#39;0.1&#39;, &#39;type&#39;=&#39;stendis&#39;, &#39;number&#39;=&#39;2&#39;) as outlier_stendis_sample, equal_size_bucket_outlier_sample(temperature, &#39;proportion&#39;=&#39;0.1&#39;, &#39;type&#39;=&#39;cos&#39;, &#39;number&#39;=&#39;2&#39;) as outlier_cos_sample, equal_size_bucket_outlier_sample(temperature, &#39;proportion&#39;=&#39;0.1&#39;, &#39;type&#39;=&#39;prenextdis&#39;, &#39;number&#39;=&#39;2&#39;) as outlier_prenextdis_sample from root.ln.wf01.wt01;</p><h2 id="m4函数" tabindex="-1"><a class="header-anchor" href="#m4函数" aria-hidden="true">#</a> M4函数</h2><p>查询语句1:</p><p>select M4(s1,&#39;timeInterval&#39;=&#39;25&#39;,&#39;displayWindowBegin&#39;=&#39;0&#39;,&#39;displayWindowEnd&#39;=&#39;100&#39;) from root.vehicle.d1</p><p>查询语句2:</p><p>select M4(s1,&#39;windowSize&#39;=&#39;10&#39;) from root.vehicle.d1</p>',33),A={href:"https://grafana.com/docs/grafana/latest/dashboards/variables/add-template-variables/#global-variables",target:"_blank",rel:"noopener noreferrer"},D=n('<p>select M4(s1,&#39;timeInterval&#39;=&#39;$__interval_ms&#39;) from root.sg1.d1</p><h2 id="_13、时间序列处理" tabindex="-1"><a class="header-anchor" href="#_13、时间序列处理" aria-hidden="true">#</a> 13、时间序列处理</h2><h3 id="change-points" tabindex="-1"><a class="header-anchor" href="#change-points" aria-hidden="true">#</a> CHANGE_POINTS</h3><p>select change_points(s1), change_points(s2), change_points(s3), change_points(s4), change_points(s5), change_points(s6) from root.testChangePoints.d1</p><h2 id="_14、lambda-表达式" tabindex="-1"><a class="header-anchor" href="#_14、lambda-表达式" aria-hidden="true">#</a> 14、Lambda 表达式</h2><h3 id="jexl-自定义函数" tabindex="-1"><a class="header-anchor" href="#jexl-自定义函数" aria-hidden="true">#</a> JEXL 自定义函数</h3><p>select jexl(temperature, &#39;expr&#39;=&#39;x -&gt; {x + x}&#39;) as jexl1, jexl(temperature, &#39;expr&#39;=&#39;x -&gt; {x * 3}&#39;) as jexl2, jexl(temperature, &#39;expr&#39;=&#39;x -&gt; {x * x}&#39;) as jexl3, jexl(temperature, &#39;expr&#39;=&#39;x -&gt; {multiply(x, 100)}&#39;) as jexl4, jexl(temperature, st, &#39;expr&#39;=&#39;(x, y) -&gt; {x + y}&#39;) as jexl5, jexl(temperature, st, str, &#39;expr&#39;=&#39;(x, y, z) -&gt; {x + y + z}&#39;) as jexl6 from root.ln.wf01.wt01;</p><h2 id="_15、条件表达式" tabindex="-1"><a class="header-anchor" href="#_15、条件表达式" aria-hidden="true">#</a> 15、条件表达式</h2><h3 id="case" tabindex="-1"><a class="header-anchor" href="#case" aria-hidden="true">#</a> CASE</h3><h4 id="语法示例" tabindex="-1"><a class="header-anchor" href="#语法示例" aria-hidden="true">#</a> 语法示例</h4><ul><li><p>格式1:</p><p>CASE</p></li></ul><p>​ WHEN condition1 THEN expression1</p><p>​ [WHEN condition2 THEN expression2] ...</p><p>​ [ELSE expression_end]</p><p>END</p><ul><li><p>格式2:</p><p>CASE caseValue</p></li></ul><p>​ WHEN whenValue1 THEN expression1</p><p>​ [WHEN whenValue2 THEN expression2] ...</p><p>​ [ELSE expression_end]</p><p>END</p><h5 id="示例1" tabindex="-1"><a class="header-anchor" href="#示例1" aria-hidden="true">#</a> 示例1</h5><p>select T, P, case</p><p>when 1000&lt;T and T&lt;1050 and 1000000&lt;P and P&lt;1100000 then &quot;good!&quot;</p><p>when T&lt;=1000 or T&gt;=1050 then &quot;bad temperature&quot;</p><p>when P&lt;=1000000 or P&gt;=1100000 then &quot;bad pressure&quot;</p><p>end as <code>result</code></p><p>from root.test1</p><h5 id="示例2" tabindex="-1"><a class="header-anchor" href="#示例2" aria-hidden="true">#</a> 示例2</h5><p>select str, case</p><p>when str like &quot;%cc%&quot; then &quot;has cc&quot;</p><p>when str like &quot;%dd%&quot; then &quot;has dd&quot;</p><p>else &quot;no cc and dd&quot; end as <code>result</code></p><p>from root.test2</p><h5 id="示例3-搭配聚合函数" tabindex="-1"><a class="header-anchor" href="#示例3-搭配聚合函数" aria-hidden="true">#</a> 示例3:搭配聚合函数</h5><p>select</p><p>count(case when x&lt;=1 then 1 end) as <code>(-∞,1]</code>,</p><p>count(case when 1&lt;x and x&lt;=3 then 1 end) as <code>(1,3]</code>,</p><p>count(case when 3&lt;x and x&lt;=7 then 1 end) as <code>(3,7]</code>,</p><p>count(case when 7&lt;x then 1 end) as <code>(7,+∞)</code></p><p>from root.test3</p><h6 id="非法-case表达式←聚合函数" tabindex="-1"><a class="header-anchor" href="#非法-case表达式←聚合函数" aria-hidden="true">#</a> 非法:CASE表达式←聚合函数</h6><p>select case when x&lt;=1 then avg(x) else sum(x) end from root.test3</p><h5 id="示例4-格式2" tabindex="-1"><a class="header-anchor" href="#示例4-格式2" aria-hidden="true">#</a> 示例4:格式2</h5><p>select x, case x when 1 then &quot;one&quot; when 2 then &quot;two&quot; else &quot;other&quot; end from root.test4</p><h5 id="示例5-结果子句类型" tabindex="-1"><a class="header-anchor" href="#示例5-结果子句类型" aria-hidden="true">#</a> 示例5:结果子句类型</h5><h6 id="非法-boolean与其它类型共存" tabindex="-1"><a class="header-anchor" href="#非法-boolean与其它类型共存" aria-hidden="true">#</a> 非法:BOOLEAN与其它类型共存</h6><p>select x, case x when 1 then true when 2 then 2 end from root.test4</p><h6 id="合法-只存在boolean类型" tabindex="-1"><a class="header-anchor" href="#合法-只存在boolean类型" aria-hidden="true">#</a> 合法:只存在BOOLEAN类型</h6><p>select x, case x when 1 then true when 2 then false end as <code>result</code> from root.test4</p><h6 id="非法-text与其它类型共存" tabindex="-1"><a class="header-anchor" href="#非法-text与其它类型共存" aria-hidden="true">#</a> 非法:TEXT与其它类型共存</h6><p>select x, case x when 1 then 1 when 2 then &quot;str&quot; end from root.test4</p><h6 id="合法-数值类型共存" tabindex="-1"><a class="header-anchor" href="#合法-数值类型共存" aria-hidden="true">#</a> 合法:数值类型共存</h6><p>select x, case x</p><p>when 1 then 1</p><p>when 2 then 222222222222222</p><p>when 3 then 3.3</p><p>when 4 then 4.4444444444444</p><p>end as <code>result</code></p><p>from root.test4</p><h2 id="_16、数据画像" tabindex="-1"><a class="header-anchor" href="#_16、数据画像" aria-hidden="true">#</a> 16、数据画像</h2><h3 id="acf" tabindex="-1"><a class="header-anchor" href="#acf" aria-hidden="true">#</a> ACF</h3><p>select acf(s1) from root.test.d1 where time &lt;= 2020-01-01 00:00:05</p><h3 id="distinct" tabindex="-1"><a class="header-anchor" href="#distinct" aria-hidden="true">#</a> Distinct</h3><p>select distinct(s2) from root.test.d2</p><h3 id="histogram" tabindex="-1"><a class="header-anchor" href="#histogram" aria-hidden="true">#</a> Histogram</h3><p>select histogram(s1,&quot;min&quot;=&quot;1&quot;,&quot;max&quot;=&quot;20&quot;,&quot;count&quot;=&quot;10&quot;) from root.test.d1</p><h3 id="integral" tabindex="-1"><a class="header-anchor" href="#integral" aria-hidden="true">#</a> Integral</h3><p>select integral(s1) from root.test.d1 where time &lt;= 2020-01-01 00:00:10</p><h4 id="指定时间单位" tabindex="-1"><a class="header-anchor" href="#指定时间单位" aria-hidden="true">#</a> 指定时间单位</h4><p>select integral(s1, &quot;unit&quot;=&quot;1m&quot;) from root.test.d1 where time &lt;= 2020-01-01 00:00:10</p><h3 id="integralavg" tabindex="-1"><a class="header-anchor" href="#integralavg" aria-hidden="true">#</a> IntegralAvg</h3><p>select integralavg(s1) from root.test.d1 where time &lt;= 2020-01-01 00:00:10</p><h3 id="mad" tabindex="-1"><a class="header-anchor" href="#mad" aria-hidden="true">#</a> Mad</h3><p>select mad(s0) from root.test</p><h5 id="近似查询" tabindex="-1"><a class="header-anchor" href="#近似查询" aria-hidden="true">#</a> 近似查询</h5><p>select mad(s0, &quot;error&quot;=&quot;0.01&quot;) from root.test</p><h3 id="median" tabindex="-1"><a class="header-anchor" href="#median" aria-hidden="true">#</a> Median</h3><p>select median(s0, &quot;error&quot;=&quot;0.01&quot;) from root.test</p><h3 id="minmax" tabindex="-1"><a class="header-anchor" href="#minmax" aria-hidden="true">#</a> MinMax</h3><p>select minmax(s1) from root.test</p><h3 id="mode" tabindex="-1"><a class="header-anchor" href="#mode" aria-hidden="true">#</a> Mode</h3><p>select mode(s2) from root.test.d2</p><h3 id="mvavg" tabindex="-1"><a class="header-anchor" href="#mvavg" aria-hidden="true">#</a> MvAvg</h3><p>select mvavg(s1, &quot;window&quot;=&quot;3&quot;) from root.test</p><h3 id="pacf" tabindex="-1"><a class="header-anchor" href="#pacf" aria-hidden="true">#</a> PACF</h3><p>select pacf(s1, &quot;lag&quot;=&quot;5&quot;) from root.test</p><h3 id="percentile" tabindex="-1"><a class="header-anchor" href="#percentile" aria-hidden="true">#</a> Percentile</h3><p>select percentile(s0, &quot;rank&quot;=&quot;0.2&quot;, &quot;error&quot;=&quot;0.01&quot;) from root.test</p><h3 id="quantile" tabindex="-1"><a class="header-anchor" href="#quantile" aria-hidden="true">#</a> Quantile</h3><p>select quantile(s0, &quot;rank&quot;=&quot;0.2&quot;, &quot;K&quot;=&quot;800&quot;) from root.test</p><h3 id="period" tabindex="-1"><a class="header-anchor" href="#period" aria-hidden="true">#</a> Period</h3><p>select period(s1) from root.test.d3</p><h3 id="qlb" tabindex="-1"><a class="header-anchor" href="#qlb" aria-hidden="true">#</a> QLB</h3><p>select QLB(s1) from root.test.d1</p><h3 id="resample" tabindex="-1"><a class="header-anchor" href="#resample" aria-hidden="true">#</a> Resample</h3><h5 id="上采样" tabindex="-1"><a class="header-anchor" href="#上采样" aria-hidden="true">#</a> 上采样</h5><p>select resample(s1,&#39;every&#39;=&#39;5m&#39;,&#39;interp&#39;=&#39;linear&#39;) from root.test.d1</p><h5 id="下采样" tabindex="-1"><a class="header-anchor" href="#下采样" aria-hidden="true">#</a> 下采样</h5><p>select resample(s1,&#39;every&#39;=&#39;30m&#39;,&#39;aggr&#39;=&#39;first&#39;) from root.test.d1</p><h5 id="指定重采样时间段" tabindex="-1"><a class="header-anchor" href="#指定重采样时间段" aria-hidden="true">#</a> 指定重采样时间段</h5><p>select resample(s1,&#39;every&#39;=&#39;30m&#39;,&#39;start&#39;=&#39;2021-03-06 15:00:00&#39;) from root.test.d1</p><h3 id="sample" tabindex="-1"><a class="header-anchor" href="#sample" aria-hidden="true">#</a> Sample</h3><h5 id="蓄水池采样" tabindex="-1"><a class="header-anchor" href="#蓄水池采样" aria-hidden="true">#</a> 蓄水池采样</h5><p>select sample(s1,&#39;method&#39;=&#39;reservoir&#39;,&#39;k&#39;=&#39;5&#39;) from root.test.d1</p><h5 id="等距采样" tabindex="-1"><a class="header-anchor" href="#等距采样" aria-hidden="true">#</a> 等距采样</h5><p>select sample(s1,&#39;method&#39;=&#39;isometric&#39;,&#39;k&#39;=&#39;5&#39;) from root.test.d1</p><h3 id="segment" tabindex="-1"><a class="header-anchor" href="#segment" aria-hidden="true">#</a> Segment</h3><p>select segment(s1,&quot;error&quot;=&quot;0.1&quot;) from root.test</p><h3 id="skew" tabindex="-1"><a class="header-anchor" href="#skew" aria-hidden="true">#</a> Skew</h3><p>select skew(s1) from root.test.d1</p><h3 id="spline" tabindex="-1"><a class="header-anchor" href="#spline" aria-hidden="true">#</a> Spline</h3><p>select spline(s1, &quot;points&quot;=&quot;151&quot;) from root.test</p><h3 id="spread" tabindex="-1"><a class="header-anchor" href="#spread" aria-hidden="true">#</a> Spread</h3><p>select spread(s1) from root.test.d1 where time &lt;= 2020-01-01 00:00:30</p><h3 id="stddev" tabindex="-1"><a class="header-anchor" href="#stddev" aria-hidden="true">#</a> Stddev</h3><p>select stddev(s1) from root.test.d1</p><h3 id="zscore" tabindex="-1"><a class="header-anchor" href="#zscore" aria-hidden="true">#</a> ZScore</h3><p>select zscore(s1) from root.test</p><h2 id="_17、异常检测" tabindex="-1"><a class="header-anchor" href="#_17、异常检测" aria-hidden="true">#</a> 17、异常检测</h2><h3 id="iqr" tabindex="-1"><a class="header-anchor" href="#iqr" aria-hidden="true">#</a> IQR</h3><p>select iqr(s1) from root.test</p><h3 id="ksigma" tabindex="-1"><a class="header-anchor" href="#ksigma" aria-hidden="true">#</a> KSigma</h3><p>select ksigma(s1,&quot;k&quot;=&quot;1.0&quot;) from root.test.d1 where time &lt;= 2020-01-01 00:00:30</p><h3 id="lof" tabindex="-1"><a class="header-anchor" href="#lof" aria-hidden="true">#</a> LOF</h3><p>select lof(s1,s2) from root.test.d1 where time&lt;1000</p><h5 id="诊断一维时间序列" tabindex="-1"><a class="header-anchor" href="#诊断一维时间序列" aria-hidden="true">#</a> 诊断一维时间序列</h5><p>select lof(s1, &quot;method&quot;=&quot;series&quot;) from root.test.d1 where time&lt;1000</p><h3 id="missdetect" tabindex="-1"><a class="header-anchor" href="#missdetect" aria-hidden="true">#</a> MissDetect</h3><p>select missdetect(s2,&#39;minlen&#39;=&#39;10&#39;) from root.test.d2</p><h3 id="range" tabindex="-1"><a class="header-anchor" href="#range" aria-hidden="true">#</a> Range</h3><p>select range(s1,&quot;lower_bound&quot;=&quot;101.0&quot;,&quot;upper_bound&quot;=&quot;125.0&quot;) from root.test.d1 where time &lt;= 2020-01-01 00:00:30</p><h3 id="twosidedfilter" tabindex="-1"><a class="header-anchor" href="#twosidedfilter" aria-hidden="true">#</a> TwoSidedFilter</h3><p>select TwoSidedFilter(s0, &#39;len&#39;=&#39;5&#39;, &#39;threshold&#39;=&#39;0.3&#39;) from root.test</p><h3 id="outlier" tabindex="-1"><a class="header-anchor" href="#outlier" aria-hidden="true">#</a> Outlier</h3><p>select outlier(s1,&quot;r&quot;=&quot;5.0&quot;,&quot;k&quot;=&quot;4&quot;,&quot;w&quot;=&quot;10&quot;,&quot;s&quot;=&quot;5&quot;) from root.test</p><h2 id="_18、数据匹配" tabindex="-1"><a class="header-anchor" href="#_18、数据匹配" aria-hidden="true">#</a> 18、数据匹配</h2><h3 id="cov" tabindex="-1"><a class="header-anchor" href="#cov" aria-hidden="true">#</a> Cov</h3><p>select cov(s1,s2) from root.test.d2</p><h3 id="dtw" tabindex="-1"><a class="header-anchor" href="#dtw" aria-hidden="true">#</a> Dtw</h3><p>select dtw(s1,s2) from root.test.d2</p><h3 id="pearson" tabindex="-1"><a class="header-anchor" href="#pearson" aria-hidden="true">#</a> Pearson</h3><p>select pearson(s1,s2) from root.test.d2</p><h3 id="ptnsym" tabindex="-1"><a class="header-anchor" href="#ptnsym" aria-hidden="true">#</a> PtnSym</h3><p>select ptnsym(s4, &#39;window&#39;=&#39;5&#39;, &#39;threshold&#39;=&#39;0&#39;) from root.test.d1</p><h3 id="xcorr" tabindex="-1"><a class="header-anchor" href="#xcorr" aria-hidden="true">#</a> XCorr</h3><p>select xcorr(s1, s2) from root.test.d1 where time &lt;= 2020-01-01 00:00:05</p><h2 id="_19、频域分析" tabindex="-1"><a class="header-anchor" href="#_19、频域分析" aria-hidden="true">#</a> 19、频域分析</h2><h3 id="conv" tabindex="-1"><a class="header-anchor" href="#conv" aria-hidden="true">#</a> Conv</h3><p>select conv(s1,s2) from root.test.d2</p><h3 id="deconv" tabindex="-1"><a class="header-anchor" href="#deconv" aria-hidden="true">#</a> Deconv</h3><h5 id="计算去卷积的商" tabindex="-1"><a class="header-anchor" href="#计算去卷积的商" aria-hidden="true">#</a> 计算去卷积的商</h5><p>select deconv(s3,s2) from root.test.d2</p><h5 id="计算去卷积的余数" tabindex="-1"><a class="header-anchor" href="#计算去卷积的余数" aria-hidden="true">#</a> 计算去卷积的余数</h5><p>select deconv(s3,s2,&#39;result&#39;=&#39;remainder&#39;) from root.test.d2</p><h3 id="dwt" tabindex="-1"><a class="header-anchor" href="#dwt" aria-hidden="true">#</a> DWT</h3><p>select dwt(s1,&quot;method&quot;=&quot;haar&quot;) from root.test.d1</p><h3 id="fft" tabindex="-1"><a class="header-anchor" href="#fft" aria-hidden="true">#</a> FFT</h3><h5 id="等距傅里叶变换" tabindex="-1"><a class="header-anchor" href="#等距傅里叶变换" aria-hidden="true">#</a> 等距傅里叶变换</h5><p>select fft(s1) from root.test.d1</p><h5 id="等距傅里叶变换并压缩" tabindex="-1"><a class="header-anchor" href="#等距傅里叶变换并压缩" aria-hidden="true">#</a> 等距傅里叶变换并压缩</h5><p>select fft(s1, &#39;result&#39;=&#39;real&#39;, &#39;compress&#39;=&#39;0.99&#39;), fft(s1, &#39;result&#39;=&#39;imag&#39;,&#39;compress&#39;=&#39;0.99&#39;) from root.test.d1</p><h3 id="highpass" tabindex="-1"><a class="header-anchor" href="#highpass" aria-hidden="true">#</a> HighPass</h3><p>select highpass(s1,&#39;wpass&#39;=&#39;0.45&#39;) from root.test.d1</p><h3 id="ifft" tabindex="-1"><a class="header-anchor" href="#ifft" aria-hidden="true">#</a> IFFT</h3><p>select ifft(re, im, &#39;interval&#39;=&#39;1m&#39;, &#39;start&#39;=&#39;2021-01-01 00:00:00&#39;) from root.test.d1</p><h3 id="lowpass" tabindex="-1"><a class="header-anchor" href="#lowpass" aria-hidden="true">#</a> LowPass</h3><p>select lowpass(s1,&#39;wpass&#39;=&#39;0.45&#39;) from root.test.d1</p><h2 id="_20、数据质量" tabindex="-1"><a class="header-anchor" href="#_20、数据质量" aria-hidden="true">#</a> 20、数据质量</h2><h3 id="completeness" tabindex="-1"><a class="header-anchor" href="#completeness" aria-hidden="true">#</a> Completeness</h3><h6 id="参数缺省" tabindex="-1"><a class="header-anchor" href="#参数缺省" aria-hidden="true">#</a> 参数缺省</h6><p>select completeness(s1) from root.test.d1 where time &lt;= 2020-01-01 00:00:30</p><h6 id="指定窗口大小" tabindex="-1"><a class="header-anchor" href="#指定窗口大小" aria-hidden="true">#</a> 指定窗口大小</h6><p>select completeness(s1,&quot;window&quot;=&quot;15&quot;) from root.test.d1 where time &lt;= 2020-01-01 00:01:00</p><h3 id="consistency" tabindex="-1"><a class="header-anchor" href="#consistency" aria-hidden="true">#</a> Consistency</h3><h6 id="参数缺省-1" tabindex="-1"><a class="header-anchor" href="#参数缺省-1" aria-hidden="true">#</a> 参数缺省</h6><p>select consistency(s1) from root.test.d1 where time &lt;= 2020-01-01 00:00:30</p><h6 id="指定窗口大小-1" tabindex="-1"><a class="header-anchor" href="#指定窗口大小-1" aria-hidden="true">#</a> 指定窗口大小</h6><p>select consistency(s1,&quot;window&quot;=&quot;15&quot;) from root.test.d1 where time &lt;= 2020-01-01 00:01:00</p><h3 id="timeliness" tabindex="-1"><a class="header-anchor" href="#timeliness" aria-hidden="true">#</a> Timeliness</h3><h6 id="参数缺省-2" tabindex="-1"><a class="header-anchor" href="#参数缺省-2" aria-hidden="true">#</a> 参数缺省</h6><p>select timeliness(s1) from root.test.d1 where time &lt;= 2020-01-01 00:00:30</p><h6 id="指定窗口大小-2" tabindex="-1"><a class="header-anchor" href="#指定窗口大小-2" aria-hidden="true">#</a> 指定窗口大小</h6><p>select timeliness(s1,&quot;window&quot;=&quot;15&quot;) from root.test.d1 where time &lt;= 2020-01-01 00:01:00</p><h3 id="validity" tabindex="-1"><a class="header-anchor" href="#validity" aria-hidden="true">#</a> Validity</h3><h6 id="参数缺省-3" tabindex="-1"><a class="header-anchor" href="#参数缺省-3" aria-hidden="true">#</a> 参数缺省</h6><p>select validity(s1) from root.test.d1 where time &lt;= 2020-01-01 00:00:30</p><h6 id="指定窗口大小-3" tabindex="-1"><a class="header-anchor" href="#指定窗口大小-3" aria-hidden="true">#</a> 指定窗口大小</h6><p>select validity(s1,&quot;window&quot;=&quot;15&quot;) from root.test.d1 where time &lt;= 2020-01-01 00:01:00</p><h3 id="accuracy" tabindex="-1"><a class="header-anchor" href="#accuracy" aria-hidden="true">#</a> Accuracy</h3><p>select Accuracy(t1,t2,t3,m1,m2,m3) from root.test</p><h2 id="_21、数据修复" tabindex="-1"><a class="header-anchor" href="#_21、数据修复" aria-hidden="true">#</a> 21、数据修复</h2><h3 id="timestamprepair" tabindex="-1"><a class="header-anchor" href="#timestamprepair" aria-hidden="true">#</a> TimestampRepair</h3><h5 id="指定标准时间间隔" tabindex="-1"><a class="header-anchor" href="#指定标准时间间隔" aria-hidden="true">#</a> 指定标准时间间隔</h5><p>select timestamprepair(s1,&#39;interval&#39;=&#39;10000&#39;) from root.test.d2</p><h5 id="自动推算标准时间间隔" tabindex="-1"><a class="header-anchor" href="#自动推算标准时间间隔" aria-hidden="true">#</a> 自动推算标准时间间隔</h5><p>select timestamprepair(s1) from root.test.d2</p><h3 id="valuefill" tabindex="-1"><a class="header-anchor" href="#valuefill" aria-hidden="true">#</a> ValueFill</h3><h5 id="使用-linear-方法进行填补" tabindex="-1"><a class="header-anchor" href="#使用-linear-方法进行填补" aria-hidden="true">#</a> 使用 linear 方法进行填补</h5><p>select valuefill(s1) from root.test.d2</p><h5 id="使用-previous-方法进行填补" tabindex="-1"><a class="header-anchor" href="#使用-previous-方法进行填补" aria-hidden="true">#</a> 使用 previous 方法进行填补</h5><p>select valuefill(s1,&quot;method&quot;=&quot;previous&quot;) from root.test.d2</p><h3 id="valuerepair" tabindex="-1"><a class="header-anchor" href="#valuerepair" aria-hidden="true">#</a> ValueRepair</h3><h5 id="使用-screen-方法进行修复" tabindex="-1"><a class="header-anchor" href="#使用-screen-方法进行修复" aria-hidden="true">#</a> 使用 Screen 方法进行修复</h5><p>select valuerepair(s1) from root.test.d2</p><h5 id="使用-lsgreedy-方法进行修复" tabindex="-1"><a class="header-anchor" href="#使用-lsgreedy-方法进行修复" aria-hidden="true">#</a> 使用 LsGreedy 方法进行修复</h5><p>select valuerepair(s1,&#39;method&#39;=&#39;LsGreedy&#39;) from root.test.d2</p><h3 id="masterrepair" tabindex="-1"><a class="header-anchor" href="#masterrepair" aria-hidden="true">#</a> MasterRepair</h3><p>select MasterRepair(t1,t2,t3,m1,m2,m3) from root.test</p><h3 id="seasonalrepair" tabindex="-1"><a class="header-anchor" href="#seasonalrepair" aria-hidden="true">#</a> SeasonalRepair</h3><h5 id="使用经典分解方法进行修复" tabindex="-1"><a class="header-anchor" href="#使用经典分解方法进行修复" aria-hidden="true">#</a> 使用经典分解方法进行修复</h5><p>select seasonalrepair(s1,&#39;period&#39;=3,&#39;k&#39;=2) from root.test.d2</p><h5 id="使用改进的分解方法进行修复" tabindex="-1"><a class="header-anchor" href="#使用改进的分解方法进行修复" aria-hidden="true">#</a> 使用改进的分解方法进行修复</h5><p>select seasonalrepair(s1,&#39;method&#39;=&#39;improved&#39;,&#39;period&#39;=3) from root.test.d2</p><h2 id="_22、序列发现" tabindex="-1"><a class="header-anchor" href="#_22、序列发现" aria-hidden="true">#</a> 22、序列发现</h2><h3 id="consecutivesequences" tabindex="-1"><a class="header-anchor" href="#consecutivesequences" aria-hidden="true">#</a> ConsecutiveSequences</h3><h5 id="手动指定标准时间间隔" tabindex="-1"><a class="header-anchor" href="#手动指定标准时间间隔" aria-hidden="true">#</a> 手动指定标准时间间隔</h5><p>select consecutivesequences(s1,s2,&#39;gap&#39;=&#39;5m&#39;) from root.test.d1</p><h5 id="自动估计标准时间间隔" tabindex="-1"><a class="header-anchor" href="#自动估计标准时间间隔" aria-hidden="true">#</a> 自动估计标准时间间隔</h5><p>select consecutivesequences(s1,s2) from root.test.d1</p><h3 id="consecutivewindows" tabindex="-1"><a class="header-anchor" href="#consecutivewindows" aria-hidden="true">#</a> ConsecutiveWindows</h3><p>select consecutivewindows(s1,s2,&#39;length&#39;=&#39;10m&#39;) from root.test.d1</p><h2 id="_23、机器学习" tabindex="-1"><a class="header-anchor" href="#_23、机器学习" aria-hidden="true">#</a> 23、机器学习</h2><h3 id="ar" tabindex="-1"><a class="header-anchor" href="#ar" aria-hidden="true">#</a> AR</h3><p>select ar(s0,&quot;p&quot;=&quot;2&quot;) from root.test.d0</p><h3 id="representation" tabindex="-1"><a class="header-anchor" href="#representation" aria-hidden="true">#</a> Representation</h3><p>select representation(s0,&quot;tb&quot;=&quot;3&quot;,&quot;vb&quot;=&quot;2&quot;) from root.test.d0</p><h3 id="rm" tabindex="-1"><a class="header-anchor" href="#rm" aria-hidden="true">#</a> RM</h3><p>select rm(s0, s1,&quot;tb&quot;=&quot;3&quot;,&quot;vb&quot;=&quot;2&quot;) from root.test.d0</p><h1 id="管理触发器" tabindex="-1"><a class="header-anchor" href="#管理触发器" aria-hidden="true">#</a> 管理触发器</h1><h2 id="_1、使用-sql-语句注册该触发器" tabindex="-1"><a class="header-anchor" href="#_1、使用-sql-语句注册该触发器" aria-hidden="true">#</a> 1、使用 SQL 语句注册该触发器</h2><p>// Create Trigger</p><p>createTrigger</p><p>​ : CREATE triggerType TRIGGER triggerName=identifier triggerEventClause ON pathPattern AS className=STRING_LITERAL uriClause? triggerAttributeClause?</p><p>​ ;</p><p>triggerType</p><p>​ : STATELESS | STATEFUL</p><p>​ ;</p><p>triggerEventClause</p><p>​ : (BEFORE | AFTER) INSERT</p><p>​ ;</p><p>uriClause</p><p>​ : USING URI uri</p><p>​ ;</p><p>uri</p><p>​ : STRING_LITERAL</p><p>​ ;</p><p>triggerAttributeClause</p><p>​ : WITH LR_BRACKET triggerAttribute (COMMA triggerAttribute)* RR_BRACKET</p><p>​ ;</p><p>triggerAttribute</p><p>​ : key=attributeKey operator_eq value=attributeValue</p><p>​ ;</p><h3 id="sql-语句示例" tabindex="-1"><a class="header-anchor" href="#sql-语句示例" aria-hidden="true">#</a> SQL 语句示例:</h3><p>CREATE STATELESS TRIGGER triggerTest</p><p>BEFORE INSERT</p>',255),G={href:"http://root.sg",target:"_blank",rel:"noopener noreferrer"},P=a("p",null,"AS 'org.apache.iotdb.trigger.ClusterAlertingExample'",-1),B={href:"http://jar/ClusterAlertingExample.jar",target:"_blank",rel:"noopener noreferrer"},C=n(`<p>WITH (</p><p>​ &quot;name&quot; = &quot;trigger&quot;,</p><p>​ &quot;limit&quot; = &quot;100&quot;</p><p>)</p><h2 id="_2、卸载触发器" tabindex="-1"><a class="header-anchor" href="#_2、卸载触发器" aria-hidden="true">#</a> 2、卸载触发器</h2><h3 id="卸载触发器的-sql-语法如下" tabindex="-1"><a class="header-anchor" href="#卸载触发器的-sql-语法如下" aria-hidden="true">#</a> 卸载触发器的 SQL 语法如下:</h3><p>// Drop Trigger</p><p>dropTrigger</p><p>: DROP TRIGGER triggerName=identifier</p><p>;</p><h3 id="示例语句" tabindex="-1"><a class="header-anchor" href="#示例语句" aria-hidden="true">#</a> 示例语句:</h3><p>DROP TRIGGER triggerTest1</p><h2 id="查询触发器" tabindex="-1"><a class="header-anchor" href="#查询触发器" aria-hidden="true">#</a> 查询触发器</h2><p>SHOW TRIGGERS</p><h1 id="权限管理" tabindex="-1"><a class="header-anchor" href="#权限管理" aria-hidden="true">#</a> 权限管理</h1><h2 id="_1、创建用户" tabindex="-1"><a class="header-anchor" href="#_1、创建用户" aria-hidden="true">#</a> 1、创建用户</h2><p>CREATE USER <code>ln_write_user</code> &#39;write_pwd&#39;</p><p>CREATE USER <code>sgcc_write_user</code> &#39;write_pwd&#39;</p><h2 id="_2、展示用户" tabindex="-1"><a class="header-anchor" href="#_2、展示用户" aria-hidden="true">#</a> 2、展示用户</h2><p>LIST USER</p><h2 id="_3、赋予用户权限" tabindex="-1"><a class="header-anchor" href="#_3、赋予用户权限" aria-hidden="true">#</a> 3、赋予用户权限</h2><p>INSERT INTO root.ln.wf01.wt01(timestamp,status) values(1509465600000,true)</p><p>系统不允许用户进行此操作,会提示错误:</p><p>IoTDB&gt; INSERT INTO root.ln.wf01.wt01(timestamp,status) values(1509465600000,true)</p><p>Msg: 602: No permissions for this operation, please add privilege INSERT_TIMESERIES.</p><p>用root用户分别赋予他们向对应 database 数据的写入权限</p><p>GRANT USER <code>ln_write_user</code> PRIVILEGES INSERT_TIMESERIES on root.ln.**</p><p>GRANT USER <code>sgcc_write_user</code> PRIVILEGES INSERT_TIMESERIES on root.sgcc1.<strong>, root.sgcc2.</strong></p><p>GRANT USER <code>ln_write_user</code> PRIVILEGES CREATE_USER</p><p>使用ln_write_user再尝试写入数据</p><p>IoTDB&gt; INSERT INTO root.ln.wf01.wt01(timestamp, status) values(1509465600000, true)</p><p>Msg: The statement is executed successfully.</p><h2 id="_4、撤销用户权限" tabindex="-1"><a class="header-anchor" href="#_4、撤销用户权限" aria-hidden="true">#</a> 4、撤销用户权限</h2><p>用root用户撤销ln_write_user和sgcc_write_user的权限:</p><p>REVOKE USER <code>ln_write_user</code> PRIVILEGES INSERT_TIMESERIES on root.ln.**</p><p>REVOKE USER <code>sgcc_write_user</code> PRIVILEGES INSERT_TIMESERIES on root.sgcc1.<strong>, root.sgcc2.</strong></p><p>REVOKE USER <code>ln_write_user</code> PRIVILEGES CREATE_USER</p><p>撤销权限后,ln_write_user就没有向root.ln.**写入数据的权限了</p><p>INSERT INTO root.ln.wf01.wt01(timestamp, status) values(1509465600000, true)</p><p>Msg: 602: No permissions for this operation, please add privilege INSERT_TIMESERIES.</p><h3 id="_5、sql-语句" tabindex="-1"><a class="header-anchor" href="#_5、sql-语句" aria-hidden="true">#</a> 5、SQL 语句</h3><ul><li>创建用户</li></ul><div class="language-Go line-numbers-mode" data-ext="Go"><pre class="language-Go"><code>CREATE USER &lt;userName&gt; &lt;password&gt;;
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p>Eg: IoTDB &gt; CREATE USER <code>thulab</code> &#39;passwd&#39;;</p><ul><li>删除用户</li></ul><div class="language-Go line-numbers-mode" data-ext="Go"><pre class="language-Go"><code>DROP USER &lt;userName&gt;;
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p>Eg: IoTDB &gt; DROP USER <code>xiaoming</code>;</p><ul><li>创建角色</li></ul><div class="language-Go line-numbers-mode" data-ext="Go"><pre class="language-Go"><code>CREATE ROLE &lt;roleName&gt;;
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p>Eg: IoTDB &gt; CREATE ROLE <code>admin</code>;</p><ul><li>删除角色</li></ul><div class="language-Go line-numbers-mode" data-ext="Go"><pre class="language-Go"><code>DROP USER &lt;userName&gt;;
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p>Eg: IoTDB &gt; DROP USER <code>xiaoming</code>;</p><ul><li>赋予用户权限</li></ul><div class="language-Go line-numbers-mode" data-ext="Go"><pre class="language-Go"><code>GRANT USER &lt;userName&gt; PRIVILEGES &lt;privileges&gt; ON &lt;nodeNames&gt;;
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p>Eg: IoTDB &gt; GRANT USER <code>tempuser</code> PRIVILEGES INSERT_TIMESERIES, DELETE_TIMESERIES on root.ln.<strong>, root.sgcc.</strong>;</p><p>Eg: IoTDB &gt; GRANT USER <code>tempuser</code> PRIVILEGES CREATE_ROLE;</p><ul><li>赋予用户全部的权限</li></ul><div class="language-Go line-numbers-mode" data-ext="Go"><pre class="language-Go"><code>GRANT USER &lt;userName&gt; PRIVILEGES ALL;
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p>Eg: IoTDB &gt; GRANT USER <code>tempuser</code> PRIVILEGES ALL;</p><ul><li>赋予角色权限</li></ul><div class="language-Go line-numbers-mode" data-ext="Go"><pre class="language-Go"><code>GRANT ROLE &lt;roleName&gt; PRIVILEGES &lt;privileges&gt; ON &lt;nodeNames&gt;;
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p>Eg: IoTDB &gt; GRANT ROLE <code>temprole</code> PRIVILEGES INSERT_TIMESERIES, DELETE_TIMESERIES ON root.sgcc.<strong>, root.ln.</strong>;</p><p>Eg: IoTDB &gt; GRANT ROLE <code>temprole</code> PRIVILEGES CREATE_ROLE;</p><ul><li>赋予角色全部的权限</li></ul><div class="language-Go line-numbers-mode" data-ext="Go"><pre class="language-Go"><code>GRANT ROLE &lt;roleName&gt; PRIVILEGES ALL;
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p>Eg: IoTDB &gt; GRANT ROLE <code>temprole</code> PRIVILEGES ALL;</p><ul><li>赋予用户角色</li></ul><div class="language-Go line-numbers-mode" data-ext="Go"><pre class="language-Go"><code>GRANT &lt;roleName&gt; TO &lt;userName&gt;;
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p>Eg: IoTDB &gt; GRANT <code>temprole</code> TO tempuser;</p><ul><li>撤销用户权限</li></ul><div class="language-Go line-numbers-mode" data-ext="Go"><pre class="language-Go"><code>REVOKE USER &lt;userName&gt; PRIVILEGES &lt;privileges&gt; ON &lt;nodeNames&gt;;
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p>Eg: IoTDB &gt; REVOKE USER <code>tempuser</code> PRIVILEGES DELETE_TIMESERIES on root.ln.**;</p><p>Eg: IoTDB &gt; REVOKE USER <code>tempuser</code> PRIVILEGES CREATE_ROLE;</p><ul><li>移除用户所有权限</li></ul><div class="language-Go line-numbers-mode" data-ext="Go"><pre class="language-Go"><code>REVOKE USER &lt;userName&gt; PRIVILEGES ALL;
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p>Eg: IoTDB &gt; REVOKE USER <code>tempuser</code> PRIVILEGES ALL;</p><ul><li>撤销角色权限</li></ul><div class="language-Go line-numbers-mode" data-ext="Go"><pre class="language-Go"><code>REVOKE ROLE &lt;roleName&gt; PRIVILEGES &lt;privileges&gt; ON &lt;nodeNames&gt;;
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p>Eg: IoTDB &gt; REVOKE ROLE <code>temprole</code> PRIVILEGES DELETE_TIMESERIES ON root.ln.**;</p><p>Eg: IoTDB &gt; REVOKE ROLE <code>temprole</code> PRIVILEGES CREATE_ROLE;</p><ul><li>撤销角色全部的权限</li></ul><div class="language-Go line-numbers-mode" data-ext="Go"><pre class="language-Go"><code>REVOKE ROLE &lt;roleName&gt; PRIVILEGES ALL;
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p>Eg: IoTDB &gt; REVOKE ROLE <code>temprole</code> PRIVILEGES ALL;</p><ul><li>撤销用户角色</li></ul><div class="language-Go line-numbers-mode" data-ext="Go"><pre class="language-Go"><code>REVOKE &lt;roleName&gt; FROM &lt;userName&gt;;
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p>Eg: IoTDB &gt; REVOKE <code>temprole</code> FROM tempuser;</p><ul><li>列出所有用户</li></ul><p>LIST USER</p><p>Eg: IoTDB &gt; LIST USER</p><ul><li>列出指定角色下所有用户</li></ul><div class="language-Go line-numbers-mode" data-ext="Go"><pre class="language-Go"><code>LIST USER OF ROLE &lt;roleName&gt;;
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p>Eg: IoTDB &gt; LIST USER OF ROLE <code>roleuser</code>;</p><ul><li>列出所有角色</li></ul><div class="language-Go line-numbers-mode" data-ext="Go"><pre class="language-Go"><code>REVOKE &lt;roleName&gt; FROM &lt;userName&gt;;
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p>Eg: IoTDB &gt; REVOKE <code>temprole</code> FROM tempuser;</p><ul><li>列出指定用户下所有角色</li></ul><div class="language-Go line-numbers-mode" data-ext="Go"><pre class="language-Go"><code>LIST USER OF ROLE &lt;roleName&gt;;
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p>Eg: IoTDB &gt; LIST USER OF ROLE <code>roleuser</code>;</p><ul><li>列出用户所有权限</li></ul><div class="language-Go line-numbers-mode" data-ext="Go"><pre class="language-Go"><code>LIST PRIVILEGES USER &lt;username&gt;;
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p>Eg: IoTDB &gt; LIST PRIVILEGES USER <code>tempuser</code>;</p><ul><li>列出用户在具体路径上相关联的权限</li></ul><div class="language-Go line-numbers-mode" data-ext="Go"><pre class="language-Go"><code>LIST PRIVILEGES USER &lt;username&gt; ON &lt;paths&gt;;
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p>Eg: IoTDB&gt; LIST PRIVILEGES USER <code>tempuser</code> ON root.ln.<strong>, root.ln.wf01.</strong>;</p><p>IoTDB&gt; LIST PRIVILEGES USER <code>tempuser</code> ON root.ln.wf01.wt01.**;</p><ul><li>列出角色所有权限</li></ul><div class="language-Go line-numbers-mode" data-ext="Go"><pre class="language-Go"><code>LIST PRIVILEGES ROLE &lt;roleName&gt;;
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p>Eg: IoTDB &gt; LIST PRIVILEGES ROLE <code>actor</code>;</p><ul><li>列出角色在具体路径上相关联的权限</li></ul><div class="language-Go line-numbers-mode" data-ext="Go"><pre class="language-Go"><code>LIST PRIVILEGES ROLE &lt;roleName&gt; ON &lt;paths&gt;;
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p>Eg: IoTDB&gt; LIST PRIVILEGES ROLE <code>temprole</code> ON root.ln.<strong>, root.ln.wf01.wt01.</strong>;</p><p>IoTDB&gt; LIST PRIVILEGES ROLE <code>temprole</code> ON root.ln.wf01.wt01.**;</p><ul><li>更新密码</li></ul><div class="language-Go line-numbers-mode" data-ext="Go"><pre class="language-Go"><code>ALTER USER &lt;username&gt; SET PASSWORD &lt;password&gt;;
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p>Eg: IoTDB &gt; ALTER USER <code>tempuser</code> SET PASSWORD &#39;newpwd&#39;;</p><h3 id="_6、非root用户限制进行的操作" tabindex="-1"><a class="header-anchor" href="#_6、非root用户限制进行的操作" aria-hidden="true">#</a> 6、非root用户限制进行的操作</h3><h6 id="tsfile管理" tabindex="-1"><a class="header-anchor" href="#tsfile管理" aria-hidden="true">#</a> TsFile管理</h6><ul><li>加载TsFile</li></ul><p>Eg: IoTDB &gt; load &#39;/Users/Desktop/data/1575028885956-101-0.tsfile&#39;</p><ul><li>删除TsFile文件</li></ul><p>Eg: IoTDB &gt; remove &#39;/Users/Desktop/data/data/root.vehicle/0/0/1575028885956-101-0.tsfile&#39;</p><ul><li>卸载TsFile文件到指定目录</li></ul><p>Eg: IoTDB &gt; unload &#39;/Users/Desktop/data/data/root.vehicle/0/0/1575028885956-101-0.tsfile&#39; &#39;/data/data/tmp&#39;</p><h6 id="删除时间分区-实验性功能" tabindex="-1"><a class="header-anchor" href="#删除时间分区-实验性功能" aria-hidden="true">#</a> 删除时间分区(实验性功能)</h6><ul><li>删除时间分区(实验性功能)</li></ul><p>Eg: IoTDB &gt; DELETE PARTITION root.ln 0,1,2</p><h6 id="连续查询" tabindex="-1"><a class="header-anchor" href="#连续查询" aria-hidden="true">#</a> 连续查询</h6><ul><li>连续查询(CQ)</li></ul><p>Eg: IoTDB &gt; CREATE CONTINUOUS QUERY cq1 BEGIN SELECT max_value(temperature) INTO temperature_max FROM root.ln.<em>.</em> GROUP BY time(10s) END</p><h6 id="运维命令" tabindex="-1"><a class="header-anchor" href="#运维命令" aria-hidden="true">#</a> 运维命令</h6><ul><li>FLUSH</li></ul><p>Eg: IoTDB &gt; flush</p><ul><li>MERGE</li></ul><p>Eg: IoTDB &gt; MERGE</p><p>Eg: IoTDB &gt; FULL MERGE</p><ul><li>CLEAR CACHE</li></ul><p>Eg: IoTDB &gt; CLEAR CACHE</p><ul><li>SET STSTEM TO READONLY / WRITABLE</li></ul><p>Eg: IoTDB &gt; SET STSTEM TO READONLY / WRITABLE</p><ul><li>SCHEMA SNAPSHOT</li></ul><p>Eg: IoTDB &gt; CREATE SNAPSHOT FOR SCHEMA</p><ul><li>查询终止</li></ul><p>Eg: IoTDB &gt; KILL QUERY 1</p><h6 id="水印工具" tabindex="-1"><a class="header-anchor" href="#水印工具" aria-hidden="true">#</a> 水印工具</h6><ul><li>为新用户施加水印</li></ul><p>Eg: IoTDB &gt; grant watermark_embedding to Alice</p><ul><li>撤销水印</li></ul><p>Eg: IoTDB &gt; revoke watermark_embedding from Alice</p><h1 id="运维命令-1" tabindex="-1"><a class="header-anchor" href="#运维命令-1" aria-hidden="true">#</a> 运维命令</h1><h2 id="_1、flush" tabindex="-1"><a class="header-anchor" href="#_1、flush" aria-hidden="true">#</a> 1、FLUSH</h2><p>IoTDB&gt; FLUSH</p><p>IoTDB&gt; FLUSH ON LOCAL</p><p>IoTDB&gt; FLUSH ON CLUSTER</p><p>IoTDB&gt; FLUSH root.ln</p><p>IoTDB&gt; FLUSH root.sg1,root.sg2 ON LOCAL</p><p>IoTDB&gt; FLUSH root.sg1,root.sg2 ON CLUSTER</p><h2 id="_2、clear-cache" tabindex="-1"><a class="header-anchor" href="#_2、clear-cache" aria-hidden="true">#</a> 2、CLEAR CACHE</h2><p>IoTDB&gt; CLEAR CACHE</p><p>IoTDB&gt; CLEAR CACHE ON LOCAL</p><p>IoTDB&gt; CLEAR CACHE ON CLUSTER</p><h2 id="_3、set-system-to-readonly-running" tabindex="-1"><a class="header-anchor" href="#_3、set-system-to-readonly-running" aria-hidden="true">#</a> 3、SET SYSTEM TO READONLY / RUNNING</h2><p>IoTDB&gt; SET SYSTEM TO RUNNING</p><p>IoTDB&gt; SET SYSTEM TO READONLY ON LOCAL</p><p>IoTDB&gt; SET SYSTEM TO READONLY ON CLUSTER</p><h2 id="_4、终止查询" tabindex="-1"><a class="header-anchor" href="#_4、终止查询" aria-hidden="true">#</a> 4、终止查询</h2><h3 id="查询超时" tabindex="-1"><a class="header-anchor" href="#查询超时" aria-hidden="true">#</a> 查询超时</h3><p>IoTDB&gt; select * from root.**;</p><p>Msg: 701 Current query is time out, please check your statement or modify timeout parameter.</p><h3 id="查询终止" tabindex="-1"><a class="header-anchor" href="#查询终止" aria-hidden="true">#</a> 查询终止</h3><h4 id="终止指定查询" tabindex="-1"><a class="header-anchor" href="#终止指定查询" aria-hidden="true">#</a> 终止指定查询</h4><div class="language-Go line-numbers-mode" data-ext="Go"><pre class="language-Go"><code>KILL QUERY &lt;queryId&gt;
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><h5 id="示例" tabindex="-1"><a class="header-anchor" href="#示例" aria-hidden="true">#</a> 示例</h5><p>kill query &#39;20221205_114444_00003_5&#39;</p><h4 id="终止所有查询" tabindex="-1"><a class="header-anchor" href="#终止所有查询" aria-hidden="true">#</a> 终止所有查询</h4><p>KILL ALL QUERIES</p><h2 id="_5、show-queries" tabindex="-1"><a class="header-anchor" href="#_5、show-queries" aria-hidden="true">#</a> 5、SHOW QUERIES</h2><h3 id="语法-1" tabindex="-1"><a class="header-anchor" href="#语法-1" aria-hidden="true">#</a> 语法</h3><p>SHOW QUERIES | (QUERY PROCESSLIST)</p><p>[WHERE whereCondition]</p><p>[ORDER BY sortKey {ASC | DESC}]</p><p>[LIMIT rowLimit] [OFFSET rowOffset]</p><h3 id="sql示例" tabindex="-1"><a class="header-anchor" href="#sql示例" aria-hidden="true">#</a> SQL示例</h3><h4 id="示例1-获取当前所有执行时间大于30s的查询" tabindex="-1"><a class="header-anchor" href="#示例1-获取当前所有执行时间大于30s的查询" aria-hidden="true">#</a> 示例1:获取当前所有执行时间大于30s的查询</h4><p>SHOW QUERIES WHERE ElapsedTime &gt; 30</p><h4 id="示例2-获取当前执行耗时top5的查询" tabindex="-1"><a class="header-anchor" href="#示例2-获取当前执行耗时top5的查询" aria-hidden="true">#</a> 示例2:获取当前执行耗时Top5的查询</h4><p>SHOW QUERIES limit 5</p><p>SHOW QUERIES ORDER BY ElapsedTime DESC limit 5</p><h1 id="tsfile-同步" tabindex="-1"><a class="header-anchor" href="#tsfile-同步" aria-hidden="true">#</a> TsFile 同步</h1><h2 id="快速上手" tabindex="-1"><a class="header-anchor" href="#快速上手" aria-hidden="true">#</a> 快速上手</h2><ul><li>创建接收端为 IoTDB 类型的 Pipe Sink</li></ul><p>IoTDB&gt; CREATE PIPESINK my_iotdb AS IoTDB (ip=&#39;接收端IP&#39;, port=&#39;接收端端口&#39;)</p><ul><li>创建同步任务Pipe(请确保接收端 IoTDB 已经启动)</li></ul><p>IoTDB&gt; CREATE PIPE my_pipe TO my_iotdb</p><ul><li>开始同步任务</li></ul><p>IoTDB&gt; START PIPE my_pipe</p><ul><li>显示所有同步任务状态</li></ul><p>IoTDB&gt; SHOW PIPES</p><ul><li>暂停任务</li></ul><p>IoTDB&gt; STOP PIPE my_pipe</p><ul><li>继续被暂停的任务</li></ul><p>IoTDB&gt; START PIPE my_pipe</p><ul><li>关闭任务(状态信息将被删除)</li></ul><p>IoTDB&gt; DROP PIPE my_pipe</p><h2 id="sql" tabindex="-1"><a class="header-anchor" href="#sql" aria-hidden="true">#</a> SQL</h2><h3 id="show-pipesinktype" tabindex="-1"><a class="header-anchor" href="#show-pipesinktype" aria-hidden="true">#</a> SHOW PIPESINKTYPE</h3><p>IoTDB&gt; SHOW PIPESINKTYPE</p><h3 id="create-pipesink" tabindex="-1"><a class="header-anchor" href="#create-pipesink" aria-hidden="true">#</a> CREATE PIPESINK</h3><div class="language-Go line-numbers-mode" data-ext="Go"><pre class="language-Go"><code>IoTDB&gt; CREATE PIPESINK &lt;PipeSinkName&gt; AS IoTDB [(ip=&#39;127.0.0.1&#39;,port=6667);]
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><h3 id="drop-pipesink" tabindex="-1"><a class="header-anchor" href="#drop-pipesink" aria-hidden="true">#</a> DROP PIPESINK</h3><div class="language-Go line-numbers-mode" data-ext="Go"><pre class="language-Go"><code>IoTDB&gt; DROP PIPESINK &lt;PipeSinkName&gt;
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><h3 id="show-pipesink" tabindex="-1"><a class="header-anchor" href="#show-pipesink" aria-hidden="true">#</a> SHOW PIPESINK</h3><p>IoTDB&gt; SHOW PIPESINKS IoTDB&gt; SHOW PIPESINK [PipeSinkName]</p><h3 id="create-pipe" tabindex="-1"><a class="header-anchor" href="#create-pipe" aria-hidden="true">#</a> CREATE PIPE</h3><p>IoTDB&gt; CREATE PIPE my_pipe TO my_iotdb [FROM (select ** from root WHERE time&gt;=yyyy-mm-dd HH:MM:SS)]</p><h3 id="stop-pipe" tabindex="-1"><a class="header-anchor" href="#stop-pipe" aria-hidden="true">#</a> STOP PIPE</h3><div class="language-Go line-numbers-mode" data-ext="Go"><pre class="language-Go"><code>IoTDB&gt; STOP PIPE &lt;PipeName&gt;
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><h3 id="start-pipe" tabindex="-1"><a class="header-anchor" href="#start-pipe" aria-hidden="true">#</a> START PIPE</h3><div class="language-Go line-numbers-mode" data-ext="Go"><pre class="language-Go"><code>IoTDB&gt; START PIPE &lt;PipeName&gt;
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><h3 id="drop-pipe" tabindex="-1"><a class="header-anchor" href="#drop-pipe" aria-hidden="true">#</a> DROP PIPE</h3><div class="language-Go line-numbers-mode" data-ext="Go"><pre class="language-Go"><code>IoTDB&gt; DROP PIPE &lt;PipeName&gt;
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><h3 id="show-pipe" tabindex="-1"><a class="header-anchor" href="#show-pipe" aria-hidden="true">#</a> SHOW PIPE</h3><p>IoTDB&gt; SHOW PIPES</p><p>IoTDB&gt; SHOW PIPE [PipeName]</p><hr class="footnotes-sep"><section class="footnotes"><ol class="footnotes-list"><li id="footnote1" class="footnote-item"><p>A-Za-z <a href="#footnote-ref1" class="footnote-backref">↩︎</a></p></li><li id="footnote2" class="footnote-item"><p>a-z <a href="#footnote-ref2" class="footnote-backref">↩︎</a></p></li><li id="footnote3" class="footnote-item"><p>A-Za-z <a href="#footnote-ref3" class="footnote-backref">↩︎</a></p></li><li id="footnote4" class="footnote-item"><p>a-z <a href="#footnote-ref4" class="footnote-backref">↩︎</a></p></li></ol></section>`,226);function U(M,F){const s=o("ExternalLinkIcon");return i(),d("div",null,[l,a("p",null,[e("Create template(s1 int, s2 float) on "),a("a",c,[e("root.sg"),t(s)])]),h,a("p",null,[e("select (a + b) * 2 + sin(a) from "),a("a",u,[e("root.sg"),t(s)])]),m,g,f,a("p",null,[e("select (a + b) * 3 from "),a("a",E,[e("root.sg"),t(s)]),e(", root.ln")]),b,a("p",null,[e("select count(charging_stauts), first_value(soc) from "),a("a",k,[e("root.sg"),t(s)]),e(" group by count(charging_status,5)")]),v,a("p",null,[e("select count(charging_stauts), first_value(soc) from "),a("a",T,[e("root.sg"),t(s)]),e(" group by count(charging_status,5,ignoreNull=false)")]),w,a("p",null,[e("from "),a("a",x,[e("root.sg"),t(s)]),e(";")]),I,a("p",null,[e("select * into root.sg_bk.:😦:😃 from "),a("a",_,[e("root.sg"),t(s)]),e(".**;")]),S,a("p",null,[e("select * into ::(backup_${4}) from "),a("a",R,[e("root.sg"),t(s)]),e(".** align by device;")]),q,a("p",null,[e("CREATE FUNCTION example AS 'org.apache.iotdb.udf.UDTFExample' USING URI '"),a("a",L,[e("http://jar/example.jar"),t(s)]),e("'")]),y,a("p",null,[e("SELECT cast(s1 as INT32) from "),a("a",N,[e("root.sg"),t(s)])]),O,a("p",null,[e("使用Grafana的"),a("a",A,[e("模板变量"),t(s)])]),D,a("p",null,[e("ON "),a("a",G,[e("root.sg"),t(s)]),e(".**")]),P,a("p",null,[e("USING URI '"),a("a",B,[e("http://jar/ClusterAlertingExample.jar"),t(s)]),e("'")]),C])}const H=r(p,[["render",U],["__file","SQL-Manual.html.vue"]]);export{H as default};