Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -359,17 +359,23 @@ CREATE DEVICE TEMPLATE <templateName> ALIGNED? '(' <measurementId> <attributeCla
**示例1:** 创建包含两个非对齐序列的元数据模板

```shell
IoTDB> create device template t1 (temperature FLOAT encoding=RLE, status BOOLEAN encoding=PLAIN compression=SNAPPY)
IoTDB> create device template t1 (temperature FLOAT, status BOOLEAN)
```

**示例2:** 创建包含一组对齐序列的元数据模板

```shell
IoTDB> create device template t2 aligned (lat FLOAT encoding=Gorilla, lon FLOAT encoding=Gorilla)
IoTDB> create device template t2 aligned (lat FLOAT, lon FLOAT)
```

其中,物理量 `lat` 和 `lon` 是对齐的。

创建模板无需显式指定编码压缩方式,如需指定,可参考如下示例:
```shell
IoTDB> create device template t1 (temperature FLOAT encoding=RLE, status BOOLEAN encoding=PLAIN compression=SNAPPY)
```
更多详细的数据类型与编码方式的对应列表请参见 [压缩&编码](../Technical-Insider/Encoding-and-Compression.md)。

### 2.2 挂载设备模板

元数据模板在创建后,需执行挂载操作,方可用于相应路径下的序列创建与数据写入。
Expand Down Expand Up @@ -557,7 +563,7 @@ IoTDB> drop device template t1
修改设备模板的 SQL 语句如下所示:

```shell
IoTDB> alter device template t1 add (speed FLOAT encoding=RLE, FLOAT TEXT encoding=PLAIN compression=SNAPPY)
IoTDB> alter device template t1 add (speed FLOAT, FLOAT TEXT)
```

**向已挂载模板的路径下的设备中写入数据,若写入请求中的物理量不在模板中,将自动扩展模板。**
Expand All @@ -570,39 +576,44 @@ IoTDB> alter device template t1 add (speed FLOAT encoding=RLE, FLOAT TEXT encodi
根据建立的数据模型,我们可以分别在两个数据库中创建相应的时间序列。创建时间序列的 SQL 语句如下所示:

```
IoTDB > create timeseries root.ln.wf01.wt01.status with datatype=BOOLEAN,encoding=PLAIN
IoTDB > create timeseries root.ln.wf01.wt01.temperature with datatype=FLOAT,encoding=RLE
IoTDB > create timeseries root.ln.wf02.wt02.hardware with datatype=TEXT,encoding=PLAIN
IoTDB > create timeseries root.ln.wf02.wt02.status with datatype=BOOLEAN,encoding=PLAIN
IoTDB > create timeseries root.sgcc.wf03.wt01.status with datatype=BOOLEAN,encoding=PLAIN
IoTDB > create timeseries root.sgcc.wf03.wt01.temperature with datatype=FLOAT,encoding=RLE
IoTDB > create timeseries root.ln.wf01.wt01.status with datatype=BOOLEAN
IoTDB > create timeseries root.ln.wf01.wt01.temperature with datatype=FLOAT
IoTDB > create timeseries root.ln.wf02.wt02.hardware with datatype=TEXT
IoTDB > create timeseries root.ln.wf02.wt02.status with datatype=BOOLEAN
IoTDB > create timeseries root.sgcc.wf03.wt01.status with datatype=BOOLEAN
IoTDB > create timeseries root.sgcc.wf03.wt01.temperature with datatype=FLOAT
```

从 v0.13 起,可以使用简化版的 SQL 语句创建时间序列:

```
IoTDB > create timeseries root.ln.wf01.wt01.status BOOLEAN encoding=PLAIN
IoTDB > create timeseries root.ln.wf01.wt01.temperature FLOAT encoding=RLE
IoTDB > create timeseries root.ln.wf02.wt02.hardware TEXT encoding=PLAIN
IoTDB > create timeseries root.ln.wf02.wt02.status BOOLEAN encoding=PLAIN
IoTDB > create timeseries root.sgcc.wf03.wt01.status BOOLEAN encoding=PLAIN
IoTDB > create timeseries root.sgcc.wf03.wt01.temperature FLOAT encoding=RLE
IoTDB > create timeseries root.ln.wf01.wt01.status BOOLEAN
IoTDB > create timeseries root.ln.wf01.wt01.temperature FLOAT
IoTDB > create timeseries root.ln.wf02.wt02.hardware TEXT
IoTDB > create timeseries root.ln.wf02.wt02.status BOOLEAN
IoTDB > create timeseries root.sgcc.wf03.wt01.status BOOLEAN
IoTDB > create timeseries root.sgcc.wf03.wt01.temperature
```

创建时间序列无需显式指定编码压缩方式,如需指定,可参考如下示例:
```
IoTDB > create timeseries root.sgcc.wf03.wt01.temperature FLOAT encoding=PLAIN compressor=SNAPPY
```

需要注意的是,当创建时间序列时指定的编码方式与数据类型不对应时,系统会给出相应的错误提示,如下所示:
需要注意的是,如果指定了编码方式,但与数据类型不对应时,系统会给出相应的错误提示,如下所示:
```
IoTDB> create timeseries root.ln.wf02.wt02.status WITH DATATYPE=BOOLEAN, ENCODING=TS_2DIFF
error: encoding TS_2DIFF does not support BOOLEAN
```

详细的数据类型与编码方式的对应列表请参见 [编码方式](../Technical-Insider/Encoding-and-Compression.md)。
更多详细的数据类型与编码压缩方式的对应列表请参见 [压缩&编码](../Technical-Insider/Encoding-and-Compression.md)。

### 3.2 创建对齐时间序列

创建一组对齐时间序列的SQL语句如下所示:

```
IoTDB> CREATE ALIGNED TIMESERIES root.ln.wf01.GPS(latitude FLOAT encoding=PLAIN compressor=SNAPPY, longitude FLOAT encoding=PLAIN compressor=SNAPPY)
IoTDB> CREATE ALIGNED TIMESERIES root.ln.wf01.GPS(latitude FLOAT, longitude FLOAT)
```

一组对齐序列中的序列可以有不同的数据类型、编码方式以及压缩方式。
Expand Down Expand Up @@ -861,7 +872,7 @@ It costs 0.002s

所用到的扩展的创建时间序列的 SQL 语句如下所示:
```
create timeseries root.turbine.d1.s1(temprature) with datatype=FLOAT, encoding=RLE, compression=SNAPPY tags(tag1=v1, tag2=v2) attributes(attr1=v1, attr2=v2)
create timeseries root.turbine.d1.s1(temprature) with datatype=FLOAT tags(tag1=v1, tag2=v2) attributes(attr1=v1, attr2=v2)
```

括号里的`temprature`是`s1`这个传感器的别名。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,17 +359,23 @@ CREATE DEVICE TEMPLATE <templateName> ALIGNED? '(' <measurementId> <attributeCla
**示例1:** 创建包含两个非对齐序列的元数据模板

```shell
IoTDB> create device template t1 (temperature FLOAT encoding=RLE, status BOOLEAN encoding=PLAIN compression=SNAPPY)
IoTDB> create device template t1 (temperature FLOAT, status BOOLEAN )
```

**示例2:** 创建包含一组对齐序列的元数据模板

```shell
IoTDB> create device template t2 aligned (lat FLOAT encoding=Gorilla, lon FLOAT encoding=Gorilla)
IoTDB> create device template t2 aligned (lat FLOAT, lon FLOAT)
```

其中,物理量 `lat` 和 `lon` 是对齐的。

创建模板无需显式指定编码压缩方式,如需指定,可参考如下示例:
```shell
IoTDB> create device template t1 (temperature FLOAT encoding=RLE, status BOOLEAN encoding=PLAIN compression=SNAPPY)
```
更多详细的数据类型与编码方式的对应列表请参见 [压缩&编码](../Technical-Insider/Encoding-and-Compression.md)。

### 2.2 挂载设备模板

元数据模板在创建后,需执行挂载操作,方可用于相应路径下的序列创建与数据写入。
Expand Down Expand Up @@ -557,7 +563,7 @@ IoTDB> drop device template t1
修改设备模板的 SQL 语句如下所示:

```shell
IoTDB> alter device template t1 add (speed FLOAT encoding=RLE, FLOAT TEXT encoding=PLAIN compression=SNAPPY)
IoTDB> alter device template t1 add (speed FLOAT, FLOAT TEXT)
```

**向已挂载模板的路径下的设备中写入数据,若写入请求中的物理量不在模板中,将自动扩展模板。**
Expand All @@ -570,39 +576,45 @@ IoTDB> alter device template t1 add (speed FLOAT encoding=RLE, FLOAT TEXT encodi
根据建立的数据模型,我们可以分别在两个数据库中创建相应的时间序列。创建时间序列的 SQL 语句如下所示:

```
IoTDB > create timeseries root.ln.wf01.wt01.status with datatype=BOOLEAN,encoding=PLAIN
IoTDB > create timeseries root.ln.wf01.wt01.temperature with datatype=FLOAT,encoding=RLE
IoTDB > create timeseries root.ln.wf02.wt02.hardware with datatype=TEXT,encoding=PLAIN
IoTDB > create timeseries root.ln.wf02.wt02.status with datatype=BOOLEAN,encoding=PLAIN
IoTDB > create timeseries root.sgcc.wf03.wt01.status with datatype=BOOLEAN,encoding=PLAIN
IoTDB > create timeseries root.sgcc.wf03.wt01.temperature with datatype=FLOAT,encoding=RLE
IoTDB > create timeseries root.ln.wf01.wt01.status with datatype=BOOLEAN
IoTDB > create timeseries root.ln.wf01.wt01.temperature with datatype=FLOAT
IoTDB > create timeseries root.ln.wf02.wt02.hardware with datatype=TEXT
IoTDB > create timeseries root.ln.wf02.wt02.status with datatype=BOOLEAN
IoTDB > create timeseries root.sgcc.wf03.wt01.status with datatype=BOOLEAN
IoTDB > create timeseries root.sgcc.wf03.wt01.temperature with datatype=FLOAT
```

从 v0.13 起,可以使用简化版的 SQL 语句创建时间序列:

```
IoTDB > create timeseries root.ln.wf01.wt01.status BOOLEAN encoding=PLAIN
IoTDB > create timeseries root.ln.wf01.wt01.temperature FLOAT encoding=RLE
IoTDB > create timeseries root.ln.wf02.wt02.hardware TEXT encoding=PLAIN
IoTDB > create timeseries root.ln.wf02.wt02.status BOOLEAN encoding=PLAIN
IoTDB > create timeseries root.sgcc.wf03.wt01.status BOOLEAN encoding=PLAIN
IoTDB > create timeseries root.sgcc.wf03.wt01.temperature FLOAT encoding=RLE
IoTDB > create timeseries root.ln.wf01.wt01.status BOOLEAN
IoTDB > create timeseries root.ln.wf01.wt01.temperature FLOAT
IoTDB > create timeseries root.ln.wf02.wt02.hardware TEXT
IoTDB > create timeseries root.ln.wf02.wt02.status BOOLEAN
IoTDB > create timeseries root.sgcc.wf03.wt01.status BOOLEAN
IoTDB > create timeseries root.sgcc.wf03.wt01.temperature FLOAT
```

需要注意的是,当创建时间序列时指定的编码方式与数据类型不对应时,系统会给出相应的错误提示,如下所示:
创建时间序列无需显式指定编码压缩方式,如需指定,可参考如下示例:
```
IoTDB > create timeseries root.sgcc.wf03.wt01.temperature FLOAT encoding=PLAIN compressor=SNAPPY
```

需要注意的是,如果指定了编码方式,但与数据类型不对应时,系统会给出相应的错误提示,如下所示:
```
IoTDB> create timeseries root.ln.wf02.wt02.status WITH DATATYPE=BOOLEAN, ENCODING=TS_2DIFF
error: encoding TS_2DIFF does not support BOOLEAN
```

详细的数据类型与编码方式的对应列表请参见 [编码方式](../Technical-Insider/Encoding-and-Compression.md)。
更多详细的数据类型与编码压缩方式的对应列表请参见 [压缩&编码](../Technical-Insider/Encoding-and-Compression.md)。


### 3.2 创建对齐时间序列

创建一组对齐时间序列的SQL语句如下所示:

```
IoTDB> CREATE ALIGNED TIMESERIES root.ln.wf01.GPS(latitude FLOAT encoding=PLAIN compressor=SNAPPY, longitude FLOAT encoding=PLAIN compressor=SNAPPY)
IoTDB> CREATE ALIGNED TIMESERIES root.ln.wf01.GPS(latitude FLOAT, longitude FLOAT)
```

一组对齐序列中的序列可以有不同的数据类型、编码方式以及压缩方式。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ select count_if(s1=0 & s2=0, 3, 'ignoreNull'='false'), count_if(s1=1 & s2=0, 3,
##### 写入语句
```sql
"CREATE DATABASE root.db",
"CREATE TIMESERIES root.db.d1.s1 WITH DATATYPE=INT32, ENCODING=PLAIN tags(city=Beijing)",
"CREATE TIMESERIES root.db.d1.s1 WITH DATATYPE=INT32 tags(city=Beijing)",
"INSERT INTO root.db.d1(timestamp,s1,s2,s3) values(1, 2, 10, true)",
"INSERT INTO root.db.d1(timestamp,s1,s2,s3) values(2, null, 20, true)",
"INSERT INTO root.db.d1(timestamp,s1,s2,s3) values(3, 10, 0, null)",
Expand Down Expand Up @@ -198,10 +198,10 @@ select time_duration(s1) from root.db.d1
##### 写入语句
```sql
CREATE DATABASE root.db;
CREATE TIMESERIES root.db.d1.s1 WITH DATATYPE=INT32, ENCODING=PLAIN;
CREATE TIMESERIES root.db.d1.s2 WITH DATATYPE=INT32, ENCODING=PLAIN;
CREATE TIMESERIES root.db.d2.s1 WITH DATATYPE=INT32, ENCODING=PLAIN;
CREATE TIMESERIES root.db.d2.s2 WITH DATATYPE=INT32, ENCODING=PLAIN;
CREATE TIMESERIES root.db.d1.s1 WITH DATATYPE=INT32;
CREATE TIMESERIES root.db.d1.s2 WITH DATATYPE=INT32;
CREATE TIMESERIES root.db.d2.s1 WITH DATATYPE=INT32;
CREATE TIMESERIES root.db.d2.s2 WITH DATATYPE=INT32;
INSERT INTO root.db.d1(time, s1) VALUES(0, 0), (4,4), (5,5), (8,8);
INSERT INTO root.db.d1(time, s2) VALUES(1, 1), (2,2), (5,5), (7,7), (8,8), (9,9);
INSERT INTO root.db.d2(time, s1) VALUES(1, 1), (2,2), (5,5), (7,7), (8,8);
Expand Down
34 changes: 17 additions & 17 deletions src/zh/UserGuide/Master/Tree/SQL-Manual/SQL-Manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,36 +40,36 @@ count databases root.sgcc
#### 创建时间序列

```sql
create timeseries root.ln.wf01.wt01.status with datatype=BOOLEAN,encoding=PLAIN
create timeseries root.ln.wf01.wt01.temperature with datatype=FLOAT,encoding=RLE
create timeseries root.ln.wf02.wt02.hardware with datatype=TEXT,encoding=PLAIN
create timeseries root.ln.wf02.wt02.status with datatype=BOOLEAN,encoding=PLAIN
create timeseries root.sgcc.wf03.wt01.status with datatype=BOOLEAN,encoding=PLAIN
create timeseries root.sgcc.wf03.wt01.temperature with datatype=FLOAT,encoding=RLE
create timeseries root.ln.wf01.wt01.status with datatype=BOOLEAN
create timeseries root.ln.wf01.wt01.temperature with datatype=FLOAT
create timeseries root.ln.wf02.wt02.hardware with datatype=TEXT
create timeseries root.ln.wf02.wt02.status with datatype=BOOLEAN
create timeseries root.sgcc.wf03.wt01.status with datatype=BOOLEAN
create timeseries root.sgcc.wf03.wt01.temperature with datatype=FLOAT
```

- 简化版

```sql
create timeseries root.ln.wf01.wt01.status BOOLEAN encoding=PLAIN
create timeseries root.ln.wf01.wt01.temperature FLOAT encoding=RLE
create timeseries root.ln.wf02.wt02.hardware TEXT encoding=PLAIN
create timeseries root.ln.wf02.wt02.status BOOLEAN encoding=PLAIN
create timeseries root.sgcc.wf03.wt01.status BOOLEAN encoding=PLAIN
create timeseries root.sgcc.wf03.wt01.temperature FLOAT encoding=RLE
create timeseries root.ln.wf01.wt01.status BOOLEAN
create timeseries root.ln.wf01.wt01.temperature FLOAT
create timeseries root.ln.wf02.wt02.hardware TEXT
create timeseries root.ln.wf02.wt02.status BOOLEAN
create timeseries root.sgcc.wf03.wt01.status BOOLEAN
create timeseries root.sgcc.wf03.wt01.temperature FLOAT
```

- 错误提示

```sql
create timeseries root.ln.wf02.wt02.status WITH DATATYPE=BOOLEAN, ENCODING=TS_2DIFF
create timeseries root.ln.wf02.wt02.status WITH DATATYPE=BOOLEAN
> error: encoding TS_2DIFF does not support BOOLEAN
```

#### 创建对齐时间序列

```sql
CREATE ALIGNED TIMESERIES root.ln.wf01.GPS(latitude FLOAT encoding=PLAIN compressor=SNAPPY, longitude FLOAT encoding=PLAIN compressor=SNAPPY)
CREATE ALIGNED TIMESERIES root.ln.wf01.GPS(latitude FLOAT, longitude FLOAT)
```

#### 删除时间序列
Expand Down Expand Up @@ -116,7 +116,7 @@ COUNT TIMESERIES root.ln.wf01.* GROUP BY LEVEL=2
#### 标签点管理

```sql
create timeseries root.turbine.d1.s1(temprature) with datatype=FLOAT, encoding=RLE, compression=SNAPPY tags(tag1=v1, tag2=v2) attributes(attr1=v1, attr2=v2)
create timeseries root.turbine.d1.s1(temprature) with datatype=FLOAT tags(tag1=v1, tag2=v2) attributes(attr1=v1, attr2=v2)
```

- 重命名标签或属性
Expand Down Expand Up @@ -267,11 +267,11 @@ CREATE DEVICE TEMPLATE <templateName> ALIGNED? '(' <measurementId> <attributeCla

创建包含两个非对齐序列的设备模板
```sql
IoTDB> create device template t1 (temperature FLOAT encoding=RLE, status BOOLEAN encoding=PLAIN compression=SNAPPY)
IoTDB> create device template t1 (temperature FLOAT, status BOOLEAN)
```
创建包含一组对齐序列的设备模板
```sql
IoTDB> create device template t2 aligned (lat FLOAT encoding=Gorilla, lon FLOAT encoding=Gorilla)
IoTDB> create device template t2 aligned (lat FLOAT, lon FLOAT)
```
#### 挂载设备模板
```sql
Expand Down
Loading