This is an automated email from the ASF dual-hosted git repository.
leirui pushed a commit to branch rl
in repository https://gitbox.apache.org/repos/asf/iotdb-docs.git
The following commit(s) were added to refs/heads/rl by this push:
new 059074f finish user manual
059074f is described below
commit 059074fe0b1824628b62077b16515cb9af785197
Author: Lei Rui <[email protected]>
AuthorDate: Fri Jul 28 16:13:40 2023 +0800
finish user manual
---
src/UserGuide/Master/User-Manual/Syntax-Rule.md | 399 +++++++++++----------
src/UserGuide/Master/User-Manual/Trigger.md | 243 +++++++------
.../Master/User-Manual/Write-Delete-Data.md | 152 ++++----
3 files changed, 410 insertions(+), 384 deletions(-)
diff --git a/src/UserGuide/Master/User-Manual/Syntax-Rule.md
b/src/UserGuide/Master/User-Manual/Syntax-Rule.md
index 330d9c6..4ee0560 100644
--- a/src/UserGuide/Master/User-Manual/Syntax-Rule.md
+++ b/src/UserGuide/Master/User-Manual/Syntax-Rule.md
@@ -19,99 +19,106 @@
-->
-## 字面值常量
+# Syntax Rule
-该部分对 IoTDB 中支持的字面值常量进行说明,包括字符串常量、数值型常量、时间戳常量、布尔型常量和空值。
+## Literal Values
-### 字符串常量
+This section describes how to write literal values in IoTDB. These include
strings, numbers, timestamp values, boolean values, and NULL.
-在 IoTDB 中,字符串是由**单引号(`'`)或双引号(`"`)字符括起来的字符序列**。示例如下:
+### String Literals
-```Plain%20Text
+in IoTDB, **A string is a sequence of bytes or characters, enclosed within
either single quote (`'`) or double quote (`"`) characters.** Examples:
+
+```js
'a string'
"another string"
```
-#### 使用场景
-
-- `INSERT` 或者 `SELECT` 中用于表达 `TEXT` 类型数据的场景。
-
- ```SQL
- # insert 示例
- insert into root.ln.wf02.wt02(timestamp,hardware) values(1, 'v1')
- insert into root.ln.wf02.wt02(timestamp,hardware) values(2, '\\')
-
- +-----------------------------+--------------------------+
- | Time|root.ln.wf02.wt02.hardware|
- +-----------------------------+--------------------------+
- |1970-01-01T08:00:00.001+08:00| v1|
- +-----------------------------+--------------------------+
- |1970-01-01T08:00:00.002+08:00| \\|
- +-----------------------------+--------------------------+
-
- # select 示例
- select code from root.sg1.d1 where code in ('string1', 'string2');
- ```
-
-- `LOAD` / `REMOVE` / `SETTLE` 指令中的文件路径。
-
- ```SQL
- # load 示例
- LOAD 'examplePath'
-
- # remove 示例
- REMOVE 'examplePath'
-
- # SETTLE 示例
- SETTLE 'examplePath'
- ```
-
-- 用户密码。
-
- ```SQL
- # 示例,write_pwd 即为用户密码
- CREATE USER ln_write_user 'write_pwd'
- ```
-
-- 触发器和 UDF 中的类全类名,示例如下:
-
- ```SQL
- # 触发器示例,AS 后使用字符串表示类全类名
- CREATE TRIGGER `alert-listener-sg1d1s1`
- AFTER INSERT
- ON root.sg1.d1.s1
- AS 'org.apache.iotdb.db.engine.trigger.example.AlertListener'
- WITH (
- 'lo' = '0',
- 'hi' = '100.0'
- )
-
- # UDF 示例,AS 后使用字符串表示类全类名
- CREATE FUNCTION example AS 'org.apache.iotdb.udf.UDTFExample'
- ```
-
-- Select 子句中可以为结果集中的值指定别名,别名可以被定义为字符串或者标识符,示例如下:
-
- ```SQL
- select s1 as 'temperature', s2 as 'speed' from root.ln.wf01.wt01;
-
- # 表头如下所示
- +-----------------------------+-----------|-----+
- | Time|temperature|speed|
- +-----------------------------+-----------|-----+
- ```
-
-- 用于表示键值对,键值对的键和值可以被定义成常量(包括字符串)或者标识符,具体请参考键值对章节。
-
-#### 如何在字符串内使用引号
-
-- 在单引号引起的字符串内,双引号无需特殊处理。同理,在双引号引起的字符串内,单引号无需特殊处理。
-- 在单引号引起的字符串里,可以通过双写单引号来表示一个单引号,即单引号 ' 可以表示为 ''。
-- 在双引号引起的字符串里,可以通过双写双引号来表示一个双引号,即双引号 " 可以表示为 ""。
-
-字符串内使用引号的示例如下:
-
-```Plain%20Text
+#### Usage Scenarios
+
+Usages of string literals:
+
+- Values of `TEXT` type data in `INSERT` or `SELECT` statements
+
+ ```sql
+ # insert
+ insert into root.ln.wf02.wt02(timestamp,hardware) values(1, 'v1')
+ insert into root.ln.wf02.wt02(timestamp,hardware) values(2, '\\')
+
+ +-----------------------------+--------------------------+
+ | Time|root.ln.wf02.wt02.hardware|
+ +-----------------------------+--------------------------+
+ |1970-01-01T08:00:00.001+08:00| v1|
+ +-----------------------------+--------------------------+
+ |1970-01-01T08:00:00.002+08:00| \\|
+ +-----------------------------+--------------------------+
+
+ # select
+ select code from root.sg1.d1 where code in ('string1', 'string2');
+ ```
+
+- Used in`LOAD` / `REMOVE` / `SETTLE` instructions to represent file path.
+
+ ```sql
+ # load
+ LOAD 'examplePath'
+
+ # remove
+ REMOVE 'examplePath'
+
+ # SETTLE
+ SETTLE 'examplePath'
+ ```
+
+- Password fields in user management statements
+
+ ```sql
+ # write_pwd is the password
+ CREATE USER ln_write_user 'write_pwd'
+ ```
+
+- Full Java class names in UDF and trigger management statements
+
+ ```sql
+ # Trigger example. Full java class names after 'AS' should be string
literals.
+ CREATE TRIGGER `alert-listener-sg1d1s1`
+ AFTER INSERT
+ ON root.sg1.d1.s1
+ AS 'org.apache.iotdb.db.engine.trigger.example.AlertListener'
+ WITH (
+ 'lo' = '0',
+ 'hi' = '100.0'
+ )
+
+ # UDF example. Full java class names after 'AS' should be string literals.
+ CREATE FUNCTION example AS 'org.apache.iotdb.udf.UDTFExample'
+ ```
+
+- `AS` function provided by IoTDB can assign an alias to time series selected
in query. Alias can be constant(including string) or identifier.
+
+ ```sql
+ select s1 as 'temperature', s2 as 'speed' from root.ln.wf01.wt01;
+
+ # Header of dataset
+ +-----------------------------+-----------|-----+
+ | Time|temperature|speed|
+ +-----------------------------+-----------|-----+
+ ```
+
+- The key/value of an attribute can be String Literal and identifier, more
details can be found at **key-value pair** part.
+
+
+#### How to use quotation marks in String Literals
+
+There are several ways to include quote characters within a string:
+
+ - `'` inside a string quoted with `"` needs no special treatment and need not
be doubled or escaped. In the same way, `"` inside a string quoted with `'`
needs no special treatment.
+ - A `'` inside a string quoted with `'` may be written as `''`.
+- A `"` inside a string quoted with `"` may be written as `""`.
+
+The following examples demonstrate how quoting and escaping work:
+
+```js
'string' // string
'"string"' // "string"
'""string""' // ""string""
@@ -123,164 +130,162 @@
"""string" // "string
```
-### 数值型常量
-
-数值型常量包括整型和浮点型。
-
-整型常量是一个数字序列。可以以 `+` 或 `-` 开头表示正负。例如:`1`, `-1`。
+### Numeric Literals
-带有小数部分或由科学计数法表示的为浮点型常量,例如:`.1`, `3.14`, `-2.23`, `+1.70`, `1.2E3`, `1.2E-3`,
`-1.2E3`, `-1.2E-3`。
+Number literals include integer (exact-value) literals and floating-point
(approximate-value) literals.
-在 IoTDB 中,`INT32` 和 `INT64` 表示整数类型(计算是准确的),`FLOAT` 和 `DOUBLE` 表示浮点数类型(计算是近似的)。
+Integers are represented as a sequence of digits. Numbers may be preceded by
`-` or `+` to indicate a negative or positive value, respectively. Examples:
`1`, `-1`.
-在浮点上下文中可以使用整数,它会被解释为等效的浮点数。
+Numbers with fractional part or represented in scientific notation with a
mantissa and exponent are approximate-value numbers. Examples: `.1`, `3.14`,
`-2.23`, `+1.70`, `1.2E3`, `1.2E-3`, `-1.2E3`, `-1.2E-3`.
-### 时间戳常量
+The `INT32` and `INT64` data types are integer types and calculations are
exact.
-时间戳是一个数据到来的时间点,在 IoTDB 中分为绝对时间戳和相对时间戳。详细信息可参考
[数据类型文档](https://iotdb.apache.org/zh/UserGuide/Master/Data-Concept/Data-Type.html)。
+The `FLOAT` and `DOUBLE` data types are floating-point types and calculations
are approximate.
-特别地,`NOW()`表示语句开始执行时的服务端系统时间戳。
+An integer may be used in floating-point context; it is interpreted as the
equivalent floating-point number.
-### 布尔型常量
+### Timestamp Literals
-布尔值常量 `TRUE` 和 `FALSE` 分别等价于 `1` 和 `0`,它们对大小写不敏感。
+The timestamp is the time point at which data is produced. It includes
absolute timestamps and relative timestamps in IoTDB. For information about
timestamp support in IoTDB, see [Data Type Doc](../Basic-Concept/Data-Type.md).
-### 空值
+Specially, `NOW()` represents a constant timestamp that indicates the system
time at which the statement began to execute.
-`NULL`值表示没有数据。`NULL`对大小写不敏感。
+### Boolean Literals
-## 标识符
+The constants `TRUE` and `FALSE` evaluate to 1 and 0, respectively. The
constant names can be written in any lettercase.
-### 使用场景
+### NULL Values
-在 IoTDB 中,触发器名称、UDF函数名、元数据模板名称、用户与角色名、连续查询标识、Pipe、PipeSink、键值对中的键和值、别名等可以作为标识符。
+The `NULL` value means “no data.” `NULL` can be written in any lettercase.
-### 约束
+## Identifier
-请注意,此处约束是标识符的通用约束,具体标识符可能还附带其它约束条件,如用户名限制字符数大于等于4,更严格的约束请参考具体标识符相关的说明文档。
+### Usage scenarios
-**标识符命名有以下约束:**
+Certain objects within IoTDB, including `TRIGGER`, `FUNCTION`(UDF),
`CONTINUOUS QUERY`, `SCHEMA TEMPLATE`, `USER`, `ROLE`,`Pipe`,`PipeSink`,`alias`
and other object names are known as identifiers.
-- 不使用反引号括起的标识符中,允许出现以下字符:
- - [ 0-9 a-z A-Z _ ] (字母,数字,下划线)
- - ['\u2E80'..'\u9FFF'] (UNICODE 中文字符)
+### Constraints
-- 标识符允许使用数字开头、不使用反引号括起的标识符不能全部为数字。
+Below are basic constraints of identifiers, specific identifiers may have
other constraints, for example, `user` should consists of more than 4
characters.
-- 标识符是大小写敏感的。
+- Permitted characters in unquoted identifiers:
+ - [0-9 a-z A-Z _ ] (letters, digits and underscore)
+ - ['\u2E80'..'\u9FFF'] (UNICODE Chinese characters)
+- Identifiers may begin with a digit, unquoted identifiers can not be a real
number.
+- Identifiers are case sensitive.
+- Key words can be used as an identifier.
-- 标识符允许为关键字。
+**You need to quote the identifier with back quote(`) in the following cases:**
-**如果出现如下情况,标识符需要使用反引号进行引用:**
+- Identifier contains special characters.
+- Identifier that is a real number.
-- 标识符包含不允许的特殊字符。
-- 标识符为实数。
+### How to use quotations marks in quoted identifiers
-### 如何在反引号引起的标识符中使用引号
+`'` and `"` can be used directly in quoted identifiers.
-**在反引号引起的标识符中可以直接使用单引号和双引号。**
+` may be written as `` in quoted identifiers. See the example below:
-**在用反引号引用的标识符中,可以通过双写反引号的方式使用反引号,即 ` 可以表示为 ``**,示例如下:
-
-```SQL
-# 创建模板 t1`t
-create schema template `t1``t`
+```sql
+# create template t1't"t
+create schema template `t1't"t`
(temperature FLOAT encoding=RLE, status BOOLEAN encoding=PLAIN
compression=SNAPPY)
-# 创建模板 t1't"t
-create schema template `t1't"t`
+# create template t1`t
+create schema template `t1``t`
(temperature FLOAT encoding=RLE, status BOOLEAN encoding=PLAIN
compression=SNAPPY)
```
-### 特殊情况示例
-
-需要使用反引号进行引用的部分情况示例:
-
-- 触发器名称出现上述特殊情况时需使用反引号引用:
-
- ```sql
- # 创建触发器 alert.`listener-sg1d1s1
- CREATE TRIGGER `alert.``listener-sg1d1s1`
- AFTER INSERT
- ON root.sg1.d1.s1
- AS 'org.apache.iotdb.db.engine.trigger.example.AlertListener'
- WITH (
- 'lo' = '0',
- 'hi' = '100.0'
- )
- ```
+### Examples
-- UDF 名称出现上述特殊情况时需使用反引号引用:
+Examples of case in which quoted identifier is used :
- ```sql
- # 创建名为 111 的 UDF,111 为实数,所以需要用反引号引用。
- CREATE FUNCTION `111` AS 'org.apache.iotdb.udf.UDTFExample'
- ```
+- Trigger name should be quoted in cases described above :
-- 元数据模板名称出现上述特殊情况时需使用反引号引用:
+ ```sql
+ # create trigger named alert.`listener-sg1d1s1
+ CREATE TRIGGER `alert.``listener-sg1d1s1`
+ AFTER INSERT
+ ON root.sg1.d1.s1
+ AS 'org.apache.iotdb.db.storageengine.trigger.example.AlertListener'
+ WITH (
+ 'lo' = '0',
+ 'hi' = '100.0'
+ )
+ ```
- ```sql
- # 创建名为 111 的元数据模板,111 为实数,需要用反引号引用。
- create schema template `111`
- (temperature FLOAT encoding=RLE, status BOOLEAN encoding=PLAIN
compression=SNAPPY)
- ```
+- UDF name should be quoted in cases described above :
-- 用户名、角色名出现上述特殊情况时需使用反引号引用,同时无论是否使用反引号引用,用户名、角色名中均不允许出现空格,具体请参考权限管理章节中的说明。
+ ```sql
+ # create a funciton named 111, 111 is a real number.
+ CREATE FUNCTION `111` AS 'org.apache.iotdb.udf.UDTFExample'
+ ```
- ```sql
- # 创建用户 special`user.
- CREATE USER `special``user.` 'write_pwd'
-
- # 创建角色 111
- CREATE ROLE `111`
- ```
+- Template name should be quoted in cases described above :
-- 连续查询标识出现上述特殊情况时需使用反引号引用:
+ ```sql
+ # create a template named 111, 111 is a real number.
+ create schema template `111`
+ (temperature FLOAT encoding=RLE, status BOOLEAN encoding=PLAIN
compression=SNAPPY)
+ ```
- ```sql
- # 创建连续查询 test.cq
- CREATE CONTINUOUS QUERY `test.cq`
- BEGIN
- SELECT max_value(temperature)
- INTO temperature_max
- FROM root.ln.*.*
- GROUP BY time(10s)
- END
- ```
+- User and Role name should be quoted in cases described above, blank space is
not allow in User and Role name whether quoted or not :
-- Pipe、PipeSink 名称出现上述特殊情况时需使用反引号引用:
-
- ```sql
- # 创建 PipeSink test.*1
- CREATE PIPESINK `test.*1` AS IoTDB ('ip' = '输入你的IP')
-
- # 创建 Pipe test.*2
- CREATE PIPE `test.*2` TO `test.*1` FROM
- (select ** from root WHERE time>=yyyy-mm-dd HH:MM:SS) WITH 'SyncDelOp' =
'true'
- ```
+ ```sql
+ # create user special`user.
+ CREATE USER `special``user.` 'write_pwd'
+
+ # create role 111
+ CREATE ROLE `111`
+ ```
+
+- Continuous query name should be quoted in cases described above :
+
+ ```sql
+ # create continuous query test.cq
+ CREATE CONTINUOUS QUERY `test.cq`
+ BEGIN
+ SELECT max_value(temperature)
+ INTO temperature_max
+ FROM root.ln.*.*
+ GROUP BY time(10s)
+ END
+ ```
+
+- Pipe、PipeSink should be quoted in cases described above :
+
+ ```sql
+ # create PipeSink test.*1
+ CREATE PIPESINK `test.*1` AS IoTDB ('ip' = '输入你的IP')
+
+ # create Pipe test.*2
+ CREATE PIPE `test.*2` TO `test.*1` FROM
+ (select ** from root WHERE time>=yyyy-mm-dd HH:MM:SS) WITH 'SyncDelOp' =
'true'
+ ```
-- Select 子句中可以结果集中的值指定别名,别名可以被定义为字符串或者标识符,示例如下:
+- `AS` function provided by IoTDB can assign an alias to time series selected
in query. Alias can be constant(including string) or identifier.
- ```sql
- select s1 as temperature, s2 as speed from root.ln.wf01.wt01;
- # 表头如下所示
- +-----------------------------+-----------+-----+
- | Time|temperature|speed|
- +-----------------------------+-----------+-----+
- ```
+ ```sql
+ select s1 as temperature, s2 as speed from root.ln.wf01.wt01;
+
+ # Header of result dataset
+ +-----------------------------+-----------|-----+
+ | Time|temperature|speed|
+ +-----------------------------+-----------|-----+
+ ```
-- 用于表示键值对,键值对的键和值可以被定义成常量(包括字符串)或者标识符,具体请参考键值对章节。
+- The key/value of an attribute can be String Literal and identifier, more
details can be found at **key-value pair** part.
-## 关键字
+## KeyWords Words
-关键字是在 SQL 具有特定含义的词,可以作为标识符。保留字是关键字的一个子集,保留字不能用于标识符。
+Keywords are words that have significance in SQL. Keywords can be used as an
identifier. Certain keywords, such as TIME/TIMESTAMP and ROOT, are reserved and
cannot use as identifiers.
-关于 IoTDB 的关键字列表,可以查看
[关键字](https://iotdb.apache.org/zh/UserGuide/Master/Reference/Keywords.html) 。
+[Keywords](../Reference/Keywords.md) shows the keywords in IoTDB.
-## 词法与文法详细定义
+## Detailed Definitions of Lexical and Grammar
-请阅读代码仓库中的词法和语法描述文件:
+Please read the lexical and grammar description files in our code repository:
-词法文件:`antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/IoTDBSqlLexer.g4`
+Lexical file:
`antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/IoTDBSqlLexer.g4`
-语法文件:`antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/IoTDBSqlParser.g4`
+Grammer file:
`antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/IoTDBSqlParser.g4`
diff --git a/src/UserGuide/Master/User-Manual/Trigger.md
b/src/UserGuide/Master/User-Manual/Trigger.md
index aacc199..97ade9b 100644
--- a/src/UserGuide/Master/User-Manual/Trigger.md
+++ b/src/UserGuide/Master/User-Manual/Trigger.md
@@ -19,40 +19,41 @@
-->
-# 触发器
+# TRIGGER
-## 使用说明
+## 1. Instructions
-触发器提供了一种侦听序列数据变动的机制。配合用户自定义逻辑,可完成告警、数据转发等功能。
+The trigger provides a mechanism for listening to changes in time series data.
With user-defined logic, tasks such as alerting and data forwarding can be
conducted.
-触发器基于 Java 反射机制实现。用户通过简单实现 Java 接口,即可实现数据侦听。IoTDB
允许用户动态注册、卸载触发器,在注册、卸载期间,无需启停服务器。
+The trigger is implemented based on the reflection mechanism. Users can
monitor data changes by implementing the Java interfaces. IoTDB allows users to
dynamically register and drop triggers without restarting the server.
-### 侦听模式
+The document will help you learn to define and manage triggers.
-IoTDB 的单个触发器可用于侦听符合特定模式的时间序列的数据变动,如时间序列 root.sg.a 上的数据变动,或者符合路径模式 root.**.a
的时间序列上的数据变动。您在注册触发器时可以通过 SQL 语句指定触发器侦听的路径模式。
+### Pattern for Listening
-### 触发器类型
+A single trigger can be used to listen for data changes in a time series that
match a specific pattern. For example, a trigger can listen for the data
changes of time series `root.sg.a`, or time series that match the pattern
`root.sg.*`. When you register a trigger, you can specify the path pattern that
the trigger listens on through an SQL statement.
-目前触发器分为两类,您在注册触发器时可以通过 SQL 语句指定类型:
+### Trigger Type
--
有状态的触发器。该类触发器的执行逻辑可能依赖前后的多条数据,框架会将不同节点写入的数据汇总到同一个触发器实例进行计算,来保留上下文信息,通常用于采样或者统计一段时间的数据聚合信息。集群中只有一个节点持有有状态触发器的实例。
--
无状态的触发器。触发器的执行逻辑只和当前输入的数据有关,框架无需将不同节点的数据汇总到同一个触发器实例中,通常用于单行数据的计算和异常检测等。集群中每个节点均持有无状态触发器的实例。
+There are currently two types of triggers, and you can specify the type
through an SQL statement when registering a trigger:
-### 触发时机
+- Stateful triggers: The execution logic of this type of trigger may depend on
data from multiple insertion statement . The framework will aggregate the data
written by different nodes into the same trigger instance for calculation to
retain context information. This type of trigger is usually used for sampling
or statistical data aggregation for a period of time. information. Only one
node in the cluster holds an instance of a stateful trigger.
+- Stateless triggers: The execution logic of the trigger is only related to
the current input data. The framework does not need to aggregate the data of
different nodes into the same trigger instance. This type of trigger is usually
used for calculation of single row data and abnormal detection. Each node in
the cluster holds an instance of a stateless trigger.
-触发器的触发时机目前有两种,后续会拓展其它触发时机。您在注册触发器时可以通过 SQL 语句指定触发时机:
+### Trigger Event
-- BEFORE INSERT,即在数据持久化之前触发。请注意,目前触发器并不支持数据清洗,不会对要持久化的数据本身进行变动。
-- AFTER INSERT,即在数据持久化之后触发。
+There are currently two trigger events for the trigger, and other trigger
events will be expanded in the future. When you register a trigger, you can
specify the trigger event through an SQL statement:
-## 编写触发器
+- BEFORE INSERT: Fires before the data is persisted. **Please note that
currently the trigger does not support data cleaning and will not change the
data to be persisted itself.**
+- AFTER INSERT: Fires after the data is persisted.
-### 触发器依赖
+## 2. How to Implement a Trigger
-触发器的逻辑需要您编写 Java 类进行实现。
-在编写触发器逻辑时,需要使用到下面展示的依赖。如果您使用 [Maven](http://search.maven.org/),则可以直接从 [Maven
库](http://search.maven.org/)中搜索到它们。请注意选择和目标服务器版本相同的依赖版本。
+You need to implement the trigger by writing a Java class, where the
dependency shown below is required. If you use
[Maven](http://search.maven.org/), you can search for them directly from the
[Maven repository](http://search.maven.org/).
-``` xml
+### Dependency
+
+```xml
<dependency>
<groupId>org.apache.iotdb</groupId>
<artifactId>iotdb-server</artifactId>
@@ -61,9 +62,11 @@ IoTDB 的单个触发器可用于侦听符合特定模式的时间序列的数
</dependency>
```
-### 接口说明
+Note that the dependency version should be correspondent to the target server
version.
+
+### Interface Description
-编写一个触发器需要实现 `org.apache.iotdb.trigger.api.Trigger` 类。
+To implement a trigger, you need to implement the
`org.apache.iotdb.trigger.api.Trigger` class.
```java
import org.apache.iotdb.trigger.api.enums.FailureStrategy;
@@ -126,25 +129,25 @@ public interface Trigger {
}
```
-该类主要提供了两类编程接口:**生命周期相关接口**和**数据变动侦听相关接口**。该类中所有的接口都不是必须实现的,当您不实现它们时,它们不会对流经的数据操作产生任何响应。您可以根据实际需要,只实现其中若干接口。
+This class provides two types of programming interfaces: **Lifecycle related
interfaces** and **data change listening related interfaces**. All the
interfaces in this class are not required to be implemented. When the
interfaces are not implemented, the trigger will not respond to the data
changes. You can implement only some of these interfaces according to your
needs.
-下面是所有可供用户进行实现的接口的说明。
+Descriptions of the interfaces are as followed.
-#### 生命周期相关接口
+#### Lifecycle Related Interfaces
-| 接口定义 | 描述
|
+| Interface | Description
|
| ------------------------------------------------------------ |
------------------------------------------------------------ |
-| *default void validate(TriggerAttributes attributes) throws Exception {}* |
用户在使用 `CREATE TRIGGER` 语句创建触发器时,可以指定触发器需要使用的参数,该接口会用于验证参数正确性。 |
-| *default void onCreate(TriggerAttributes attributes) throws Exception {}* |
当您使用`CREATE
TRIGGER`语句创建触发器后,该接口会被调用一次。在每一个触发器实例的生命周期内,该接口会且仅会被调用一次。该接口主要有如下作用:帮助用户解析 SQL
语句中的自定义属性(使用`TriggerAttributes`)。 可以创建或申请资源,如建立外部链接、打开文件等。 |
-| *default void onDrop() throws Exception {}* | 当您使用`DROP
TRIGGER`语句删除触发器后,该接口会被调用。在每一个触发器实例的生命周期内,该接口会且仅会被调用一次。该接口主要有如下作用:可以进行资源释放的操作。可以用于持久化触发器计算的结果。
|
-| *default void restore() throws Exception {}* | 当重启 DataNode
时,集群会恢复 DataNode 上已经注册的触发器实例,在此过程中会为该 DataNode 上的有状态触发器调用一次该接口。有状态触发器实例所在的
DataNode 宕机后,集群会在另一个可用 DataNode 上恢复该触发器的实例,在此过程中会调用一次该接口。该接口可以用于自定义恢复逻辑。 |
+| *default void validate(TriggerAttributes attributes) throws Exception {}* |
When you creates a trigger using the `CREATE TRIGGER` statement, you can
specify the parameters that the trigger needs to use, and this interface will
be used to verify the correctness of the parameters。 |
+| *default void onCreate(TriggerAttributes attributes) throws Exception {}* |
This interface is called once when you create a trigger using the `CREATE
TRIGGER` statement. During the lifetime of each trigger instance, this
interface will be called only once. This interface is mainly used for the
following functions: helping users to parse custom attributes in SQL statements
(using `TriggerAttributes`). You can create or apply for resources, such as
establishing external links, opening fi [...]
+| *default void onDrop() throws Exception {}* | This
interface is called when you drop a trigger using the `DROP TRIGGER` statement.
During the lifetime of each trigger instance, this interface will be called
only once. This interface mainly has the following functions: it can perform
the operation of resource release and can be used to persist the results of
trigger calculations. |
+| *default void restore() throws Exception {}* | When the
DataNode is restarted, the cluster will restore the trigger instance registered
on the DataNode, and this interface will be called once for stateful trigger
during the process. After the DataNode where the stateful trigger instance is
located goes down, the cluster will restore the trigger instance on another
available DataNode, calling this interface once in the process. This interface
can be used to customize rec [...]
-#### 数据变动侦听相关接口
+#### Data Change Listening Related Interfaces
-##### 侦听接口
+##### Listening Interface
```java
- /**
+/**
* @param tablet see {@link Tablet} for detailed information of data
structure. Data that is
* inserted will be constructed as a Tablet and you can define process
logic with {@link
* Tablet}.
@@ -156,45 +159,45 @@ public interface Trigger {
}
```
-数据变动时,触发器以 Tablet 作为触发操作的单位。您可以通过 Tablet 获取相应序列的元数据和数据,然后进行相应的触发操作,触发成功则返回值应当为
true。该接口返回 false 或是抛出异常我们均认为触发失败。在触发失败时,我们会根据侦听策略接口进行相应的操作。
+When the data changes, the trigger uses the Tablet as the unit of firing
operation. You can obtain the metadata and data of the corresponding sequence
through Tablet, and then perform the corresponding trigger operation. If the
fire process is successful, the return value should be true. If the interface
returns false or throws an exception, we consider the trigger fire process as
failed. When the trigger fire process fails, we will perform corresponding
operations according to the liste [...]
-进行一次 INSERT
操作时,对于其中的每条时间序列,我们会检测是否有侦听该路径模式的触发器,然后将符合同一个触发器所侦听的路径模式的时间序列数据组装成一个新的 Tablet
用于触发器的 fire 接口。可以理解成:
+When performing an INSERT operation, for each time series in it, we will
detect whether there is a trigger that listens to the path pattern, and then
assemble the time series data that matches the path pattern listened by the
same trigger into a new Tablet for trigger fire interface. Can be understood as:
```java
Map<PartialPath, List<Trigger>> pathToTriggerListMap => Map<Trigger, Tablet>
```
-**请注意,目前我们不对触发器的触发顺序有任何保证。**
+**Note that currently we do not make any guarantees about the order in which
triggers fire.**
-下面是示例:
+Here is an example:
-假设有三个触发器,触发器的触发时机均为 BEFORE INSERT
+Suppose there are three triggers, and the trigger event of the triggers are
all BEFORE INSERT:
-- 触发器 Trigger1 侦听路径模式:root.sg.*
-- 触发器 Trigger2 侦听路径模式:root.sg.a
-- 触发器 Trigger3 侦听路径模式:root.sg.b
+- Trigger1 listens on `root.sg.*`
+- Trigger2 listens on `root.sg.a`
+- Trigger3 listens on `root.sg.b`
-写入语句:
+Insertion statement:
```sql
insert into root.sg(time, a, b) values (1, 1, 1);
```
-序列 root.sg.a 匹配 Trigger1 和 Trigger2,序列 root.sg.b 匹配 Trigger1 和 Trigger3,那么:
+The time series `root.sg.a` matches Trigger1 and Trigger2, and the sequence
`root.sg.b` matches Trigger1 and Trigger3, then:
-- root.sg.a 和 root.sg.b 的数据会被组装成一个新的 tablet1,在相应的触发时机进行 Trigger1.fire(tablet1)
-- root.sg.a 的数据会被组装成一个新的 tablet2,在相应的触发时机进行 Trigger2.fire(tablet2)
-- root.sg.b 的数据会被组装成一个新的 tablet3,在相应的触发时机进行 Trigger3.fire(tablet3)
+- The data of `root.sg.a` and `root.sg.b` will be assembled into a new
tablet1, and Trigger1.fire(tablet1) will be executed at the corresponding
Trigger Event.
+- The data of `root.sg.a` will be assembled into a new tablet2, and
Trigger2.fire(tablet2) will be executed at the corresponding Trigger Event.
+- The data of `root.sg.b` will be assembled into a new tablet3, and
Trigger3.fire(tablet3) will be executed at the corresponding Trigger Event.
-##### 侦听策略接口
+##### Listening Strategy Interface
-在触发器触发失败时,我们会根据侦听策略接口设置的策略进行相应的操作,您可以通过下述接口设置
`org.apache.iotdb.trigger.api.enums.FailureStrategy`,目前有乐观和悲观两种策略:
+When the trigger fails to fire, we will take corresponding actions according
to the strategy set by the listening strategy interface. You can set
`org.apache.iotdb.trigger.api.enums.FailureStrategy`. There are currently two
strategies, optimistic and pessimistic:
--
乐观策略:触发失败的触发器不影响后续触发器的触发,也不影响写入流程,即我们不对触发失败涉及的序列做额外处理,仅打日志记录失败,最后返回用户写入数据成功,但触发部分失败。
-- 悲观策略:失败触发器影响后续所有 Pipeline 的处理,即我们认为该 Trigger
触发失败会导致后续所有触发流程不再进行。如果该触发器的触发时机为 BEFORE INSERT,那么写入也不再进行,直接返回写入失败。
+- Optimistic strategy: The trigger that fails to fire does not affect the
firing of subsequent triggers, nor does it affect the writing process, that is,
we do not perform additional processing on the sequence involved in the trigger
failure, only log the failure to record the failure, and finally inform user
that data insertion is successful, but the trigger fire part failed.
+- Pessimistic strategy: The failure trigger affects the processing of all
subsequent Pipelines, that is, we believe that the firing failure of the
trigger will cause all subsequent triggering processes to no longer be carried
out. If the trigger event of the trigger is BEFORE INSERT, then the insertion
will no longer be performed, and the insertion failure will be returned
directly.
```java
- /**
+ /**
* Overrides this method to set the expected FailureStrategy, {@link
FailureStrategy#OPTIMISTIC}
* is the default strategy.
*
@@ -205,18 +208,13 @@ insert into root.sg(time, a, b) values (1, 1, 1);
}
```
-您可以参考下图辅助理解,其中 Trigger1 配置采用乐观策略,Trigger2 配置采用悲观策略。Trigger1 和 Trigger2 的触发时机是
BEFORE INSERT,Trigger3 和 Trigger4 的触发时机是 AFTER INSERT。 正常执行流程如下:
-
-<img
src="https://alioss.timecho.com/docs/img/UserGuide/Process-Data/Triggers/Trigger_Process_Flow.jpg?raw=true">
-
-<img
src="https://alioss.timecho.com/docs/img/UserGuide/Process-Data/Triggers/Trigger_Process_Strategy.jpg?raw=true">
+### Example
+If you use [Maven](http://search.maven.org/), you can refer to our sample
project **trigger-example**.
-### 示例
+You can find it
[here](https://github.com/apache/iotdb/tree/master/example/trigger).
-如果您使用 [Maven](http://search.maven.org/),可以参考我们编写的示例项目 trigger-example。您可以在
[这里](https://github.com/apache/iotdb/tree/master/example/trigger)
找到它。后续我们会加入更多的示例项目供您参考。
-
-下面是其中一个示例项目的代码:
+Here is the code from one of the sample projects:
```java
/*
@@ -240,9 +238,9 @@ insert into root.sg(time, a, b) values (1, 1, 1);
package org.apache.iotdb.trigger;
-import
org.apache.iotdb.db.engine.trigger.sink.alertmanager.AlertManagerConfiguration;
-import org.apache.iotdb.db.engine.trigger.sink.alertmanager.AlertManagerEvent;
-import
org.apache.iotdb.db.engine.trigger.sink.alertmanager.AlertManagerHandler;
+import
org.apache.iotdb.db.storageengine.trigger.sink.alertmanager.AlertManagerConfiguration;
+import
org.apache.iotdb.db.storageengine.trigger.sink.alertmanager.AlertManagerEvent;
+import
org.apache.iotdb.db.storageengine.trigger.sink.alertmanager.AlertManagerHandler;
import org.apache.iotdb.trigger.api.Trigger;
import org.apache.iotdb.trigger.api.TriggerAttributes;
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
@@ -319,23 +317,24 @@ public class ClusterAlertingExample implements Trigger {
}
}
```
-## 管理触发器
-您可以通过 SQL 语句注册和卸载一个触发器实例,您也可以通过 SQL 语句查询到所有已经注册的触发器。
+## 3. Trigger Management
+
+You can create and drop a trigger through an SQL statement, and you can also
query all registered triggers through an SQL statement.
-**我们建议您在注册触发器时停止写入。**
+**We recommend that you stop insertion while creating triggers.**
-### 注册触发器
+### Create Trigger
-触发器可以注册在任意路径模式上。被注册有触发器的序列将会被触发器侦听,当序列上有数据变动时,触发器中对应的触发方法将会被调用。
+Triggers can be registered on arbitrary path patterns. The time series
registered with the trigger will be listened to by the trigger. When there is
data change on the series, the corresponding fire method in the trigger will be
called.
-注册一个触发器可以按如下流程进行:
+Registering a trigger can be done as follows:
-1. 按照编写触发器章节的说明,实现一个完整的 Trigger 类,假定这个类的全类名为
`org.apache.iotdb.trigger.ClusterAlertingExample`
-2. 将项目打成 JAR 包。
-3. 使用 SQL 语句注册该触发器。注册过程中会仅只会调用一次触发器的 `validate` 和 `onCreate` 接口,具体请参考编写触发器章节。
+1. Implement a Trigger class as described in the How to implement a Trigger
chapter, assuming the class's full class name is
`org.apache.iotdb.trigger.ClusterAlertingExample`
+2. Package the project into a JAR package.
+3. Register the trigger with an SQL statement. During the creation process,
the `validate` and `onCreate` interfaces of the trigger will only be called
once. For details, please refer to the chapter of How to implement a Trigger.
-完整 SQL 语法如下:
+The complete SQL syntax is as follows:
```sql
// Create Trigger
@@ -350,7 +349,7 @@ triggerType
triggerEventClause
: (BEFORE | AFTER) INSERT
;
-
+
uriClause
: USING URI uri
;
@@ -358,7 +357,7 @@ uriClause
uri
: STRING_LITERAL
;
-
+
triggerAttributeClause
: WITH LR_BRACKET triggerAttribute (COMMA triggerAttribute)* RR_BRACKET
;
@@ -368,44 +367,44 @@ triggerAttribute
;
```
-下面对 SQL 语法进行说明,您可以结合使用说明章节进行理解:
+Below is the explanation for the SQL syntax:
-- triggerName:触发器 ID,该 ID 是全局唯一的,用于区分不同触发器,大小写敏感。
-- triggerType:触发器类型,分为无状态(STATELESS)和有状态(STATEFUL)两类。
-- triggerEventClause:触发时机,目前仅支持写入前(BEFORE INSERT)和写入后(AFTER INSERT)两种。
-- pathPattern:触发器侦听的路径模式,可以包含通配符 * 和 **。
-- className:触发器实现类的类名。
-- uriClause:可选项,当不指定该选项时,我们默认 DBA 已经在各个 DataNode 节点的 trigger_root_dir
目录(配置项,默认为 IOTDB_HOME/ext/trigger)下放置好创建该触发器需要的 JAR 包。当指定该选项时,我们会将该 URI
对应的文件资源下载并分发到各 DataNode 的 trigger_root_dir/install 目录下。
-- triggerAttributeClause:用于指定触发器实例创建时需要设置的参数,SQL 语法中该部分是可选项。
+- triggerName: The trigger ID, which is globally unique and used to
distinguish different triggers, is case-sensitive.
+- triggerType: Trigger types are divided into two categories, STATELESS and
STATEFUL.
+- triggerEventClause: when the trigger fires, BEFORE INSERT and AFTER INSERT
are supported now.
+- pathPattern:The path pattern the trigger listens on, can contain wildcards *
and **.
+- className:The class name of the Trigger class.
+- jarLocation: Optional. When this option is not specified, by default, we
consider that the DBA has placed the JAR package required to create the trigger
in the trigger_root_dir directory (configuration item, default is
IOTDB_HOME/ext/trigger) of each DataNode node. When this option is specified,
we will download and distribute the file resource corresponding to the URI to
the trigger_root_dir/install directory of each DataNode.
+- triggerAttributeClause: It is used to specify the parameters that need to be
set when the trigger instance is created. This part is optional in the SQL
syntax.
-下面是一个帮助您理解的 SQL 语句示例:
+Here is an example SQL statement to help you understand:
```sql
CREATE STATELESS TRIGGER triggerTest
BEFORE INSERT
ON root.sg.**
AS 'org.apache.iotdb.trigger.ClusterAlertingExample'
-USING URI 'http://jar/ClusterAlertingExample.jar'
+USING URI '/jar/ClusterAlertingExample.jar'
WITH (
"name" = "trigger",
"limit" = "100"
)
```
-上述 SQL 语句创建了一个名为 triggerTest 的触发器:
+The above SQL statement creates a trigger named triggerTest:
-- 该触发器是无状态的(STATELESS)
-- 在写入前触发(BEFORE INSERT)
-- 该触发器侦听路径模式为 root.sg.**
-- 所编写的触发器类名为 org.apache.iotdb.trigger.ClusterAlertingExample
-- JAR 包的 URI 为 http://jar/ClusterAlertingExample.jar
-- 创建该触发器实例时会传入 name 和 limit 两个参数。
+- The trigger is stateless.
+- Fires before insertion.
+- Listens on path pattern root.sg.**
+- The implemented trigger class is named
`org.apache.iotdb.trigger.ClusterAlertingExample`
+- The JAR package URI is http://jar/ClusterAlertingExample.jar
+- When creating the trigger instance, two parameters, name and limit, are
passed in.
-### 卸载触发器
+### Drop Trigger
-可以通过指定触发器 ID 的方式卸载触发器,卸载触发器的过程中会且仅会调用一次触发器的 `onDrop` 接口。
+The trigger can be dropped by specifying the trigger ID. During the process of
dropping the trigger, the `onDrop` interface of the trigger will be called only
once.
-卸载触发器的 SQL 语法如下:
+The SQL syntax is:
```sql
// Drop Trigger
@@ -414,54 +413,54 @@ dropTrigger
;
```
-下面是示例语句:
+Here is an example statement:
```sql
DROP TRIGGER triggerTest1
```
-上述语句将会卸载 ID 为 triggerTest1 的触发器。
+The above statement will drop the trigger with ID triggerTest1.
+
+### Show Trigger
-### 查询触发器
+You can query information about triggers that exist in the cluster through an
SQL statement.
-可以通过 SQL 语句查询集群中存在的触发器的信息。SQL 语法如下:
+The SQL syntax is as follows:
```sql
SHOW TRIGGERS
```
-该语句的结果集格式如下:
+The result set format of this statement is as follows:
| TriggerName | Event | Type | State
| PathPattern | ClassName
| NodeId |
| ------------ | ---------------------------- | -------------------- |
------------------------------------------- | ----------- |
--------------------------------------- |
--------------------------------------- |
| triggerTest1 | BEFORE_INSERT / AFTER_INSERT | STATELESS / STATEFUL |
INACTIVE / ACTIVE / DROPPING / TRANSFFERING | root.** |
org.apache.iotdb.trigger.TriggerExample | ALL(STATELESS) /
DATA_NODE_ID(STATEFUL) |
+### Trigger State
-### 触发器状态说明
-
-在集群中注册以及卸载触发器的过程中,我们维护了触发器的状态,下面是对这些状态的说明:
+During the process of creating and dropping triggers in the cluster, we
maintain the states of the triggers. The following is a description of these
states:
-| 状态 | 描述 |
是否建议写入进行 |
-| ------------ | ------------------------------------------------------------
| ---------------- |
-| INACTIVE | 执行 `CREATE TRIGGER` 的中间状态,集群刚在 ConfigNode 上记录该触发器的信息,还未在任何
DataNode 上激活该触发器 | 否 |
-| ACTIVE | 执行 `CREATE TRIGGE` 成功后的状态,集群所有 DataNode 上的该触发器都已经可用 | 是
|
-| DROPPING | 执行 `DROP TRIGGER` 的中间状态,集群正处在卸载该触发器的过程中 | 否 |
-| TRANSFERRING | 集群正在进行该触发器实例位置的迁移 | 否
|
+| State | Description
| Is it recommended to insert data? |
+| ------------ | ------------------------------------------------------------
| --------------------------------- |
+| INACTIVE | The intermediate state of executing `CREATE TRIGGER`, the
cluster has just recorded the trigger information on the ConfigNode, and the
trigger has not been activated on any DataNode. | NO
|
+| ACTIVE | Status after successful execution of `CREATE TRIGGE`, the
trigger is available on all DataNodes in the cluster. | YES
|
+| DROPPING | Intermediate state of executing `DROP TRIGGER`, the cluster
is in the process of dropping the trigger. | NO |
+| TRANSFERRING | The cluster is migrating the location of this trigger
instance. | NO |
-## 重要注意事项
+## 4. Notes
-- 触发器从注册时开始生效,不对已有的历史数据进行处理。**即只有成功注册触发器之后发生的写入请求才会被触发器侦听到。**
-- 触发器目前采用**同步触发**,所以编写时需要保证触发器效率,否则可能会大幅影响写入性能。**您需要自己保证触发器内部的并发安全性**。
-- 集群中**不能注册过多触发器**。因为触发器信息全量保存在 ConfigNode 中,并且在所有 DataNode 都有一份该信息的副本。
--
**建议注册触发器时停止写入**。注册触发器并不是一个原子操作,注册触发器时,会出现集群内部分节点已经注册了该触发器,部分节点尚未注册成功的中间状态。为了避免部分节点上的写入请求被触发器侦听到,部分节点上没有被侦听到的情况,我们建议注册触发器时不要执行写入。
-- 触发器将作为进程内程序执行,如果您的触发器编写不慎,内存占用过多,由于 IoTDB 并没有办法监控触发器所使用的内存,所以有 OOM 的风险。
-- 持有有状态触发器实例的节点宕机时,我们会尝试在另外的节点上恢复相应实例,在恢复过程中我们会调用一次触发器类的 restore
接口,您可以在该接口中实现恢复触发器所维护的状态的逻辑。
-- 触发器 JAR 包有大小限制,必须小于 min(`config_node_ratis_log_appender_buffer_size_max`,
2G),其中 `config_node_ratis_log_appender_buffer_size_max` 是一个配置项,具体含义可以参考 IOTDB
配置项说明。
-- **不同的 JAR 包中最好不要有全类名相同但功能实现不一样的类**。例如:触发器 trigger1、trigger2 分别对应资源
trigger1.jar、trigger2.jar。如果两个 JAR 包里都包含一个
`org.apache.iotdb.trigger.example.AlertListener` 类,当 `CREATE TRIGGER`
使用到这个类时,系统会随机加载其中一个 JAR 包中的类,最终导致触发器执行行为不一致以及其他的问题。
+- The trigger takes effect from the time of registration, and does not process
the existing historical data. **That is, only insertion requests that occur
after the trigger is successfully registered will be listened to by the
trigger. **
+- The fire process of trigger is synchronous currently, so you need to ensure
the efficiency of the trigger, otherwise the writing performance may be greatly
affected. **You need to guarantee concurrency safety of triggers yourself**.
+- Please do no register too many triggers in the cluster. Because the trigger
information is fully stored in the ConfigNode, and there is a copy of the
information in all DataNodes
+- **It is recommended to stop writing when registering triggers**. Registering
a trigger is not an atomic operation. When registering a trigger, there will be
an intermediate state in which some nodes in the cluster have registered the
trigger, and some nodes have not yet registered successfully. To avoid write
requests on some nodes being listened to by triggers and not being listened to
on some nodes, we recommend not to perform writes when registering triggers.
+- When the node holding the stateful trigger instance goes down, we will try
to restore the corresponding instance on another node. During the recovery
process, we will call the restore interface of the trigger class once.
+- The trigger JAR package has a size limit, which must be less than
min(`config_node_ratis_log_appender_buffer_size_max`, 2G), where
`config_node_ratis_log_appender_buffer_size_max` is a configuration item. For
the specific meaning, please refer to the IOTDB configuration item description.
+- **It is better not to have classes with the same full class name but
different function implementations in different JAR packages.** For example,
trigger1 and trigger2 correspond to resources trigger1.jar and trigger2.jar
respectively. If two JAR packages contain a
`org.apache.iotdb.trigger.example.AlertListener` class, when `CREATE TRIGGER`
uses this class, the system will randomly load the class in one of the JAR
packages, which will eventually leads the inconsistent behavior of trig [...]
-## 配置参数
+## 5. Configuration Parameters
-| 配置项 | 含义
|
-| ------------------------------------------------- |
---------------------------------------------- |
-| *trigger_lib_dir* | 保存触发器 jar 包的目录位置
|
-| *stateful\_trigger\_retry\_num\_when\_not\_found* | 有状态触发器触发无法找到触发器实例时的重试次数 |
\ No newline at end of file
+| Parameter | Meaning
|
+| ------------------------------------------------- |
------------------------------------------------------------ |
+| *trigger_lib_dir* | Directory to save the
trigger jar package |
+| *stateful\_trigger\_retry\_num\_when\_not\_found* | How many times will we
retry to found an instance of stateful trigger on DataNodes if not found |
diff --git a/src/UserGuide/Master/User-Manual/Write-Delete-Data.md
b/src/UserGuide/Master/User-Manual/Write-Delete-Data.md
index dd39d71..77f398f 100644
--- a/src/UserGuide/Master/User-Manual/Write-Delete-Data.md
+++ b/src/UserGuide/Master/User-Manual/Write-Delete-Data.md
@@ -20,51 +20,51 @@
-->
-# 写入数据
-## CLI写入数据
+# Write & Delete Data
+## CLI INSERT
-IoTDB 为用户提供多种插入实时数据的方式,例如在 [Cli/Shell
工具](../QuickStart/Command-Line-Interface.md) 中直接输入插入数据的 INSERT 语句,或使用 Java
API(标准 [Java JDBC](../API/Programming-JDBC.md) 接口)单条或批量执行插入数据的 INSERT 语句。
+IoTDB provides users with a variety of ways to insert real-time data, such as
directly inputting [INSERT SQL statement](../Reference/SQL-Reference.md) in
[Client/Shell tools](../QuickStart/Command-Line-Interface.md), or using [Java
JDBC](../API/Programming-JDBC.md) to perform single or batch execution of
[INSERT SQL statement](../Reference/SQL-Reference.md).
-本节主要为您介绍实时数据接入的 INSERT 语句在场景中的实际使用示例,有关 INSERT SQL 语句的详细语法请参见本文 [INSERT
语句](../Reference/SQL-Reference.md) 节。
+NOTE: This section mainly introduces the use of [INSERT SQL
statement](../Reference/SQL-Reference.md) for real-time data import in the
scenario.
-注:写入重复时间戳的数据则原时间戳数据被覆盖,可视为更新数据。
+Writing a repeat timestamp covers the original timestamp data, which can be
regarded as updated data.
-### 使用 INSERT 语句
+### Use of INSERT Statements
-使用 INSERT
语句可以向指定的已经创建的一条或多条时间序列中插入数据。对于每一条数据,均由一个时间戳类型的时间戳和一个数值或布尔值、字符串类型的传感器采集值组成。
+The [INSERT SQL statement](../Reference/SQL-Reference.md) statement is used to
insert data into one or more specified timeseries created. For each point of
data inserted, it consists of a
[timestamp](../Basic-Concept/Data-Model-and-Terminology.md) and a sensor
acquisition value (see [Data Type](../Basic-Concept/Data-Type.md)).
-在本节的场景实例下,以其中的两个时间序列`root.ln.wf02.wt02.status`和`root.ln.wf02.wt02.hardware`为例
,它们的数据类型分别为 BOOLEAN 和 TEXT。
+In the scenario of this section, take two timeseries
`root.ln.wf02.wt02.status` and `root.ln.wf02.wt02.hardware` as an example, and
their data types are BOOLEAN and TEXT, respectively.
-单列数据插入示例代码如下:
+The sample code for single column data insertion is as follows:
-```sql
+```
IoTDB > insert into root.ln.wf02.wt02(timestamp,status) values(1,true)
IoTDB > insert into root.ln.wf02.wt02(timestamp,hardware) values(1, 'v1')
```
-以上示例代码将长整型的 timestamp 以及值为 true 的数据插入到时间序列`root.ln.wf02.wt02.status`中和将长整型的
timestamp
以及值为”v1”的数据插入到时间序列`root.ln.wf02.wt02.hardware`中。执行成功后会返回执行时间,代表数据插入已完成。
+The above example code inserts the long integer timestamp and the value "true"
into the timeseries `root.ln.wf02.wt02.status` and inserts the long integer
timestamp and the value "v1" into the timeseries `root.ln.wf02.wt02.hardware`.
When the execution is successful, cost time is shown to indicate that the data
insertion has been completed.
-> 注意:在 IoTDB 中,TEXT 类型的数据单双引号都可以来表示,上面的插入语句是用的是双引号表示 TEXT 类型数据,下面的示例将使用单引号表示
TEXT 类型数据。
+> Note: In IoTDB, TEXT type data can be represented by single and double
quotation marks. The insertion statement above uses double quotation marks for
TEXT type data. The following example will use single quotation marks for TEXT
type data.
-INSERT 语句还可以支持在同一个时间点下多列数据的插入,同时向 2 时间点插入上述两个时间序列的值,多列数据插入示例代码如下:
+The INSERT statement can also support the insertion of multi-column data at
the same time point. The sample code of inserting the values of the two
timeseries at the same time point '2' is as follows:
```sql
-IoTDB > insert into root.ln.wf02.wt02(timestamp, status, hardware) values (2,
false, 'v2')
+IoTDB > insert into root.ln.wf02.wt02(timestamp, status, hardware) VALUES (2,
false, 'v2')
```
-此外,INSERT 语句支持一次性插入多行数据,同时向 2 个不同时间点插入上述时间序列的值,示例代码如下:
+In addition, The INSERT statement support insert multi-rows at once. The
sample code of inserting two rows as follows:
```sql
IoTDB > insert into root.ln.wf02.wt02(timestamp, status, hardware) VALUES (3,
false, 'v3'),(4, true, 'v4')
```
-插入数据后我们可以使用 SELECT 语句简单查询已插入的数据。
+After inserting the data, we can simply query the inserted data using the
SELECT statement:
```sql
IoTDB > select * from root.ln.wf02.wt02 where time < 5
```
-结果如图所示。由查询结果可以看出,单列、多列数据的插入操作正确执行。
+The result is shown below. The query result shows that the insertion
statements of single column and multi column data are performed correctly.
```
+-----------------------------+--------------------------+------------------------+
@@ -79,17 +79,19 @@ Total line number = 4
It costs 0.004s
```
-此外,我们可以省略 timestamp 列,此时系统将使用当前的系统时间作为该数据点的时间戳,示例代码如下:
+In addition, we can omit the timestamp column, and the system will use the
current system timestamp as the timestamp of the data point. The sample code is
as follows:
+
```sql
IoTDB > insert into root.ln.wf02.wt02(status, hardware) values (false, 'v2')
```
-**注意:** 当一次插入多行数据时必须指定时间戳。
-### 向对齐时间序列插入数据
+**Note:** Timestamps must be specified when inserting multiple rows of data in
a SQL.
-向对齐时间序列插入数据只需在SQL中增加`ALIGNED`关键词,其他类似。
+### Insert Data Into Aligned Timeseries
-示例代码如下:
+To insert data into a group of aligned time series, we only need to add the
`ALIGNED` keyword in SQL, and others are similar.
+
+The sample code is as follows:
```sql
IoTDB > create aligned timeseries root.sg1.d1(s1 INT32, s2 DOUBLE)
@@ -98,7 +100,7 @@ IoTDB > insert into root.sg1.d1(time, s1, s2) aligned
values(2, 2, 2), (3, 3, 3)
IoTDB > select * from root.sg1.d1
```
-结果如图所示。由查询结果可以看出,数据的插入操作正确执行。
+The result is shown below. The query result shows that the insertion
statements are performed correctly.
```
+-----------------------------+--------------+--------------+
@@ -112,28 +114,35 @@ Total line number = 3
It costs 0.004s
```
-## 原生接口写入
-原生接口 (Session) 是目前IoTDB使用最广泛的系列接口,包含多种写入接口,适配不同的数据采集场景,性能高效且支持多语言。
+## NATIVE API WRITE
+
+The Native API ( Session ) is the most widely used series of APIs of IoTDB,
including multiple APIs, adapted to different data collection scenarios, with
high performance and multi-language support.
+
+### Multi-language API write
+
+#### Java
+
+Before writing via the Java API, you need to establish a connection, refer to
[Java Native API](../API/Programming-Java-Native-API.md).
+then refer to [ JAVA Data Manipulation Interface (DML)
](../API/Programming-Java-Native-API.md#insert)
+
+#### Python
+
+Refer to [ Python Data Manipulation Interface (DML)
](../API/Programming-Python-Native-API.md#insert)
+
+#### C++
-### 多语言接口写入
-* ### Java
- 使用Java接口写入之前,你需要先建立连接,参考 [Java原生接口](../API/Programming-Java-Native-API.md)。
- 之后通过 [ JAVA 数据操作接口(DML)](../API/Programming-Java-Native-API.md#数据写入)写入。
+Refer to [ C++ Data Manipulation Interface (DML)
](../API/Programming-Cpp-Native-API.md#insert)
-* ### Python
- 参考 [ Python 数据操作接口(DML)](../API/Programming-Python-Native-API.md#数据写入)
+#### Go
-* ### C++
- 参考 [ C++ 数据操作接口(DML)](../API/Programming-Cpp-Native-API.md)
+Refer to [Go Native API](../API/Programming-Go-Native-API.md)
-* ### Go
- 参考 [Go 原生接口](../API/Programming-Go-Native-API.md)
+## REST API WRITE
-## REST API写入
+Refer to [insertTablet (v1)](../API/RestServiceV1.md#inserttablet) or
[insertTablet (v2)](../API/RestServiceV2.md#inserttablet)
-参考 [insertTablet (v1)](../API/RestServiceV1.md#inserttablet) or [insertTablet
(v2)](../API/RestServiceV2.md#inserttablet)
+Example:
-示例如下:
```JSON
{
"timestamps": [
@@ -166,44 +175,46 @@ It costs 0.004s
}
```
-## MQTT写入
+## MQTT WRITE
-参考 [内置 MQTT 服务](../API/Programming-MQTT.md#内置-mqtt-服务)
+Refer to [Built-in MQTT
Service](../API/Programming-MQTT.md#built-in-mqtt-service)
-## 批量数据导入
+## BATCH DATA LOAD
-针对于不同场景,IoTDB 为用户提供多种批量导入数据的操作方式,本章节向大家介绍最为常用的两种方式为 CSV文本形式的导入 和 TsFile文件形式的导入。
+In different scenarios, the IoTDB provides a variety of methods for importing
data in batches. This section describes the two most common methods for
importing data in CSV format and TsFile format.
-### TsFile批量导入
+### TsFile Batch Load
-TsFile 是在 IoTDB 中使用的时间序列的文件格式,您可以通过CLI等工具直接将存有时间序列的一个或多个 TsFile
文件导入到另外一个正在运行的IoTDB实例中。具体操作方式请参考[TsFile
导入工具](../Maintenance-Tools/Load-Tsfile.md),[TsFile
导出工具](../Maintenance-Tools/TsFile-Load-Export-Tool.md)。
+TsFile is the file format of time series used in IoTDB. You can directly
import one or more TsFile files with time series into another running IoTDB
instance through tools such as CLI. For details, see [TsFile Load
Tool](../Maintenance-Tools/Load-Tsfile.md) [TsFile Export
Tools](../Maintenance-Tools/TsFile-Load-Export-Tool.md).
-### CSV批量导入
+### CSV Batch Load
-CSV 是以纯文本形式存储表格数据,您可以在CSV文件中写入多条格式化的数据,并批量的将这些数据导入到 IoTDB
中,在导入数据之前,建议在IoTDB中创建好对应的元数据信息。如果忘记创建元数据也不要担心,IoTDB
可以自动将CSV中数据推断为其对应的数据类型,前提是你每一列的数据类型必须唯一。除单个文件外,此工具还支持以文件夹的形式导入多个 CSV
文件,并且支持设置如时间精度等优化参数。具体操作方式请参考 [CSV 导入导出工具](../Maintenance-Tools/CSV-Tool.md)。
+CSV stores table data in plain text. You can write multiple formatted data
into a CSV file and import the data into the IoTDB in batches. Before importing
data, you are advised to create the corresponding metadata in the IoTDB. Don't
worry if you forget to create one, the IoTDB can automatically infer the data
in the CSV to its corresponding data type, as long as you have a unique data
type for each column. In addition to a single file, the tool supports importing
multiple CSV files as f [...]
-# 删除数据
+## DELETE
-用户使用 [DELETE 语句](../Reference/SQL-Reference.md)
可以删除指定的时间序列中符合时间删除条件的数据。在删除数据时,用户可以选择需要删除的一个或多个时间序列、时间序列的前缀、时间序列带、*路径对某一个时间区间内的数据进行删除。
+Users can delete data that meet the deletion condition in the specified
timeseries by using the [DELETE statement](../Reference/SQL-Reference.md). When
deleting data, users can select one or more timeseries paths, prefix paths, or
paths with star to delete data within a certain time interval.
-在 JAVA 编程环境中,您可以使用 JDBC API 单条或批量执行 DELETE 语句。
+In a JAVA programming environment, you can use the [Java
JDBC](../API/Programming-JDBC.md) to execute single or batch UPDATE statements.
-## 单传感器时间序列值删除
+### Delete Single Timeseries
-以测控 ln 集团为例,存在这样的使用场景:
+Taking ln Group as an example, there exists such a usage scenario:
-wf02 子站的 wt02 设备在 2017-11-01 16:26:00
之前的供电状态出现多段错误,且无法分析其正确数据,错误数据影响了与其他设备的关联分析。此时,需要将此时间段前的数据删除。进行此操作的 SQL 语句为:
+The wf02 plant's wt02 device has many segments of errors in its power supply
status before 2017-11-01 16:26:00, and the data cannot be analyzed correctly.
The erroneous data affected the correlation analysis with other devices. At
this point, the data before this time point needs to be deleted. The SQL
statement for this operation is
```sql
delete from root.ln.wf02.wt02.status where time<=2017-11-01T16:26:00;
```
-如果我们仅仅想要删除 2017 年内的在 2017-11-01 16:26:00 之前的数据,可以使用以下 SQL:
+In case we hope to merely delete the data before 2017-11-01 16:26:00 in the
year of 2017, The SQL statement is:
+
```sql
delete from root.ln.wf02.wt02.status where time>=2017-01-01T00:00:00 and
time<=2017-11-01T16:26:00;
```
-IoTDB 支持删除一个时间序列任何一个时间范围内的所有时序点,用户可以使用以下 SQL 语句指定需要删除的时间范围:
+IoTDB supports to delete a range of timeseries points. Users can write SQL
expressions as follows to specify the delete interval:
+
```sql
delete from root.ln.wf02.wt02.status where time < 10
delete from root.ln.wf02.wt02.status where time <= 10
@@ -214,43 +225,54 @@ delete from root.ln.wf02.wt02.status where time >= 20
delete from root.ln.wf02.wt02.status where time = 20
```
-需要注意,当前的删除语句不支持 where 子句后的时间范围为多个由 OR 连接成的时间区间。如下删除语句将会解析出错:
+Please pay attention that multiple intervals connected by "OR" expression are
not supported in delete statement:
+
```
delete from root.ln.wf02.wt02.status where time > 4 or time < 0
Msg: 303: Check metadata error: For delete statement, where clause can only
contain atomic
expressions like : time > XXX, time <= XXX, or two atomic expressions
connected by 'AND'
```
-如果 delete 语句中未指定 where 子句,则会删除时间序列中的所有数据。
+If no "where" clause specified in a delete statement, all the data in a
timeseries will be deleted.
+
```sql
delete from root.ln.wf02.wt02.status
```
-## 多传感器时间序列值删除
-当 ln 集团 wf02 子站的 wt02 设备在 2017-11-01 16:26:00 之前的供电状态和设备硬件版本都需要删除,此时可以使用含义更广的
[路径模式(Path Pattern)](../Data-Concept/Data-Model-and-Terminology.md)
进行删除操作,进行此操作的 SQL 语句为:
+### Delete Multiple Timeseries
+If both the power supply status and hardware version of the ln group wf02
plant wt02 device before 2017-11-01 16:26:00 need to be deleted, [the prefix
path with broader meaning or the path with
star](../Basic-Concept/Data-Model-and-Terminology.md) can be used to delete the
data. The SQL statement for this operation is:
```sql
-delete from root.ln.wf02.wt02.* where time <= 2017-11-01T16:26:00;
+delete from root.ln.wf02.wt02 where time <= 2017-11-01T16:26:00;
```
-需要注意的是,当删除的路径不存在时,IoTDB 不会提示路径不存在,而是显示执行成功,因为 SQL
是一种声明式的编程方式,除非是语法错误、权限不足等,否则都不认为是错误,如下所示。
+or
```sql
+delete from root.ln.wf02.wt02.* where time <= 2017-11-01T16:26:00;
+```
+
+It should be noted that when the deleted path does not exist, IoTDB will not
prompt that the path does not exist, but that the execution is successful,
because SQL is a declarative programming method. Unless it is a syntax error,
insufficient permissions and so on, it is not considered an error, as shown
below:
+
+```
IoTDB> delete from root.ln.wf03.wt02.status where time < now()
Msg: The statement is executed successfully.
```
-## 删除时间分区 (实验性功能)
-您可以通过如下语句来删除某一个 database 下的指定时间分区:
+### Delete Time Partition (experimental)
+
+You may delete all data in a time partition of a database using the following
grammar:
```sql
DELETE PARTITION root.ln 0,1,2
```
-上例中的 0,1,2 为待删除时间分区的 id,您可以通过查看 IoTDB 的数据文件夹找到它,或者可以通过计算`timestamp /
partitionInterval`(向下取整),
-手动地将一个时间戳转换为对应的 id,其中的`partitionInterval`可以在 IoTDB 的配置文件中找到(如果您使用的版本支持时间分区)。
+The `0,1,2` above is the id of the partition that is to be deleted, you can
find it from the IoTDB
+data folders or convert a timestamp manually to an id using `timestamp /
partitionInterval
+` (flooring), and the `partitionInterval` should be in your config (if
time-partitioning is
+supported in your version).
-请注意该功能目前只是实验性的,如果您不是开发者,使用时请务必谨慎。
+Please notice that this function is experimental and mainly for development,
please use it with care.