提交 d7a9e355 编写于 作者: Z Zesong Sun 提交者: Jialin Qiao

[IOTDB-123] Add documents in Chinese and fix links in English documents (#219)

* Add documents in Chinese and fix links in English documents
上级 d5c7f55d
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
# 常见问题
Comming Soon.
\ No newline at end of file
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
# IoTDB实例
这些示例快速概述了IoTDB JDBC。IoTDB为用户提供了标准的JDBC与IoTDB交互,其他语言版本很快就会融合。
要使用IoTDB,您需要为您的时间序列设置存储组(有关存储组的详细概念,请查看我们的文档)。然后您需要根据数据类型、名称等创建特定的时间序列(存储组的详细概念,请查看我们的文档),之后可以插入和查询数据。在本页中,我们将展示使用iotdb jdbc的基本示例。
## IoTDB Hello World
``` JAVA
/**
* The class is to show how to write and read date from IoTDB through JDBC
*/
package com.tsinghua.iotdb.demo;
import java.sql.*;
import java.text.SimpleDateFormat;
import java.util.Date;
public class IotdbHelloWorld {
public static void main(String[] args) throws SQLException, ClassNotFoundException {
Connection connection = null;
Statement statement = null;
try {
// 1. load JDBC driver of IoTDB
Class.forName("org.apache.iotdb.iotdb.jdbc.IoTDBDriver");
// 2. DriverManager connect to IoTDB
connection = DriverManager.getConnection("jdbc:iotdb://localhost:6667/", "root", "root");
// 3. Create statement
statement = connection.createStatement();
// 4. Set storage group
statement.execute("set storage group to root.vehicle.sensor");
// 5. Create timeseries
statement.execute("CREATE TIMESERIES root.vehicle.sensor.sensor0 WITH DATATYPE=DOUBLE, ENCODING=PLAIN");
// 6. Insert data to IoTDB
statement.execute("INSERT INTO root.vehicle.sensor(timestamp, sensor0) VALUES (2018/10/24 19:33:00, 142)");
// 7. Query data
String sql = "select * from root.vehicle.sensor";
String path = "root.vehicle.sensor.sensor0";
boolean hasResultSet = statement.execute(sql);
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
if (hasResultSet) {
ResultSet res = statement.getResultSet();
System.out.println(" Time" + "|" + path);
while (res.next()) {
long time = Long.parseLong(res.getString("Time"));
String dateTime = dateFormat.format(new Date(time));
System.out.println(dateTime + " | " + res.getString(path));
}
res.close();
}
}
finally {
// 8. Close
if (statement != null) statement.close();
if (connection != null) connection.close();
}
}
}
```
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
# 研究论文
Apache IoTDB 始于清华大学软件学院。IoTDB是一个用于管理大量时间序列数据的数据库,它采用了列式存储、数据编码、预计算和索引技术,具有类SQL的接口,可支持每秒每节点写入数百万数据点,可以秒级获得超过数万亿个数据点的查询结果。它还可以很容易地与 ApacheHadoop、MapReduce 和 ApacheSpark 集成以进行分析。
相关研究论文如下:
* [PISA: An Index for Aggregating Big Time Series Data](https://dl.acm.org/citation.cfm?id=2983775&dl=ACM&coll=DL), Xiangdong Huang and Jianmin Wang and Raymond K. Wong and Jinrui Zhang and Chen Wang. CIKM 2016.
* [Matching Consecutive Subpatterns over Streaming Time Series](https://link.springer.com/chapter/10.1007/978-3-319-96893-3_8), Rong Kang and Chen Wang and Peng Wang and Yuting Ding and Jianmin Wang. APWeb/WAIM 2018.
* [KV-match: A Subsequence Matching Approach Supporting Normalization and Time Warping](https://www.semanticscholar.org/paper/KV-match%3A-A-Subsequence-Matching-Approach-and-Time-Wu-Wang/9ed84cb15b7e5052028fc5b4d667248713ac8592), Jiaye Wu and Peng Wang and Chen Wang and Wei Wang and Jianmin Wang. ICDE 2019.
* 我们还研发了面向时间序列数据库的Benchmark工具: https://github.com/thulab/iotdb-benchmark
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
### v0.7.0 Release Notes
Comming Soon.
\ No newline at end of file
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
# 快速入门
## 安装环境
安装前需要保证设备上配有JDK>=1.8的运行环境,并配置好JAVA_HOME环境变量。
如需从源码进行编译,还需要Maven>=3.0的运行环境。
## IoTDB安装
IoTDB支持多种安装途径。用户可以使用三种方式对IoTDB进行安装——下载二进制可运行程序、使用源码、使用docker镜像。
* 二进制可运行程序:请从Download页面下载最新的安装包,解压后即完成安装。
* 使用源码:您可以从代码仓库下载源码并编译:`git clone https://github.com/apache/incubator-iotdb.git`, 并通过`mvn package -DskipTests` 进行编译。
* 使用Docker: dockerfile文件位于 https://github.com/apache/incubator-iotdb/blob/master/docker/Dockerfile
## IoTDB试用
用户可以根据以下操作对IoTDB进行简单的试用,若以下操作均无误,则说明IoTDB安装成功。
在后文中,记$IOTDB_HOME为IoTDB的安装目录路径,即上述iotdb子文件夹路径。
### 启动IoTDB
用户可以使用$IOTDB_HOME/bin文件夹下的start-server脚本启动IoTDB。
Linux系统与MacOS系统启动命令如下:
```
> $IOTDB_HOME/bin/start-server.sh
```
Windows系统启动命令如下:
```
> $IOTDB_HOME\bin\start-server.bat
```
当服务器输出log中包含ERROR输出时,服务器启动不成功。
### 操作IoTDB
#### 使用Cli/Shell工具
IoTDB为用户提供多种与服务器交互的方式,您可以选择使用Cli/Shell工具、Grafana可视化工具或JAVA API与IoTDB服务器进行数据写入与查询的交互操作。在此我们介绍使用Cli/Shell工具进行写入、查询数据的基本步骤。
初始安装后的IoTDB中有一个默认用户:root,默认密码为root。用户可以使用该用户运行Cli/Shell工具操作IoTDB。Cli/Shell工具启动脚本为$IOTDB_HOME/bin文件夹下的start-client脚本。启动脚本时需要指定运行IP和PORT。
以下启动语句为服务器在本机运行,且用户未更改运行端口号的示例。
Linux系统与MacOS系统启动命令如下:
```
> $IOTDB_HOME/bin/start-client.sh -h 127.0.0.1 -p 6667 -u root
```
Windows系统启动命令如下:
```
> $IOTDB_HOME\bin\start-client.bat -h 127.0.0.1 -p 6667 -u root
```
回车后输入root用户的密码,即可成功启动客户端。启动后出现如图提示即为启动成功。
```
_____ _________ ______ ______
|_ _| | _ _ ||_ _ `.|_ _ \
| | .--.|_/ | | \_| | | `. \ | |_) |
| | / .'`\ \ | | | | | | | __'.
_| |_| \__. | _| |_ _| |_.' /_| |__) |
|_____|'.__.' |_____| |______.'|_______/ version x.x.x
IoTDB> login successfully
IoTDB>
```
#### IoTDB的基本操作
Cli/Shell启动成功后,用户可使用该工具输入SQL命令操作IoTDB Server。
在这里,我们首先介绍一下使用Cli/Shell工具创建时间序列、插入数据并查看数据的方法。
数据在IoTDB中的组织形式是以时间序列为单位,每一个时间序列中有若干个数据-时间点对,存储结构为存储组。在定义时间序列之前,要首先使用SET STORAGE GROUP语句定义存储组。SQL语句如下:
```
IoTDB> SET STORAGE GROUP TO root.ln
```
执行成功后,Cli/Shell返回execute successfully表示执行成功。
存储组设定后,使用CREATE TIMESERIES语句可以创建新的时间序列,创建时间序列时需要定义数据的类型和编码形式。SQL语句如下:
```
IoTDB> CREATE TIMESERIES root.ln.wf01.wt01.status WITH DATATYPE=BOOLEAN, ENCODING=PLAIN
```
执行成功后,Cli/Shell返回execute successfully表示执行成功。
如果系统中已有被创建的存储组和时间序列,则系统会提示该部分已存在。如以下提示表示存储组已存在:
```
IoTDB> SET STORAGE GROUP TO root.ln
error: The path of root.ln already exist, it can't be set to the storage group
```
如下提示表示时间序列已存在:
```
IoTDB> CREATE TIMESERIES root.ln.wf01.wt01.status WITH DATATYPE=BOOLEAN, ENCODING=PLAIN
error: Timeseries root.ln.wf01.wt01.status already exist
```
创建时间序列后,我们使用SHOW TIMESERIES语句查看系统中存在的所有时间序列,SQL语句如下:
```
IoTDB> SHOW TIMESERIES
```
执行结果为:
```
=== Timeseries Tree ===
{
"root":{
"ln":{
"wf01":{
"wt01":{
"status":{
"args":"{}",
"StorageGroup":"root.ln",
"DataType":"BOOLEAN",
"Compressor":"UNCOMPRESSED",
"Encoding":"PLAIN"
}
}
}
}
}
}
```
我们可以尝试再创建一个时间序列,查看SHOW TIMESERIES的返回情况。SQL语句如下:
```
IoTDB> CREATE TIMESERIES root.ln.wf01.wt01.temperature WITH DATATYPE=FLOAT, ENCODING=RLE
IoTDB> SHOW TIMESERIES
```
执行结果为:
```
=== Timeseries Tree ===
{
"root":{
"ln":{
"wf01":{
"wt01":{
"temperature":{
"args":"{}",
"StorageGroup":"root.ln",
"DataType":"FLOAT",
"Compressor":"UNCOMPRESSED",
"Encoding":"RLE"
},
"status":{
"args":"{}",
"StorageGroup":"root.ln",
"DataType":"BOOLEAN",
"Compressor":"UNCOMPRESSED",
"Encoding":"PLAIN"
}
}
}
}
}
}
```
为了查看指定的时间序列,我们可以使用SHOW TIMESERIES <Path>语句,查看时间序列root.ln.wf01.wt01.status的SQL语句如下:
```
IoTDB> SHOW TIMESERIES root.ln.wf01.wt01.status
```
执行结果为:
```
+------------------------------+--------------+--------+--------+
| Timeseries| Storage Group|DataType|Encoding|
+------------------------------+--------------+--------+--------+
| root.ln.wf01.wt01.status| root.ln| BOOLEAN| PLAIN|
+------------------------------+--------------+--------+--------+
timeseries number = 1
Execute successfully.
It costs 0.02s.
```
我们还可以使用SHOW STORAGE GROUP语句来查看系统当前所有的存储组,SQL语句如下:
```
IoTDB> SHOW STORAGE GROUP
```
执行结果为:
```
+-----------------------------------+
| Storage Group|
+-----------------------------------+
| root.ln|
+-----------------------------------+
storage group number = 1
Execute successfully.
It costs 0.001s
```
接下来,我们使用INSERT语句向root.ln.wf01.wt01.status时间序列中插入数据,在插入数据时需要首先指定时间戳和插入的传感器路径名称:
```
IoTDB> INSERT INTO root.ln.wf01.wt01(timestamp,status) values(100,true);
execute successfully.
```
我们也可以向多个传感器中同时插入数据,这些传感器同属于一个时间戳:
```
IoTDB> INSERT INTO root.ln.wf01.wt01(timestamp,status,temperature) values(200,false,20.71)

execute successfully.
```
最后,我们查询之前插入的数据。使用SELECT语句我们可以查询指定的时间序列的数据结果,SQL语句如下:
```
IoTDB> SELECT status FROM root.ln.wf01.wt01
```
查询结果如下:
```
+-----------------------+------------------------+
| Time|root.ln.wf01.wt01.status|
+-----------------------+------------------------+
|1970-01-01T08:00:00.100| true|
|1970-01-01T08:00:00.200| false|
+-----------------------+------------------------+
record number = 1
execute successfully.
```
我们也可以查询多个时间序列的数据结果,SQL语句如下:
```
IoTDB> SELECT * FROM root.ln.wf01.wt01
```
查询结果如下:
```
+-----------------------+--------------------------+-----------------------------+
| Time| root.ln.wf01.wt01.status|root.ln.wf01.wt01.temperature|
+-----------------------+--------------------------+-----------------------------+
|1970-01-01T08:00:00.100| true| null|
|1970-01-01T08:00:00.200| false| 20.71|
+-----------------------+--------------------------+-----------------------------+
```
输入quit或exit可退出Client结束本次会话,Client输出quit normally表示退出成功,操作语句与返回结果如下:
```
IoTDB> quit
quit normally
```
### 停止IoTDB
#### 使用stop-server脚本强制停止
用户可以使用$IOTDB_HOME/bin文件夹下的stop-server脚本停止IoTDB(注意,此停止方式为强制停止,若希望安全停止IoTDB,请使用Jconsole工具的停止方法)。
Linux系统与MacOS系统停止命令如下:
```
> $IOTDB_HOME/bin/stop-server.sh
```
Windows系统停止命令如下:
```
> $IOTDB_HOME\bin\stop-server.bat
```
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
# 第1章: IoTDB概述
## 什么是IoTDB
IoTDB是针对时间序列数据收集、存储与分析一体化的数据管理引擎。它具有体量轻、性能高、易使用的特点,完美对接Hadoop与Spark生态,适用于工业物联网应用中海量时间序列数据高速写入和复杂分析查询的需求。
\ No newline at end of file
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
# 第1章: IoTDB概述
## 架构
IoTDB套件由若干个组件构成,共同形成“数据收集-数据写入-数据存储-数据查询-数据可视化-数据分析”等一系列功能。
图1.1展示了使用IoTDB套件全部组件后形成的整体应用架构。下文称所有组件形成IoTDB套件,而IoTDB特指其中的时间序列数据库组件。
<img style="width:100%; max-width:800px; max-height:600px; margin-left:auto; margin-right:auto; display:block;" src="https://user-images.githubusercontent.com/13203019/51578977-4d5b5800-1efa-11e9-9d6e-6bfe7e890f30.jpg">
在图1.1中,用户可以通过JDBC将来自设备上传感器采集的时序数据、服务器负载和CPU内存等系统状态数据、消息队列中的时序数据、应用程序的时序数据或者其他数据库中的时序数据导入到本地或者远程的IoTDB中。用户还可以将上述数据直接写成本地(或位于HDFS上)的TsFile文件。
对于写入到IoTDB的数据以及本地的TsFile文件,可以通过同步工具TsFileSync将数据文件同步到HDFS上,进而实现在Hadoop或Spark的数据处理平台上的诸如异常检测、机器学习等数据处理任务。对于分析的结果,可以写回成TsFile文件。
IoTDB和TsFile还提供了相应的客户端工具,满足用户查看和写入数据的SQL形式、脚本形式和图形化形式等多种需求。
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
# 第1章: IoTDB概述
## 应用场景
### 场景1
某公司采用表面贴装技术(SMT)生产芯片:需要首先在芯片上的焊接点处印刷(即涂抹)锡膏,然后将元器件放置在锡膏上,进而通过加热熔化锡膏并冷却,使得元器件被焊接在芯片上。上述流程采用自动化生产线。为了确保产品质量合格,在印刷锡膏后,需要通过光学设备对锡膏印刷的质量进行评估:采用三维锡膏印刷检测(SPI)设备对每个焊接点上的锡膏的体积(v)、高度(h)、面积(a)、水平偏移(px)、竖直偏移(py)进行度量。
为了提升印刷质量,该公司有必要将各个芯片上焊接点的度量值进行存储,以便后续基于这些数据进行分析。
此时可以采用IoTDB套件中的TsFile组件、TsFileSync工具和Hadoop/Spark集成组件对数据进行存储:每新印刷一个芯片,就在SPI设备上使用SDK写一条数据,这些数据最终形成一个TsFile文件。通过TsFileSync工具,生成的TsFile文件将按一定规则(如每天)被同步到Hadoop数据中心,并由数据分析人员对其进行分析。
<img style="width:100%; max-width:800px; max-height:600px; margin-left:auto; margin-right:auto; display:block;" src="https://user-images.githubusercontent.com/13203019/51579014-695ef980-1efa-11e9-8cbc-e9e7ee4fa0d8.png">
在场景1中,仅需要TsFile、TsFileSync部署在一台PC上,此外还需要Hadoop/Spark集群。其示意图如图1.2所示。图1.3展示了此时的应用架构。
<img style="width:100%; max-width:800px; max-height:600px; margin-left:auto; margin-right:auto; display:block;" src="https://user-images.githubusercontent.com/13203019/51579026-77ad1580-1efa-11e9-8345-564b22d70286.jpg">
### 场景2
某公司拥有多座风力发电机,公司在每个发电机上安装了上百种传感器,分别采集该发电机的工作状态、工作环境中的风速等信息。
为了保证发电机的正常运转并对发电机及时监控和分析,公司需要收集这些传感器信息,在发电机工作环境中进行部分计算和分析,还需要将收集的原始信息上传到数据中心。
此时可以采用IoTDB套件中的IoTDB、TsFileSync工具和Hadoop/Spark集成组件等。需要部署一个场控PC机,其上安装IoTDB和TsFileSync工具,用于支持读写数据、本地计算和分析以及上传数据到数据中心。此外还需要部署Hadoop/Spark集群用于数据中心端的数据存储和分析。如图1.4所示。
<img style="width:100%; max-width:800px; max-height:600px; margin-left:auto; margin-right:auto; display:block;" src="https://user-images.githubusercontent.com/13203019/51579033-7ed42380-1efa-11e9-889f-fb4180291a9e.png">
图1.5给出了此时的应用架构。
<img style="width:100%; max-width:800px; max-height:600px; margin-left:auto; margin-right:auto; display:block;" src="https://user-images.githubusercontent.com/13203019/51579064-8f849980-1efa-11e9-8cd6-a7339cd0540f.jpg">
### 场景3
某工厂在厂区范围内拥有多种机械手设备,这些机械手设备的硬件配置有限,很难搭载复杂的应用程序。在每个机械手设备上工厂安装了很多种传感器,用以对机械手的工作状态、温度等信息进行监控。由于工厂的网络环境原因,在工厂内部的机械手均处于工厂内部局域网内,无法连接外部网络。同时,工厂中会有少量服务器能够直接连接外部公网。
为了保证机械手的监控数据能够及时监控和分析,公司需要收集这些机械手传感器信息,将其发送至可以连接外部网络的服务器上,而后将原始数据信息上传到数据中心进行复杂的计算和分析。
此时,可以采用IoTDB套件中的IoTDB、IoTDB-CLI工具、TsFileSync工具和Hadoop/Spark集成组件等。将IoTDB服务器安装在工厂连接外网的服务器上,用户接收机械手传输的数据并将数据上传到数据中心。将IoTDB-CLI工具安装在每一个连接工厂内网的机械手上,用于将传感器产生的实时数据上传到工厂内部服务器。再使用TsFileSync工具将原始数据上传到数据中心。此外还需要部署Hadoop/Spark集群用于数据中心端的数据存储和分析。如图1.6中间场景所示。
<img style="width:100%; max-width:800px; max-height:600px; margin-left:auto; margin-right:auto; display:block;" src="https://user-images.githubusercontent.com/13203019/51579080-96aba780-1efa-11e9-87ac-940c45b19dd7.jpg">
图1.7给出了此时的应用架构。
<img style="width:100%; max-width:800px; max-height:600px; margin-left:auto; margin-right:auto; display:block;" src="https://user-images.githubusercontent.com/13203019/51579085-9dd2b580-1efa-11e9-97b9-f56bc8d342b0.jpg">
### 场景4
某汽车公司在其下属的汽车上均安装了传感器采集车辆的行驶状态等监控信息。这些汽车设备的硬件配置有限,很难搭载复杂的应用程序。安装传感器的汽车可以通过窄带物联网相互连接,也可以通过窄带物联网将数据发送至外部网络。
为了能够实时接收汽车传感器所采集的物联网数据,公司需要在车辆行驶的过程中将传感器数据通过窄带物联网实时发送至数据中心,而后在数据中心的服务器上进行复杂的计算和分析。
此时,可以采用IoTDB套件中的IoTDB、IoTDB-CLI和Hadoop/Spark集成组件等。将IoTDB-CLI工具安装在每一辆车联网内的车辆上,使用IoTDB-JDBC工具将数据直接传回数据中心的服务器。
此外还需要部署Hadoop/Spark集群用于数据中心端的数据存储和分析。如图1.8所示。
<img style="width:100%; max-width:800px; max-height:600px; margin-left:auto; margin-right:auto; display:block;" src="https://user-images.githubusercontent.com/13203019/51579095-a4f9c380-1efa-11e9-9f95-17165ec55568.jpg">
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
# 第1章: IoTDB概述
## 主要功能与特点
IoTDB具有以下特点:
* 灵活的部署方式
* 云端一键部署
* 终端解压即用
* 终端-云端无缝连接(数据云端同步工具)
* 低硬件成本的存储解决方案
* 高压缩比的磁盘存储(10亿数据点硬盘成本低于1.4元)
* 目录结构的时间序列组织管理方式
* 支持复杂结构的智能网联设备的时间序列组织
* 支持大量同类物联网设备的时间序列组织
* 可用模糊方式对海量复杂的时间序列目录结构进行检索
* 高通量的时间序列数据读写
* 支持百万级低功耗强连接设备数据接入(海量)
* 支持智能网联设备数据高速读写(高速)
* 以及同时具备上述特点的混合负载
* 面向时间序列的丰富查询语义
* 跨设备、跨传感器的时间序列时间对齐
* 面向时序数据特征的计算(频域变换,0.7.0版本不支持)
* 提供面向时间维度的丰富聚合函数支持
* 极低的学习门槛
* 支持类SQL的数据操作
* 提供JDBC的编程接口
* 完善的导入导出工具(0.7.0版本不支持)
* 完美对接开源生态环境
* 支持开源数据分析生态系统:Hadoop、Spark
* 支持开源可视化工具对接:Grafana
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
# 第2章 IoTDB基本概念
## 主要概念及术语
IoTDB中涉及如下基本概念:
* 设备
设备指的是在实际场景中拥有传感器的装置。在IoTDB当中,所有的传感器都应有其对应的归属的设备。
* 传感器
传感器是指在实际场景中的一种检测装置,它能感受到被测量的信息,并能将感受到的信息按一定规律变换成为电信号或其他所需形式的信息输出并发送给IoTDB。在IoTDB当中,存储的所有的数据及路径,都是以传感器为单位进行组织。
* 3.1.3 存储组
用户可以将任意前缀路径设置成存储组。如有4条时间序列`root.vehicle.d1.s1`, `root.vehicle.d1.s2`, `root.vehicle.d2.s1`, `root.vehicle.d2.s2`,路径`root.vehicle`下的两个设备d1,d2可能属于同一个业主,或者同一个厂商,因此关系紧密。这时候就可以将前缀路径`root.vehicle`指定为一个存储组,这将使得IoTDB将其下的所有设备的数据存储在同一个文件夹下。未来`root.vehicle`下增加了新的设备,也将属于该存储组。
> 注意:不允许将一个完整路径(如上例的`root.vehicle.d1.s1`)设置成存储组。
设置合理数量的存储组可以带来性能的提升:既不会因为产生过多的存储文件(夹)导致频繁切换IO降低系统速度(并且会占用大量内存且出现频繁的内存-文件切换),也不会因为过少的存储文件夹(降低了并发度从而)导致写入命令阻塞。
用户应根据自己的数据规模和使用场景,平衡存储文件的存储组设置,以达到更好的系统性能。(未来会有官方提供的存储组规模与性能测试报告)
> 注意:一个时间序列其前缀必须属于某个存储组。在创建时间序列之前,用户必须设定该序列属于哪个存储组(Storage Group)。只有设置了存储组的时间序列才可以被持久化在磁盘上。
一个前缀路径一旦被设定成存储组后就不可以再更改这个存储组的设置。
一个存储组设定后,其对应的前缀路径的所有父层级与子层级也不允许再设置存储组(如,`root.ln`设置存储组后,root层级与`root.ln.wf01`不允许被设置为存储组)。
* 路径
在IoTDB中,路径是指符合以下约束的表达式:
```
path: LayerName (DOT LayerName)+
LayerName: Identifier | STAR
```
其中STAR为“*”,DOT为“.”。
我们称一个路径中在两个“.”中间的部分叫做一个层级,则`root.a.b.c`为一个层级为4的路径。
值得说明的是,在路径中,root为一个保留字符,它只允许出现在下文提到的时间序列的开头,若其他层级出现root,则无法解析,提示报错。
* 时间序列
时间序列是IoTDB中的核心概念。时间序列可以被看作产生时序数据的传感器的所在完整路径,在IoTDB中所有的时间序列必须以root开始、以传感器作为结尾。一个时间序列也可称为一个全路径。
例如,vehicle种类的device1有名为sensor1的传感器,则它的时间序列可以表示为:`root.vehicle.device1.sensor1`
> 注意:当前IoTDB支持的时间序列必须大于等于四层(之后会更改为两层)。
* 前缀路径
前缀路径是指一个时间序列的前缀所在的路径,一个前缀路径包含以该路径为前缀的所有时间序列。例如当前我们有`root.vehicle.device1.sensor1`, `root.vehicle.device1.sensor2`, `root.vehicle.device2.sensor1`三个传感器,则`root.vehicle.device1`前缀路径包含`root.vehicle.device1.sensor1``root.vehicle.device1.sensor2`两个时间序列,而不包含`root.vehicle.device2.sensor1`
* 3.1.7 带`*`路径
为了使得在表达多个时间序列或表达前缀路径的时候更加方便快捷,IoTDB为用户提供带`*`路径。`*`可以出现在路径中的任何层。按照`*`出现的位置,带`*`路径可以分为两种:
`*`出现在路径的结尾;
`*`出现在路径的中间;
`*`出现在路径的结尾时,其代表的是(`*`)+,即为一层或多层`*`。例如`root.vehicle.device1.*`代表的是`root.vehicle.device1.*`, `root.vehicle.device1.*.*`, `root.vehicle.device1.*.*.*`等所有以`root.vehicle.device1`为前缀路径的大于等于4层的路径。
`*`出现在路径的中间,其代表的是`*`本身,即为一层。例如`root.vehicle.*.sensor1`代表的是以`root.vehicle`为前缀,以`sensor1`为后缀,层次等于4层的路径。
> 注意:`*`不能放在路径开头。
> 注意:`*`放在末尾时与前缀路径表意相同,例如`root.vehicle.*`与`root.vehicle`为相同含义。
* 时间戳
时间戳是一个数据到来的时间点。IoTDB时间戳分为两种类型,一种为LONG类型,一种为DATETIME类型(包含DATETIME-INPUT, DATETIME-DISPLAY两个小类)。
在用户在输入时间戳时,可以使用LONG类型的时间戳或DATETIME-INPUT类型的时间戳,其中DATETIME-INPUT类型的时间戳支持格式见表格2-1。
<center>**表格2-1 DATETIME-INPUT类型支持格式**
|format|
|:---:|
|yyyy-MM-dd HH:mm:ss|
|yyyy/MM/dd HH:mm:ss|
|yyyy.MM.dd HH:mm:ss|
|yyyy-MM-dd'T'HH:mm:ss|
|yyyy/MM/dd'T'HH:mm:ss|
|yyyy.MM.dd'T'HH:mm:ss|
|yyyy-MM-dd HH:mm:ssZZ|
|yyyy/MM/dd HH:mm:ssZZ|
|yyyy.MM.dd HH:mm:ssZZ|
|yyyy-MM-dd'T'HH:mm:ssZZ|
|yyyy/MM/dd'T'HH:mm:ssZZ|
|yyyy.MM.dd'T'HH:mm:ssZZ|
|yyyy/MM/dd HH:mm:ss.SSS|
|yyyy-MM-dd HH:mm:ss.SSS|
|yyyy.MM.dd HH:mm:ss.SSS|
|yyyy/MM/dd'T'HH:mm:ss.SSS|
|yyyy-MM-dd'T'HH:mm:ss.SSS|
|yyyy.MM.dd'T'HH:mm:ss.SSS|
|yyyy-MM-dd HH:mm:ss.SSSZZ|
|yyyy/MM/dd HH:mm:ss.SSSZZ|
|yyyy.MM.dd HH:mm:ss.SSSZZ|
|yyyy-MM-dd'T'HH:mm:ss.SSSZZ|
|yyyy/MM/dd'T'HH:mm:ss.SSSZZ|
|yyyy.MM.dd'T'HH:mm:ss.SSSZZ|
|ISO8601 standard time format|
</center>
IoTDB在显示时间戳时可以支持LONG类型以及DATETIME-DISPLAY类型,其中DATETIME-DISPLAY类型可以支持用户自定义时间格式。自定义时间格式的语法见表格2-2。
<center>**表格2-2 DATETIME-DISPLAY自定义时间格式的语法**
|Symbol|Meaning|Presentation|Examples|
|:---:|:---:|:---:|:---:|
|G|era|era|era|
|C|century of era (>=0)| number| 20|
| Y |year of era (>=0)| year| 1996|
|||||
| x |weekyear| year| 1996|
| w |week of weekyear| number |27|
| e |day of week |number| 2|
| E |day of week |text |Tuesday; Tue|
|||||
| y| year| year| 1996|
| D |day of year |number| 189|
| M |month of year |month| July; Jul; 07|
| d |day of month |number| 10|
|||||
| a |halfday of day |text |PM|
| K |hour of halfday (0~11) |number| 0|
| h |clockhour of halfday (1~12) |number| 12|
|||||
| H |hour of day (0~23)| number| 0|
| k |clockhour of day (1~24) |number| 24|
| m |minute of hour| number| 30|
| s |second of minute| number| 55|
| S |fraction of second |millis| 978|
|||||
| z |time zone |text |Pacific Standard Time; PST|
| Z |time zone offset/id| zone| -0800; -08:00; America/Los_Angeles|
|||||
| '| escape for text |delimiter|  |
| ''| single quote| literal |'|
</center>
*
一个时间序列的值是由实际中的传感器向IoTDB发送的数值。这个值可以按照数据类型被IoTDB存储,同时用户也可以针对这个值的数据类型选择压缩方式,以及对应的编码方式。数据类型与对应编码的详细信息请参见本文[数据类型](/#/Documents/latest/chap2/sec2)[编码方式](/#/Documents/latest/chap2/sec3)节。
* 数据点
一个数据点是由一个时间戳-值对(timestamp, value)组成的。
* 数据的列
一个数据的列包含属于一个时间序列的所有值以及这些值相对应的时间戳。当有多个数据的列时,IoTDB会针对时间戳做合并,变为多个<时间戳-多值>对(timestamp, value, value, …)。
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
# 第2章 IoTDB基本概念
## 数据类型
IoTDB支持BOOLEAN(布尔值), INT32(整型), INT64(长整型), FLOAT(单精度浮点数), DOUBLE(双精度浮点数), TEXT(字符串)一共六种数据类型。
其中FLOAT与DOUBLE类型的序列,如果编码方式采用[RLE](/#/Documents/latest/chap2/sec3)[TS_2DIFF](/#/Documents/latest/chap2/sec3)可以指定MAX_POINT_NUMBER,该项为浮点数的小数点后位数,具体指定方式请参见本文[第5.1节](/#/Documents/latest/chap5/sec1),若不指定则系统会根据配置文件tsfile-format.properties文件中的[float_precision项](/#/Documents/latest/chap2/sec3)配置。
当系统中用户输入的数据类型与该时间序列的数据类型不对应时,系统会提醒类型错误,如下所示,二阶差分不支持布尔类型的编码:
```
IoTDB> create timeseries root.ln.wf02.wt02.status WITH DATATYPE=BOOLEAN, ENCODING=TS_2DIFF
error: encoding TS_2DIFF does not support BOOLEAN
```
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
# 第2章 IoTDB基本概念
## 编码方式
为了提高数据的存储效率,需要在数据写入的过程中对数据进行编码,从而减少磁盘空间的使用量。在写数据以及读数据的过程中都能够减少I/O操作的数据量从而提高性能。IoTDB支持四种针对不同类型的数据的编码方法:
* PLAIN编码(PLAIN)
PLAIN编码,默认的编码方式,即不编码,支持多种数据类型,压缩和解压缩的时间效率较高,但空间存储效率较低。
* 二阶差分编码(TS_2DIFF)
二阶差分编码,比较适合编码单调递增或者递减的序列数据,不适合编码波动较大的数据。
二阶差分编码也可用于对浮点数进行编码,但在创建时间序列的时候需指定保留小数位数(MAX_POINT_NUMBER,具体指定方式参见本文[第5.1节](/#/Documents/latest/chap5/sec1))。比较适合存储某些浮点数值连续出现、单调调递增或者递减的序列数据,不适合存储对小数点后精度要求较高以及前后波动较大的序列数据。
* 游程编码(RLE)
游程编码,比较适合存储某些整数值连续出现的序列,不适合编码大部分情况下前后值不一样的序列数据。
游程编码也可用于对浮点数进行编码,,但在创建时间序列的时候需指定保留小数位数(MAX_POINT_NUMBER,具体指定方式参见本文本文[第5.1节](/#/Documents/latest/chap5/sec1))。比较适合存储某些浮点数值连续出现的序列数据,不适合存储对小数点后精度要求较高以及前后波动较大的序列数据。
* GORILLA编码(GORILLA)
GORILLA编码,比较适合编码前后值比较接近的浮点数序列,不适合编码前后波动较大的数据。
* 数据类型与编码的对应关系
前文介绍的四种编码适用于不同的数据类型,若对应关系错误,则无法正确创建时间序列。数据类型与支持其编码的编码方式对应关系总结如表格2-3。
<center> **表格2-3 数据类型与支持其编码的对应关系**
|数据类型 |支持的编码|
|:---:|:---:|
|BOOLEAN| PLAIN, RLE|
|INT32 |PLAIN, RLE, TS_2DIFF|
|INT64 |PLAIN, RLE, TS_2DIFF|
|FLOAT |PLAIN, RLE, TS_2DIFF, GORILLA|
|DOUBLE |PLAIN, RLE, TS_2DIFF, GORILLA|
|TEXT |PLAIN|
</center>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
# 第2章 IoTDB基本概念
## 压缩方式
当时间序列写入并按照指定的类型编码为二进制数据后,IoTDB会使用压缩技术对该数据进行压缩,进一步提升空间存储效率。虽然编码和压缩都旨在提升存储效率,但编码技术通常只适合特定的数据类型(如二阶差分编码只适合与INT32或者INT64编码,存储浮点数需要先将他们乘以10m以转换为整数),然后将它们转换为二进制流。压缩方式(SNAPPY)针对二进制流进行压缩,因此压缩方式的使用不再受数据类型的限制。
IoTDB允许在创建一个时间序列的时候指定该列的压缩方式。现阶段IoTDB现在支持的压缩方式有两种:UNCOMPRESSOR(不压缩)和SNAPPY压缩。压缩方式的指定语法详见本文[5.1节](/#/Documents/latest/chap5/sec1)
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
# 第3章 IoTDB操作指南
## Sample Data
我们为您提供一份简化的[样例数据](https://github.com/apache/incubator-iotdb/blob/master/docs/Documentation/OtherMaterial-Sample%20Data.txt)
下载文件: [IoTDB-SampleData.txt](https://raw.githubusercontent.com/apache/incubator-iotdb/master/docs/Documentation/OtherMaterial-Sample%20Data.txt).
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
# 第3章 IoTDB操作指南
## 数据模型选用与创建
在向IoTDB导入数据之前,首先要根据[样例数据](/#/Documents/latest/chap3/sec1)选择合适的数据存储模型,然后使用[SET STORAGE GROUP](/#/Documents/latest/chap5/sec1)语句和[CREATE TIMESERIES](/#/Documents/latest/chap5/sec1)语句设置存储组,并创建时间序列。
### 选用存储模型
根据本文描述的[数据](/#/Documents/latest/chap3/sec1)属性层级,按照属性涵盖范围以及它们之间的从属关系,我们可将其表示为如下图3.1的属性层级组织结构,其层级关系为:集团层-电场层-设备层-传感器层。其中ROOT为根节点,传感器层的每一个节点称为叶子节点。在使用IoTDB的过程中,您可以直接将由ROOT节点到每一个叶子节点路径上的属性用“.”连接,将其作为一个IoTDB的时间序列的名称。图3.1中最左侧的路径可以生成一个名为`ROOT.ln.wf01.wt01.status`的时间序列。
<center><img style="width:100%; max-width:800px; max-height:600px; margin-left:auto; margin-right:auto; display:block;" src="https://user-images.githubusercontent.com/13203019/51577327-7aa50780-1ef4-11e9-9d75-cadabb62444e.jpg">
**图3.1 属性层级组织结构**</center>
得到时间序列的名称之后,我们需要根据数据的实际场景和规模设置存储组。由于在本文所述场景中,每次到达的数据通常以集团为单位(即数据可能为跨电场、跨设备的),为了写入数据时避免频繁切换IO降低系统速度,且满足用户以集团为单位进行物理隔离数据的要求,我们将存储组设置在集团层。
### 创建存储组
存储模型选用后,我们可以根据存储模型建立相应的存储组。创建存储组的SQL语句如下所示:
```
IoTDB > set storage group to root.ln
IoTDB > set storage group to root.sgcc
```
根据以上两条SQL语句,我们可以创建出两个存储组。
需要注意的是,当系统中已经存在某个存储组或存储组的父亲节点或者孩子节点被设置为存储组的情况下,用户不可创建存储组。例如在已经有`root.ln``root.sgcc`这两个存储组的情况下,创建`root.ln.wf01`存储组是不可行的。系统将给出相应的错误提示,如下所示:
```
IoTDB> set storage group to root.ln.wf01
error: The prefix of root.ln.wf01 has been set to the storage group.
```
### 查看存储组
在存储组创建后,我们可以使用[SHOW STORAGE GROUP](/#/Documents/latest/chap5/sec1)语句来查看所有的存储组,SQL语句如下所示:
```
IoTDB> show storage group
```
执行结果为:
<center><img style="width:100%; max-width:800px; max-height:600px; margin-left:auto; margin-right:auto; display:block;" src="https://user-images.githubusercontent.com/13203019/51577338-84c70600-1ef4-11e9-9dab-605b32c02836.jpg"></center>
### 创建时间序列
根据建立的数据模型,我们可以分别在两个存储组中创建相应的时间序列。创建时间序列的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.wf02.wt02.status WITH DATATYPE=BOOLEAN, ENCODING=TS_2DIFF
error: encoding TS_2DIFF does not support BOOLEAN
```
详细的数据类型与编码方式的对应列表请参见[编码方式](/#/Documents/latest/chap2/sec3)
### 查看时间序列
目前,IoTDB支持两种查看时间序列的方式:
* SHOW TIMESERIES语句以JSON形式展示系统中所有的时间序列信息
* SHOW TIMESERIES <`Path`>语句以表格的形式返回给定路径的下的所有时间序列信息及时间序列总数。时间序列信息具体包括:时间序列路径名,数据类型,编码类型。其中,`Path`需要为一个前缀路径、带星路径或时间序列路径。例如,分别查看`root`路径和`root.ln`路径下的时间序列,SQL语句如下所示:
```
IoTDB> show timeseries root
IoTDB> show timeseries root.ln
```
执行结果分别为:
<center><img style="width:100%; max-width:800px; max-height:600px; margin-left:auto; margin-right:auto; display:block;" src="https://user-images.githubusercontent.com/13203019/51577347-8db7d780-1ef4-11e9-91d6-764e58c10e94.jpg"></center>
<center><img style="width:100%; max-width:800px; max-height:600px; margin-left:auto; margin-right:auto; display:block;" src="https://user-images.githubusercontent.com/13203019/51577359-97413f80-1ef4-11e9-8c10-53b291fc10a5.jpg"></center>
需要注意的是,当查询路径不存在时,系统会给出相应的错误提示,如下所示:
```
IoTDB> show timeseries root.ln.wf03
Msg: Failed to fetch timeseries root.ln.wf03's metadata because: Timeseries does not exist.
```
### 注意事项
0.7.0版本对用户操作的数据规模进行一些限制:
限制1:假设运行时IoTDB分配到的JVM内存大小为p,用户自定义的每次将内存中的数据写入到磁盘时的大小([group_size_in_byte](/#/Documents/latest/chap4/sec2))为q。存储组的数量不能超过p/q。
限制2:时间序列的数量不超过运行时IoTDB分配到的JVM内存与20KB的比值。
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
# 第3章 IoTDB操作指南
## 数据接入
### 历史数据导入
0.7.0版本中暂不支持此功能。
### 实时数据接入
IoTDB为用户提供多种插入实时数据的方式,例如在[Cli/Shell工具](/#/Tools/Cli)中直接输入插入数据的[INSERT语句](/#/Documents/latest/chap5/sec1),或使用Java API(标准[Java JDBC](/#/Documents/latest/chap6/sec1)接口)单条或批量执行插入数据的[INSERT语句](/#/Documents/latest/chap5/sec1)
本节主要为您介绍实时数据接入的[INSERT语句](/#/Documents/latest/chap5/sec1)在场景中的实际使用示例,有关INSERT SQL语句的详细语法请参见本文[INSERT语句](/#/Documents/latest/chap5/sec1)节。
#### 使用INSERT语句
使用[INSERT语句](/#/Documents/latest/chap5/sec1)可以向指定的已经创建的一条或多条时间序列中插入数据。对于每一条数据,均由一个时间戳类型的[时间戳](/#/Documents/latest/chap2/sec1)和一个[数值类型](/#/Documents/latest/chap2/sec2)的传感器采集值组成。
在本节的场景实例下,以其中的两个时间序列`root.ln.wf02.wt02.status``root.ln.wf02.wt02.hardware`为例 ,它们的数据类型分别为BOOLEAN和TEXT。
单列数据插入示例代码如下:
```
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`中。执行成功后会出现execute successfully的提示,代表数据插入已完成。
> 注意:在IoTDB中,TEXT类型的数据单双引号都可以来表示,上面的插入语句是用的是双引号表示TEXT类型数据,下面的示例将使用单引号表示TEXT类型数据。
INSERT语句还可以支持在同一个时间点下多列数据的插入,同时向2时间点插入上述两个时间序列的值,多列数据插入示例代码如下:
```
IoTDB > insert into root.ln.wf02.wt02(timestamp, status, hardware) VALUES (2, false, 'v2')
```
插入数据后我们可以使用SELECT语句简单查询已插入的数据。
```
IoTDB > select * from root.ln.wf02 where time < 3
```
结果如图所示。由查询结果可以看出,单列、多列数据的插入操作正确执行。
<center><img style="width:100%; max-width:800px; max-height:600px; margin-left:auto; margin-right:auto; display:block;" src="https://user-images.githubusercontent.com/13203019/51605021-c2ee1500-1f48-11e9-8f6b-ba9b48875a41.png"></center>
### INSERT语句的错误处理
若用户向一个不存在的时间序列中插入数据,例如执行以下命令:
```
IoTDB > insert into root.ln.wf02.wt02(timestamp, temperature) values(1,"v1")
```
由于`root.ln.wf02.wt02. temperature`时间序列不存在,系统将会返回以下ERROR告知该Timeseries路径不存在:
```
error: Timeseries root.ln.wf02.wt02.temperature does not exist.
```
若用户插入的数据类型与该Timeseries对应的数据类型不一致,例如执行以下命令:
```
IoTDB > insert into root.ln.wf02.wt02(timestamp,hardware) values(1,100)
```
系统将会返回以下ERROR告知数据类型有误:
```
error: The TEXT data type should be covered by " or '
```
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
# 第3章 IoTDB操作指南
## 数据维护
### 数据更新
用户使用[UPDATE语句](/#/Documents/latest/chap5/sec1)可以更新指定的时间序列中一段时间的数据。在更新数据时,用户可以选择需要更新的一个时间序列(0.7.0版本暂不支持多个时间序列的更新)并指定更新某个时间点或时间段的数据(0.7.0版本必须有时间过滤条件)。
在JAVA编程环境中,您可以使用[JDBC API](/#/Documents/latest/chap6/sec1)单条或批量执行UPDATE语句。
#### 单传感器时间序列值更新
以测控ln集团wf02子站wt02设备供电状态为例,存在这样的使用场景:
当数据接入并分析后,发现从2017-11-01 15:54:00到2017-11-01 16:00:00内的供电状态为true,但实际供电状态存在异常。需要将这段时间状态更新为false。进行此操作的SQL语句为:
```
update root.ln.wf02 SET wt02.status = false where time <=2017-11-01T16:00:00 and time >= 2017-11-01T15:54:00
```
需要注意的是,当更新数据类型与实际类型不符时,IoTDB会给出相应的错误提示:
```
IoTDB> update root.ln.wf02 set wt02.status = 1205 where time < now()
error: The BOOLEAN data type should be true/TRUE or false/FALSE
```
当更新的列不存在时,IoTDB给出没有存在的路径的错误提示:
```
IoTDB> update root.ln.wf02 set wt02.sta = false where time < now()
error: do not select any existing path
```
### 数据删除
用户使用[DELETE语句](/#/Documents/latest/chap5/sec1)可以删除指定的时间序列中符合时间删除条件的数据。在删除数据时,用户可以选择需要删除的一个或多个时间序列、时间序列的前缀、时间序列带*路径对某时间之前的数据进行删除(0.7.0版本暂不支持删除某一闭时间区间范围内的数据)。
在JAVA编程环境中,您可以使用[JDBC API](/#/Documents/latest/chap6/sec1)单条或批量执行UPDATE语句。
#### 单传感器时间序列值删除
以测控ln集团为例,存在这样的使用场景:
wf02子站的wt02设备在2017-11-01 16:26:00之前的供电状态出现多段错误,且无法分析其正确数据,错误数据影响了与其他设备的关联分析。此时,需要将此时间段前的数据删除。进行此操作的SQL语句为:
```
delete from root.ln.wf02.wt02.status where time<=2017-11-01T16:26:00;
```
#### 多传感器时间序列值删除
当ln集团wf02子站的wt02设备在2017-11-01 16:26:00之前的供电状态和设备硬件版本都需要删除,此时可以使用含义更广的前缀路径(参见本文第3.1.6节)或带`*`路径(参见本文第3.1.7节)进行删除操作,进行此操作的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会提示路径不存在,无法删除数据,如下所示。
```
IoTDB> delete from root.ln.wf03.wt02.status where time < now()
error: TimeSeries does not exist and cannot be delete data
```
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
# 第3章 IoTDB操作指南
## 权限管理
IoTDB为用户提供了权限管理操作,从而为用户提供对于数据的权限管理功能,保障数据的安全。
我们将通过以下几个具体的例子为您示范基本的用户权限操作,详细的SQL语句及使用方式详情请参见本文[第5.1节](/#/Documents/latest/chap5/sec1)。同时,在JAVA编程环境中,您可以使用[JDBC API](/#/Documents/latest/chap6/sec1)单条或批量执行权限管理类语句。
### 基本概念
#### 用户
用户即数据库的合法使用者。一个用户与一个唯一的用户名相对应,并且拥有密码作为身份验证的手段。一个人在使用数据库之前,必须先提供合法的(即存于数据库中的)用户名与密码,使得自己成为用户。
#### 权限
数据库提供多种操作,并不是所有的用户都能执行所有操作。如果一个用户可以执行某项操作,则称该用户有执行该操作的权限。权限可分为数据管理权限(如对数据进行增删改查)以及权限管理权限(用户、角色的创建与删除,权限的赋予与撤销等)。数据管理权限往往需要一个路径来限定其生效范围,它的生效范围是以该路径对应的节点为根的一颗子树(具体请参考IoTDB的数据组织)。
#### 角色
角色是若干权限的集合,并且有一个唯一的角色名作为标识符。用户通常和一个现实身份相对应(例如交通调度员),而一个现实身份可能对应着多个用户。这些具有相同现实身份的用户往往具有相同的一些权限。角色就是为了能对这样的权限进行统一的管理的抽象。
#### 默认用户及其具有的角色
初始安装后的IoTDB中有一个默认用户:root,默认密码为root。该用户为管理员用户,固定拥有所有权限,无法被赋予、撤销权限,也无法被删除。
### 权限操作示例
根据本文中描述的[样例数据](/#/Documents/latest/chap3/sec1)内容,IoTDB的样例数据可能同时属于ln, sgcc等不同发电集团,不同的发电集团不希望其他发电集团获取自己的数据库数据,因此我们需要将不同的数据在集团层进行权限隔离。
#### 创建用户
我们可以为ln和sgcc集团创建两个用户角色,名为ln_write_user, sgcc_write_user,密码均为write_pwd。SQL语句为:
```
CREATE USER ln_write_user write_pwd
CREATE USER sgcc_write_user write_pwd
```
此时使用展示用户的SQL语句:
```
LIST USER
```
我们可以看到这两个已经被创建的用户,结果如图:
<center><img style="width:100%; max-width:800px; max-height:600px; margin-left:auto; margin-right:auto; display:block;" src="https://user-images.githubusercontent.com/13203019/51578263-e2a91d00-1ef7-11e9-94e8-28819b6fea87.jpg"></center>
#### 赋予用户权限
此时,虽然两个用户已经创建,但是他们不具有任何权限,因此他们并不能对数据库进行操作,例如我们使用ln_write_user用户对数据库中的数据进行写入,SQL语句为:
```
INSERT INTO root.ln.wf01.wt01(timestamp,status) values(1509465600000,true)
```
此时,系统不允许用户进行此操作,会提示错误,如图:
<center><img style="width:100%; max-width:800px; max-height:600px; margin-left:auto; margin-right:auto; display:block;" src="https://user-images.githubusercontent.com/13203019/51597609-9af5b600-1f36-11e9-9460-8ab185eb4735.png"></center>
现在,我们分别赋予他们向对应存储组数据的写入权限,并再次尝试向对应的存储组进行数据写入。SQL语句为:
```
GRANT USER ln_write_user PRIVILEGES 'INSERT_TIMESERIES' on root.ln
GRANT USER sgcc_write_user PRIVILEGES 'INSERT_TIMESERIES' on root.sgcc
INSERT INTO root.ln.wf01.wt01(timestamp, status) values(1509465600000, true)
```
执行状态如图所示:
<center><img style="width:100%; max-width:800px; max-height:600px; margin-left:auto; margin-right:auto; display:block;" src="https://user-images.githubusercontent.com/13203019/51578942-33ba1080-1efa-11e9-891c-09d69791aff1.jpg"></center>
### 其他说明
#### 用户、权限与角色的关系
角色是权限的集合,而权限和角色都是用户的一种属性。即一个角色可以拥有若干权限。一个用户可以拥有若干角色与权限(称为用户自身权限)。
目前在IoTDB中并不存在相互冲突的权限,因此一个用户真正具有的权限是用户自身权限与其所有的角色的权限的并集。即要判定用户是否能执行某一项操作,就要看用户自身权限或用户的角色的所有权限中是否有一条允许了该操作。用户自身权限与其角色权限,他的多个角色的权限之间可能存在相同的权限,但这并不会产生影响。
需要注意的是:如果一个用户自身有某种权限(对应操作A),而他的某个角色有相同的权限。那么如果仅从该用户撤销该权限无法达到禁止该用户执行操作A的目的,还需要从这个角色中也撤销对应的权限,或者从这个用户将该角色撤销。同样,如果仅从上述角色将权限撤销,也不能禁止该用户执行操作A。
同时,对角色的修改会立即反映到所有拥有该角色的用户上,例如对角色增加某种权限将立即使所有拥有该角色的用户都拥有对应权限,删除某种权限也将使对应用户失去该权限(除非用户本身有该权限)。
#### 系统所含权限列表
<center>**表格3-8 系统所含权限列表**
|权限名称|说明|
|:---|:---|
|SET\_STORAGE\_GROUP|创建时间序列。包含设置存储组的权限。路径相关|
|INSERT\_TIMESERIES|插入数据。路径相关|
|UPDATE\_TIMESERIES|更新数据。路径相关|
|READ\_TIMESERIES|查询数据。路径相关|
|DELETE\_TIMESERIES|删除数据或时间序列。路径相关|
|CREATE\_USER|创建用户。路径无关|
|DELETE\_USER|删除用户。路径无关|
|MODIFY\_PASSWORD|修改所有用户的密码。路径无关。(没有该权限者仍然能够修改自己的密码。)|
|LIST\_USER|列出所有用户,列出某用户权限,列出某用户具有的角色三种操作的权限。路径无关|
|GRANT\_USER\_PRIVILEGE|赋予用户权限。路径无关|
|REVOKE\_USER\_PRIVILEGE|撤销用户权限。路径无关|
|GRANT\_USER\_ROLE|赋予用户角色。路径无关|
|REVOKE\_USER\_ROLE|撤销用户角色。路径无关|
|CREATE\_ROLE|创建角色。路径无关|
|DELETE\_ROLE|删除角色。路径无关|
|LIST\_ROLE|列出所有角色,列出某角色拥有的权限,列出拥有某角色的所有用户三种操作的权限。路径无关|
|GRANT\_ROLE\_PRIVILEGE|grant role priviledges; path independent|
|REVOKE\_ROLE\_PRIVILEGE|撤销角色权限。路径无关|
</center>
#### 用户名限制
IoTDB规定用户名的字符长度不小于4,其中用户名不能包含空格。
#### 密码限制
IoTDB规定密码的字符长度不小于4,其中密码不能包含空格,密码采用MD5进行加密。
#### 角色名限制
IoTDB规定角色名的字符长度不小于4,其中角色名不能包含空格。
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
# 第4章 系统部署与管理
## 系统部署
IoTDB为您提供了两种安装方式,您可以参考下面的建议,任选其中一种:
第一种,从官网下载安装包。这是我们推荐使用的安装方式,通过该方式,您将得到一个可以立即使用的、打包好的二进制可执行文件。
第二种,使用源码编译。若您需要自行修改代码,可以使用该安装方式。
### 安装环境要求
安装前请保证您的电脑上配有JDK>=1.8的运行环境,并配置好JAVA_HOME环境变量。
如果您需要从源码进行编译,还需要安装:
1. Maven>=3.0的运行环境,具体安装方法可以参考以下链接:[https://maven.apache.org/install.html](https://maven.apache.org/install.html)
### 从官网下载二进制可执行文件
您可以从[http://iotdb.apache.org/#/Download](http://iotdb.apache.org/#/Download)上下载已经编译好的可执行程序iotdb-xxx.tar.gz或者iotdb-xxx.zip,该压缩包包含了IoTDB系统运行所需的所有必要组件。
```
NOTE:
iotdb-<version>.tar.gz # For Linux or MacOS
iotdb-<version>.zip # For Windows
```
下载后,您可使用以下操作对IoTDB的压缩包进行解压:
如果您使用的操作系统是Linux或MacOS,则使用如下解压命令:
```
Shell > uzip iotdb-<version>.zip
```
如果您使用的操作系统是Windows,则使用解压缩工具解压或使用如下解压命令:
```
Shell > tar -zxf iotdb-<version>.tar.gz # For Linux or MacOS
```
解压后文件夹内容见图:
```
iotdb/ <-- root path
|
+- bin/ <-- script files
|
+- conf/ <-- configuration files
|
+- lib/ <-- project dependencies
|
+- LICENSE <-- LICENSE
```
### 使用源码编译
您还可以使用从Git仓库克隆源码进行编译的方式安装IoTDB,具体操作步骤如下:
```
Shell > git clone https://github.com/apache/incubator-iotdb.git
```
或者:
```
Shell > git clone git@github.com:apache/incubator-iotdb.git
```
>注意:当前为未发布版本,需要获取权限后才可克隆源码,如需使用源码编译,请联系IoTDB。
步骤三:源码克隆后,进入到源码文件夹目录下,使用以下命令进行编译:
```
> mvn clean package -pl iotdb -am -Dmaven.test.skip=true
```
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
# 第4章 系统部署与管理
## 系统配置
为方便IoTDB Server的配置与管理,IoTDB Server为用户提供三种配置项,使得用户可以在启动服务器或服务器运行时对其进行配置。
三种配置项的配置文件均位于IoTDB安装目录:$IOTDB_HOME/conf文件夹下,其中涉及server配置的共有3个文件,分别为:iotdb-env.sh, tsfile-format.properties, iotdb-engine.properties。用户可以通过更改其中的配置项对系统运行的相关配置项进行配置。
配置文件的说明如下:
* iotdb-env.sh:环境配置项的默认配置文件。用户可以在文件中配置JAVA-JVM的相关系统配置项。
* tsfile-format.properties:IoTDB文件层系统配置项的默认配置文件。用户可以在文件中配置IoTDB存储时TsFile文件的相关信息,如每次将内存中的数据写入到磁盘时的数据大小(group_size_in_byte),内存中每个列打一次包的大小(page_size_in_byte)等。
* iotdb-engine.properties:IoTDB引擎层系统配置项的默认配置文件。用户可以在文件中配置IoTDB引擎运行时的相关参数,如JDBC服务监听端口(rpc_port)、overflow数据文件存储目录(overflow_data_dir)等。
### 环境配置项
环境配置项主要用于对IoTDB Server运行的Java环境相关参数进行配置,如JVM相关配置。IoTDB Server启动时,此部分配置会被传给JVM。用户可以通过查看 iotdb-env.sh(或iotdb-env.bat)文件查看环境配置项内容。详细配置项说明如下:
* JMX\_LOCAL
|名字|JMX\_LOCAL|
|:---:|:---|
|描述|JMX监控模式,配置为yes表示仅允许本地监控,设置为no的时候表示允许远程监控|
|类型|枚举String : “yes”, “no”|
|默认值|yes|
|改后生效方式|重启服务器生效|
* JMX\_PORT
|名字|JMX\_PORT|
|:---:|:---|
|描述|JMX监听端口。请确认该端口不是系统保留端口并且未被占用。|
|类型|Short Int: [0,65535]|
|默认值|31999|
|改后生效方式|重启服务器生效|
* MAX\_HEAP\_SIZE
|名字|MAX\_HEAP\_SIZE|
|:---:|:---|
|描述|IoTDB启动时能使用的最大堆内存大小。|
|类型|String|
|默认值|取决于操作系统和机器配置。在Linux或MacOS系统下默认为机器内存的四分之一。在Windows系统下,32位系统的默认值是512M,64位系统默认值是2G。|
|改后生效方式|重启服务器生效|
* HEAP\_NEWSIZE
|名字|HEAP\_NEWSIZE|
|:---:|:---|
|描述|oTDB启动时能使用的最小堆内存大小。|
|类型|String|
|默认值|取决于操作系统和机器配置。在Linux或MacOS系统下默认值为机器CPU核数乘以100M的值与MAX\_HEAP\_SIZE四分之一这二者的最小值。在Windows系统下,32位系统的默认值是512M,64位系统默认值是2G。。|
|改后生效方式|重启服务器生效|
### 系统配置项
系统配置项是IoTDB Server运行的核心配置,它主要用于设置IoTDB Server文件层和引擎层的参数,便于用户根据自身需求调整Server的相关配置,以达到较好的性能表现。系统配置项可分为两大模块:文件层配置项和引擎层配置项。用户可以通过查看tsfile-format.properties, iotdb-engine.properties,文件查看和修改两种配置项的内容。在0.7.0版本中字符串类型的配置项大小写敏感。
#### 文件层配置
* compressor
|名字|compressor|
|:---:|:---|
|描述|数据压缩方法|
|类型|枚举String : “UNCOMPRESSED”, “SNAPPY”|
|默认值| UNCOMPRESSED |
|改后生效方式|即时生效|
* group\_size\_in\_byte
|名字|group\_size\_in\_byte|
|:---:|:---|
|描述|每次将内存中的数据写入到磁盘时的最大写入字节数|
|类型|Int32|
|默认值| 134217728 |
|改后生效方式|即时生效|
* max\_number\_of\_points\_in\_page
|名字| max\_number\_of\_points\_in\_page |
|:---:|:---|
|描述|一个页中最多包含的数据点(时间戳-值的二元组)数量|
|类型|Int32|
|默认值| 1048576 |
|改后生效方式|即时生效|
* max\_string\_length
|名字| max\_string\_length |
|:---:|:---|
|描述|针对字符串类型的数据,单个字符串最大长度,单位为字符|
|类型|Int32|
|默认值| 128 |
|改后生效方式|即时生效|
* page\_size\_in\_byte
|名字| page\_size\_in\_byte |
|:---:|:---|
|描述|内存中每个列写出时,写成的页单页最大的大小,单位为字节|
|类型|Int32|
|默认值| 134217728 |
|改后生效方式|即时生效|
* time\_series\_data\_类型
|名字| time\_series\_data\_类型 |
|:---:|:---|
|描述|时间戳数据类型|
|类型|枚举String: "INT32", "INT64"|
|默认值| Int64 |
|改后生效方式|即时生效|
* time\_series\_encoder
|名字| time\_series\_data\_类型 |
|:---:|:---|
|描述| 时间列编码方式|
|类型|枚举String: “TS_2DIFF”,“PLAIN”,“RLE”|
|默认值| TS_2DIFF |
|改后生效方式|即时生效|
* float_precision
|名字| float_precision |
|:---:|:---|
|描述| 浮点数精度,为小数点后数字的位数 |
|类型|Int32|
|默认值| 默认为2位。注意:32位浮点数的十进制精度为7位,64位浮点数的十进制精度为15位。如果设置超过机器精度将没有实际意义。|
|改后生效方式|即时生效|
#### 引擎层配置
* back\_loop\_period
|名字| back\_loop\_period |
|:---:|:---|
|描述| 系统统计量触发统计的频率,单位为秒。|
|类型|Int32|
|默认值| 10 |
|改后生效方式|重启服务器生效|
* data\_dir
|名字| data\_dir |
|:---:|:---|
|描述| IoTDB数据存储路径,默认存放在和bin目录同级的data目录下。相对路径的起始目录与操作系统相关,建议使用绝对路径。|
|类型|String|
|默认值| data |
|改后生效方式|重启服务器生效|
* enable_wal
|名字| enable_wal |
|:---:|:---|
|描述| 是否开启写前日志,默认值为true表示开启,配置成false表示关闭 |
|类型|Bool|
|默认值| true |
|改后生效方式|重启服务器生效|
* fetch_size
|名字| fetch_size |
|:---:|:---|
|描述| 批量读取数据的时候,每一次读取数据的数量。单位为数据条数,即不同时间戳的个数。某次会话中,用户可以在使用时自己设定,此时仅在该次会话中生效。|
|类型|Int32|
|默认值| 10000 |
|改后生效方式|重启服务器生效|
* flush\_wal\_period\_in\_ms
|名字| flush\_wal\_period\_in\_ms |
|:---:|:---|
|描述| 写前日志定期刷新到磁盘的周期,单位毫秒,有可能丢失至多flush\_wal\_period\_in\_ms毫秒的操作。 |
|类型|Int32|
|默认值| 10 |
|改后生效方式|重启服务器生效|
* flush\_wal\_threshold
|名字| flush\_wal\_threshold |
|:---:|:---|
|描述| A写前日志的条数达到该值之后,刷新到磁盘,有可能丢失至多flush\_wal\_threshold个操作 |
|类型|Int32|
|默认值| 10000 |
|改后生效方式|重启服务器生效|
* max\_opened\_folder
|名字| max\_opened\_folder |
|:---:|:---|
|描述| 最大同时打开的文件夹个数。默认为100。该值变大,则占用内存变多,IO随机读写变小,文件分块(即group)更加整齐;该值越小,则占用内存越少,IO随机读写变多,文件块大小不足group的概率变大group\_size\_in\_byte * max\_opened\_folder = 内存的最大占用量理论值。对于一个应用,folder的总量等于storage\_group的数量 |
|类型|Int32|
|默认值| 100 |
|改后生效方式|重启服务器生效|
* merge\_concurrent\_threads
|名字| merge\_concurrent\_threads |
|:---:|:---|
|描述| overflow数据进行合并的时候最多可以用来进行merge的线程数。值越大,对IO和CPU消耗越多。值越小,当overflow数据过多时,磁盘占用量越大,读取会变慢。 |
|类型|Int32|
|默认值| 10 |
|改后生效方式|重启服务器生效|
* mult\_dir\_strategy
|名字| mult\_dir\_strategy |
|:---:|:---|
|描述| IoTDB在tsfile\_dir中为TsFile选择目录时采用的策略。可使用简单类名或类名全称。系统提供以下三种策略:<br>1. SequenceStrategy:IoTDB按顺序从tsfile\_dir中选择目录,依次遍历tsfile\_dir中的所有目录,并不断轮循;<br>2. MaxDiskUsableSpaceFirstStrategy:IoTDB优先选择tsfile\_dir中对应磁盘空余空间最大的目录;<br>3. MinFolderOccupiedSpaceFirstStrategy:IoTDB优先选择tsfile\_dir中已使用空间最小的目录;<br>4. <UserDfineStrategyPackage>(用户自定义策略)<br>您可以通过以下方法完成用户自定义策略:<br>1. 继承cn.edu.tsinghua.iotdb.conf.directories.strategy.DirectoryStrategy类并实现自身的Strategy方法;<br>2. 将实现的类的完整类名(包名加类名,UserDfineStrategyPackage)填写到该配置项;<br>3. 将该类jar包添加到工程中。|
|类型|String|
|默认值| MaxDiskUsableSpaceFirstStrategy |
|改后生效方式|重启服务器生效|
* period\_time\_for\_flush\_in\_second
|名字| period\_time\_for\_flush\_in\_second |
|:---:|:---|
|描述| IoTDB定时关闭文件的间隔。单位为秒。每隔设置的时间,系统会自动将内存中的数据刷入磁盘,并将当前打开的所有文件流封口。|
|类型|Int32|
|默认值| 3600 |
|改后生效方式|重启服务器生效|
* period\_time\_for\_merge\_in\_second
|名字| period\_time\_for\_merge\_in\_second |
|:---:|:---|
|描述| IoTDB在运行时有两部分数据存在于内存:overflow和bufferwrite,系统会自动每隔一段时间合并两部分数据。单位为秒。|
|类型|Int32|
|默认值| 7200 |
|改后生效方式|重启服务器生效|
* rpc_address
|名字| rpc_address |
|:---:|:---|
|描述| |
|类型|String|
|默认值| "0.0.0.0" |
|改后生效方式|重启服务器生效|
* rpc_port
|名字| rpc_port |
|:---:|:---|
|描述|jdbc服务监听端口。请确认该端口不是系统保留端口并且未被占用。|
|类型|Short Int : [0,65535]|
|默认值| 6667 |
|改后生效方式|重启服务器生效|
* tsfile_dir
|名字| tsfile_dir |
|:---:|:---|
|描述| IoTDB TsFile的存储路径,默认存放在和bin目录同级的data目录下的settled1、settled2、settled3三个文件夹中(数据分配策略见mult\_dir\_strategy配置项)。相对路径的起始目录与操作系统相关,建议使用绝对路径。若路径不存在,系统会自动创建。|
|类型|String[]|
|默认值| settled1, settled2, settled3 |
|改后生效方式|重启服务器生效|
* wal\_cleanup\_threshold
|名字| wal\_cleanup\_threshold |
|:---:|:---|
|描述| 当文件中和内存中的日志总条数达到该值后,对所有日志进行压缩并去掉无用的记录日志。该值过大会导致短暂的写入暂停,过小会增加IO和CPU消耗 |
|类型|Int32|
|默认值| 500000 |
|改后生效方式|重启服务器生效|
* sys\_dir
|名字| sys\_dir |
|:---:|:---|
|描述| IIoTDB系统元数据存储路径,默认存放在和bin目录同级的data目录下。相对路径的起始目录与操作系统相关,建议使用绝对路径。 |
|类型|String|
|默认值| system |
|改后生效方式|重启服务器生效|
* time_zone
|名字| time_zone |
|:---:|:---|
|描述| 服务器所处的时区,默认为北京时间(东八区) |
|类型|Time Zone String|
|默认值| +08:00 |
|改后生效方式|重启服务器生效|
* enable\_stat\_monitor
|名字| enable\_stat\_monitor |
|:---:|:---|
|描述| 选择是否启动后台统计功能|
|类型| Boolean |
|默认值| true |
|改后生效方式|重启服务器生效|
* mem\_threshold\_warning
|名字| mem\_threshold\_warning |
|:---:|:---|
|描述| 百分比值,这个值乘以IoTDB运行时分配到的最大堆内存值后得到一个阈值。当IoTDB使用内存超过该阈值的时候,将触发把当前内存中的数据写入到磁盘上,并释放相应内存的操作。默认为IoTDB运行时能使用最大堆内存的80%。如果该值配置超过1,那么该配置项将不生效。如果该值小于等于0,那么使用默认值。|
|类型| Float |
|默认值| 0.8 |
|改后生效方式|重启服务器生效|
* mem\_threshold\_dangerous
|名字| mem\_threshold\_dangerous |
|:---:|:---|
|描述| 百分比值,这个值乘以IoTDB运行时分配到的最大堆内存后得到一个阈值。当IoTDB使用内存超过该阈值的时候,将触发把当前内存中的数据写入到磁盘上,并释放相应内存的操作。同时,写入操作将被阻塞。默认为IoTDB运行时能使用最大堆内存的90%。如果该值配置超过1,那么该配置项将不生效。如果该值小于等于0,那么使用默认值。|
|类型| Float |
|默认值| 0.9 |
|改后生效方式|重启服务器生效|
* mem\_monitor\_interval
|名字| mem\_monitor\_interval |
|:---:|:---|
|描述| IoTDB系统每隔一段时间检查当前内存使用情况,如果超过了根据mem\_threshold\_warning或者mem\_threshold\_dangerous计算出来的阈值,将触发相应的操作。单位是为毫秒,默认值是1000毫秒。|
|类型| Int64 |
|默认值| 1000 |
|改后生效方式|重启服务器生效|
* bufferwrite\_meta\_size\_threshold
|名字| bufferwrite\_meta\_size\_threshold |
|:---:|:---|
|描述| 当内存中保存的TsFile文件元数据大小超过该阈值之后,会将元数据保存在TsFile文件尾部,然后关闭该文件,并释放元数据占用的内存空间。单位为byte,默认值为200M。|
|类型| Int64 |
|默认值| 209715200 |
|改后生效方式|重启服务器生效|
* bufferwrite\_file\_size\_threshold
|名字| bufferwrite\_meta\_size\_threshold |
|:---:|:---|
|描述| 当磁盘上的一个TsFile文件大小超过该阈值时,会关闭该TsFile文件。并打开一个新的TsFile文件接受数据写入。单位为byte,默认值为2G。|
|类型| Int64 |
|默认值| 2147483648 |
|改后生效方式|重启服务器生效|
* overflow\_meta\_size\_threshold
|名字| overflow\_meta\_size\_threshold |
|:---:|:---|
|描述| 当内存中保存的Overflow文件元数据大小超过该阈值之后,会将元数据保存在TsFile文件尾部,然后关闭该文件,并释放元数据占用的内存空间。单位为byte,默认值为200M。|
|类型| Int64 |
|默认值| 209715200 |
|改后生效方式|重启服务器生效|
* overflow\_file\_size\_threshold
|名字| overflow\_file\_size\_threshold |
|:---:|:---|
|描述| 当磁盘上的一个Overflow文件大小超过该阈值时,会关闭该Overflow文件。并打开一个新的Overflow文件接受数据写入。单位为byte,默认值为2G。|
|类型| Int64 |
|默认值| 2147483648 |
|改后生效方式|重启服务器生效|
* concurrent\_flush\_thread
|名字| concurrent\_flush\_thread |
|:---:|:---|
|描述| 当IoTDB将内存中的数据写入磁盘时,最多启动多少个线程来执行该操作。如果该值小于等于0,那么采用机器所安装的CPU核的数量。默认值为0。|
|类型| Int32 |
|默认值| 0 |
|改后生效方式|重启服务器生效|
* stat\_monitor\_detect\_freq\_sec
|名字| concurrent\_flush\_thread |
|:---:|:---|
|描述| 每隔一段时间(以秒为单位)检测当前记录统计量时间范围是否超过stat_monitor_retain_interval,并进行定时清理。|
|类型| Int32 |
|默认值|600 |
|改后生效方式|重启服务器生效|
* stat\_monitor\_retain\_interval\_sec
|名字| stat\_monitor\_retain\_interval\_sec |
|:---:|:---|
|描述| 系统统计信息的保留时间(以秒为单位),超过保留时间范围的统计数据将被定时清理。|
|类型| Int32 |
|默认值|600 |
|改后生效方式|重启服务器生效|
\ No newline at end of file
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
# 第4章 系统部署与管理
## 系统监控
当前用户可以使用Java的JConsole工具对正在运行的IoTDB进程进行系统状态监控,或使用IoTDB为用户开放的接口查看数据统计量。
### 系统状态监控
进入Jconsole监控页面后,首先看到的是IoTDB各类运行情况的概览。在这里,您可以看到[堆内存信息、线程信息、类信息以及服务器的CPU使用情况](https://docs.oracle.com/javase/7/docs/technotes/guides/management/jconsole.html)
### 数据统计监控
本模块是IoTDB为用户提供的对其中存储数据信息的数据统计监控方式,我们会在系统中为您记录各个模块的数据统计信息,并将其汇总存入数据库中。当前0.7.0版本的IoTDB提供IoTDB写入数据的统计功能。
用户可以选择开启或关闭数据统计监控功能(您可以设定配置文件中的`enable_stat_monitor`项,详细信息参见本文第5.2.2.2.2节)。
#### 写入数据统计
系统目前对写入数据的统计可分为两大模块: 全局(Global) 写入数据统计和存储组(Storage Group) 写入数据统计。 全局统计量记录了所有写入数据的点数、请求数统计,存储组统计量对某一个存储组的写入数据进行了统计,系统默认设定每 5 秒 (若需更改统计频率,您可以设定配置文件中的`back_loop_period_sec`项,详细信息参见本文[4.2节](/#/Documents/latest/chap4/sec2)) 将统计量写入 IoTDB 中,并以系统指定的命名方式存储。系统刷新或者重启后, IoTDB 不对统计量做恢复处理,统计量从零值重新开始计算。
为了避免统计信息占用过多空间,我们为统计信息加入定期清除无效数据的机制。系统将每隔一段时间删除无效数据。用户可以通过设置删除机制触发频率(`stat_monitor_retain_interval_sec`项,默认为600s,详细信息参见本文[4.2节](/#/Documents/latest/chap4/sec2))配置删除数据的频率,通过设置有效数据的期限(`stat_monitor_detect_freq_sec`项,默认为600s,详细信息参见本文[4.2节](/#/Documents/latest/chap4/sec2))设置有效数据的范围,即距离清除操作触发时间为`stat_monitor_detect_freq_sec`以内的数据为有效数据。为了保证系统的稳定,不允许频繁地删除统计量,因此如果配置参数的时间小于默认值,系统不采用配置参数而使用默认参数。
注:当前 0.7.0 版本统计的写入数据统计信息会同时统计用户写入的数据与系统内部监控数据。
写入数据统计项列表:
* TOTAL_POINTS (全局)
|名字| TOTAL\_POINTS |
|:---:|:---|
|描述| 写入总点数|
|时间序列名称| root.stats.write.global.TOTAL\_POINTS |
|服务器重启后是否重置| 是 |
|例子| select TOTAL_POINTS from root.stats.write.global|
* TOTAL\_REQ\_SUCCESS (全局)
|名字| TOTAL\_REQ\_SUCCESS |
|:---:|:---|
|描述| 写入请求成功次数|
|时间序列名称| root.stats.write.global.TOTAL\_REQ\_SUCCESS |
|服务器重启后是否重置| 是 |
|例子| select TOTAL\_REQ\_SUCCESS from root.stats.write.global|
* TOTAL\_REQ\_FAIL (全局)
|名字| TOTAL\_REQ\_FAIL |
|:---:|:---|
|描述| 写入请求失败次数|
|时间序列名称| root.stats.write.global.TOTAL\_REQ\_FAIL |
|服务器重启后是否重置| 是 |
|例子| select TOTAL\_REQ\_FAIL from root.stats.write.global|
* TOTAL\_POINTS\_FAIL (全局)
|名字| TOTAL\_POINTS\_FAIL |
|:---:|:---|
|描述| 写入点数数百次数|
|时间序列名称| root.stats.write.global.TOTAL\_POINTS\_FAIL |
|服务器重启后是否重置| 是 |
|例子| select TOTAL\_POINTS\_FAIL from root.stats.write.global|
* TOTAL\_POINTS\_SUCCESS (全局)
|名字| TOTAL\_POINTS\_SUCCESS |
|:---:|:---|
|描述| 写入点数成功次数|
|时间序列名称| root.stats.write.global.TOTAL\_POINTS\_SUCCESS |
|服务器重启后是否重置| 是 |
|例子| select TOTAL\_POINTS\_SUCCESS from root.stats.write.global|
* TOTAL\_REQ\_SUCCESS (STORAGE GROUP)
|名字| TOTAL\_REQ\_SUCCESS |
|:---:|:---|
|描述| 写入存储组成功次数|
|时间序列名称| root.stats.write.\<storage\_group\_name\>.TOTAL\_REQ\_SUCCESS |
|服务器重启后是否重置| 是 |
|例子| select TOTAL\_REQ\_SUCCESS from root.stats.write.\<storage\_group\_name\>|
* TOTAL\_REQ\_FAIL (STORAGE GROUP)
|名字| TOTAL\_REQ\_FAIL |
|:---:|:---|
|描述| 写入某个Storage group的请求失败次数|
|时间序列名称| root.stats.write.\<storage\_group\_name\>.TOTAL\_REQ\_FAIL |
|服务器重启后是否重置| 是 |
|例子| select TOTAL\_REQ\_FAIL from root.stats.write.\<storage\_group\_name\>|
* TOTAL\_POINTS\_SUCCESS (STORAGE GROUP)
|名字| TOTAL\_POINTS\_SUCCESS |
|:---:|:---|
|描述| 写入某个Storage group成功的点数|
|时间序列名称| root.stats.write.\<storage\_group\_name\>.TOTAL\_POINTS\_SUCCESS |
|服务器重启后是否重置| 是 |
|例子| select TOTAL\_POINTS\_SUCCESS from root.stats.write.\<storage\_group\_name\>|
* TOTAL\_POINTS\_FAIL (STORAGE GROUP)
|名字| TOTAL\_POINTS\_FAIL |
|:---:|:---|
|描述| 写入某个Storage group失败的点数|
|时间序列名称| root.stats.write.\<storage\_group\_name\>.TOTAL\_POINTS\_FAIL |
|服务器重启后是否重置| 是 |
|例子| select TOTAL\_POINTS\_FAIL from root.stats.write.\<storage\_group\_name\>|
> 其中,\<storage\_group\_name\> 为所需进行数据统计的存储组名称,存储组中的“.”使用“_”代替。例如:名为'root.a.b'的存储组命名为:'root\_a\_b'。
下面为您展示两个具体的例子。用户可以通过`SELECT`语句查询自己所需要的写入数据统计项。(查询方法与普通的时间序列查询方式一致)
我们以查询全局统计量总写入成功数(`TOTAL_POINTS_SUCCES`)为例,用IoTDB SELECT语句查询它的值。SQL语句如下:
```
select TOTAL_POINTS_SUCCESS from root.stats.write.global
```
我们以查询存储组root.ln的统计量总写入成功数(`TOTAL_POINTS_SUCCESS`)为例,用IoTDB SELECT语句查询它的值。SQL语句如下:
```
select TOTAL_POINTS_SUCCESS from root.stats.write.root_ln
```
若您需要查询当前系统的写入统计信息,您可以使用`MAX_VALUE()`聚合函数进行查询,SQL语句如下:
```
select MAX_VALUE(TOTAL_POINTS_SUCCESS) from root.stats.write.root_ln
```
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
# 第4章 系统部署与管理
## 系统日志
IoTDB支持用户通过修改日志配置文件的方式对IoTDB系统日志(如日志输出级别等)进行配置,系统日志配置文件默认位置在$IOTDB_HOME/conf文件夹下,默认的日志配置文件名为logback.xml。用户可以通过增加或更改其中的xml树型节点参数对系统运行日志的相关配置进行修改。需要说明的是,使用日志配置文件对系统日志进行配置并非修改完文件立刻生效,而是重启IoTDB系统后生效。详细配置说明参看本文第5.4.2节日志文件配置说明。
同时,为了方便在系统运行过程中运维人员对系统的调试,我们为系统运维人员提供了动态修改日志配置的JMX接口,能够在系统不重启的前提下实时对系统的Log模块进行配置。详细使用方法参看[动态系统日志配置说明](/#/Documents/latest/chap4/sec4)
### 动态系统日志配置说明
#### 连接JMX
本节以Jconsole为例介绍连接JMX并进入动态系统日志配置模块的方法。启动Jconsole控制页面,在新建连接处建立与IoTDB Server的JMX连接(可以选择本地进程或给定IoTDB的IP及PORT进行远程连接,IoTDB的JMX服务默认运行端口为31999),如下图使用远程进程连接Localhost下运行在31999端口的IoTDB JMX服务。
<img style="width:100%; max-width:800px; max-height:600px; margin-left:auto; margin-right:auto; display:block;" src="https://user-images.githubusercontent.com/13203019/51577195-f94d7500-1ef3-11e9-999a-b4f67055d80e.png">
连接到JMX后,您可以通过MBean选项卡找到名为`ch.qos.logback.classic``MBean`,如下图所示。
<img style="width:100%; max-width:800px; max-height:600px; margin-left:auto; margin-right:auto; display:block;" src="https://user-images.githubusercontent.com/13203019/51577204-fe122900-1ef3-11e9-9e89-2eb1d46e24b8.png">
`ch.qos.logback.classic`的MBean操作(Operations)选项中,可以看到当前动态系统日志配置支持的5种接口,您可以通过使用相应的方法,来执行相应的操作,操作页面如图。
<img style="width:100%; max-width:800px; max-height:600px; margin-left:auto; margin-right:auto; display:block;" src="https://user-images.githubusercontent.com/13203019/51577216-09fdeb00-1ef4-11e9-9005-542ad7d9e9e0.png">
#### 动态系统日志接口说明
* reloadDefaultConfiguration接口
该方法为重新加载默认的logback配置文件,用户可以先对默认的配置文件进行修改,然后调用该方法将修改后的配置文件重新加载到系统中,使其生效。
* reloadByFileName接口
该方法为加载一个指定路径的logback配置文件,并使其生效。该方法接受一个名为p1的String类型的参数,该参数为需要指定加载的配置文件路径。
* getLoggerEffectiveLevel接口
该方法为获取指定Logger当前生效的日志级别。该方法接受一个名为p1的String类型的参数,该参数为指定Logger的名称。该方法返回指定Logger当前生效的日志级别。
* getLoggerLevel接口
该方法为获取指定Logger的日志级别。该方法接受一个名为p1的String类型的参数,该参数为指定Logger的名称。该方法返回指定Logger的日志级别。
需要注意的是,该方法与`getLoggerEffectiveLevel`方法的区别在于,该方法返回的是指定Logger在配置文件中被设定的日志级别,如果用户没有对该Logger进行日志级别的设定,则返回空。按照Logback的日志级别继承机制,如果一个Logger没有被显示地设定日志级别,其将会从其最近的祖先继承日志级别的设定。这时,调用`getLoggerEffectiveLevel`方法将返回该Logger生效的日志级别;而调用本节所述方法,将返回空。
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
# 第4章 系统部署与管理
## 数据管理
本节将介绍IoTDB的数据存储方式,便于您对IoTDB的数据管理有一个直观的了解。
IoTDB需要存储的数据分为三类,分别为数据文件、系统文件以及写前日志文件。
### 数据文件
数据文件存储了用户写入IoTDB系统的所有数据。包含TsFile文件和其他文件,其中,TsFile文件可以通过配置项`tsfile_dir`配置存储路径(详情见[tsfile_dir配置项](/#/Documents/latest/chap4/sec2)),其他文件可通过[data_dir配置项](/#/Documents/latest/chap4/sec2)进行配置。
为了更好的支持用户对于磁盘空间扩展等存储需求,IoTDB为TsFile的存储配置增加了多文件目录的存储方式,用户可自主配置多个存储路径作为数据的持久化位置(详情见[tsfile_dir配置项](/#/Documents/latest/chap4/sec2)),并可以指定或自定义目录选择策略(详情见[mult_dir_strategy配置项](/#/Documents/latest/chap4/sec2))。
### 系统文件
系统文件包括Restore文件和Schema文件,存储了数据文件的元数据信息。可通过sys_dir配置项进行配置(详情见[sys_dir配置项](/#/Documents/latest/chap4/sec2))。
### 写前日志文件
写前日志文件存储了系统的写前日志。可通过`wal_dir`配置项进行配置(详情见[wal_dir配置项](/#/Documents/latest/chap4/sec2))。
### 数据存储目录设置举例
接下来我们将举一个数据目录配置的例子,来具体说明如何配置数据的存储目录。
IoTDB涉及到的所有数据目录路径有:data_dir, tsfile_dir, mult_dir_strategy, sys_dir和wal_dir,它们分别涉及的是IoTDB的数据文件、系统文件以及写前日志文件。您可以选择输入路径自行配置,也可以不进行任何操作使用系统默认的配置项(关于各个配置项的具体内容见本文第5.2.2.2.2节)。
以下我们给出一个用户对五个目录都进行自行配置的例子。
```
data_dir = D:\\iotdb\\data\\data
tsfile_dir = E:\\iotdb\\data\\data1, data\\data2, F:\\data3 
mult_dir_strategy = MaxDiskUsableSpaceFirstStrategy
sys_dir = data\\system
wal_dir = data
```
按照上述配置,系统会:
* 将除TsFile之外的数据文件存储在D:\iotdb\data\data
* 将TsFile存储在路径E:\iotdb\data\data1、路径%IOTDB_HOME%\data\data2和路径F:\data3中。且对这三个路径的选择策略是:`优先选择磁盘剩余空间最大的目录`,即在每次数据持久化到磁盘时系统会自动选择磁盘剩余空间最大的一个目录将数据进行写入
* 将TsFile之外的其他数据文件存储在路径D:\\iotdb\\data\\data中
* 将系统文件存储在%IOTDB_HOME%\data\system
* 将写前日志文件存储在%IOTDB_HOME%\data
> 如果对上述TsFile的目录进行了修改,那么需要将旧目录中的所有TsFile移动到新的目录中,并且要严格按照目录的顺序。
> 如果您在TsFile的目录中增加了新路径,那么IoTDB会直接将该目录纳入到多目录选择的范围中,用户无需有其他的操作。
例如,将tsfile_dir修改为
```
D:\\data4, E:\\data5, F:\\data6
```
那么就需要将E:\iotdb\data\data1中的文件移动到D:\data4,%IOTDB_HOME%\data\data2的文件移动到E:\data5,F:\data3的文件移动到F:\data6。系统即可继续正常运行。
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
# 第4章 系统部署与管理
Coming Soon.
\ No newline at end of file
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
# 第5章: IoTDB SQL文档
## IoTDB查询语句
### Schema语句
* 设置存储组
``` SQL
SET STORAGE GROUP TO <PrefixPath>
Eg: IoTDB > SET STORAGE GROUP TO root.ln.wf01.wt01
Note: PrefixPath can not include `*`
```
* 创建时间序列语句
```
CREATE TIMESERIES <Timeseries> WITH <AttributeClauses>
AttributeClauses : DATATYPE=<DataTypeValue> COMMA ENCODING=<EncodingValue> [COMMA <ExtraAttributeClause>]*
DataTypeValue: BOOLEAN | DOUBLE | FLOAT | INT32 | INT64 | TEXT
EncodingValue: GORILLA | PLAIN | RLE | TS_2DIFF
ExtraAttributeClause: {
COMPRESSOR = <CompressorValue>
MAX_POINT_NUMBER = Integer
}
CompressorValue: UNCOMPRESSED | SNAPPY
Eg: IoTDB > CREATE TIMESERIES root.ln.wf01.wt01.status WITH DATATYPE=BOOLEAN, ENCODING=PLAIN
Eg: IoTDB > CREATE TIMESERIES root.ln.wf01.wt01.temperature WITH DATATYPE=FLOAT, ENCODING=RLE
Eg: IoTDB > CREATE TIMESERIES root.ln.wf01.wt01.temperature WITH DATATYPE=FLOAT, ENCODING=RLE, COMPRESSOR=SNAPPY, MAX_POINT_NUMBER=3
Note: Datatype and encoding type must be corresponding. Please check Chapter 3 Encoding Section for details.
```
* 删除时间序列语句
```
DELETE TIMESERIES <PrefixPath> [COMMA <PrefixPath>]*
Eg: IoTDB > DELETE TIMESERIES root.ln.wf01.wt01.status
Eg: IoTDB > DELETE TIMESERIES root.ln.wf01.wt01.status, root.ln.wf01.wt01.temperature
Eg: IoTDB > DELETE TIMESERIES root.ln.wf01.wt01.*
```
* 显示所有时间序列语句
```
SHOW TIMESERIES
Eg: IoTDB > SHOW TIMESERIES
Note: This statement can only be used in IoTDB Client. If you need to show all timeseries in JDBC, please use `DataBaseMetadata` interface.
```
* 显示特定时间序列语句
```
SHOW TIMESERIES <Path>
Eg: IoTDB > SHOW TIMESERIES root
Eg: IoTDB > SHOW TIMESERIES root.ln
Eg: IoTDB > SHOW TIMESERIES root.ln.*.*.status
Eg: IoTDB > SHOW TIMESERIES root.ln.wf01.wt01.status
Note: The path can be prefix path, star path or timeseries path
Note: This statement can be used in IoTDB Client and JDBC.
```
* 显示存储组语句
```
SHOW STORAGE GROUP
Eg: IoTDB > SHOW STORAGE GROUP
Note: This statement can be used in IoTDB Client and JDBC.
```
### 数据管理语句
* 插入记录语句
```
INSERT INTO <PrefixPath> LPAREN TIMESTAMP COMMA <Sensor> [COMMA <Sensor>]* RPAREN VALUES LPAREN <TimeValue>, <PointValue> [COMMA <PointValue>]* RPAREN
Sensor : Identifier
Eg: IoTDB > INSERT INTO root.ln.wf01.wt01(timestamp,status) values(1509465600000,true)
Eg: IoTDB > INSERT INTO root.ln.wf01.wt01(timestamp,status) VALUES(NOW(), false)
Eg: IoTDB > INSERT INTO root.ln.wf01.wt01(timestamp,temperature) VALUES(2017-11-01T00:17:00.000+08:00,24.22028)
Eg: IoTDB > INSERT INTO root.ln.wf01.wt01(timestamp, status, temperature) VALUES (1509466680000, false, 20.060787);
Note: the statement needs to satisfy this constraint: <PrefixPath> + <Path> = <Timeseries>
Note: The order of Sensor and PointValue need one-to-one correspondence
```
* 更新记录语句
```
UPDATE <UpdateClause> SET <SetClause> WHERE <WhereClause>
UpdateClause: <prefixPath>
SetClause: <SetExpression>
SetExpression: <Path> EQUAL <PointValue>
WhereClause : <Condition> [(AND | OR) <Condition>]*
Condition : <Expression> [(AND | OR) <Expression>]*
Expression : [NOT | !]? TIME PrecedenceEqualOperator <TimeValue>
Eg: IoTDB > UPDATE root.ln.wf01.wt01 SET temperature = 23 WHERE time < NOW() and time > 2017-11-1T00:15:00+08:00
Note: the statement needs to satisfy this constraint: <PrefixPath> + <Path> = <Timeseries>
```
* 删除记录语句
```
DELETE FROM <PrefixPath> [COMMA <PrefixPath>]* WHERE TIME LESSTHAN <TimeValue>
Eg: DELETE FROM root.ln.wf01.wt01.temperature WHERE time < 2017-11-1T00:05:00+08:00
Eg: DELETE FROM root.ln.wf01.wt01.status, root.ln.wf01.wt01.temperature WHERE time < NOW()
Eg: DELETE FROM root.ln.wf01.wt01.* WHERE time < 1509466140000
```
* 选择记录语句
```
SELECT <SelectClause> FROM <FromClause> [WHERE <WhereClause>]?
SelectClause : <SelectPath> (COMMA <SelectPath>)*
SelectPath : <FUNCTION> LPAREN <Path> RPAREN | <Path>
FUNCTION : ‘COUNT’ , ‘MIN_TIME’, ‘MAX_TIME’, ‘MIN_VALUE’, ‘MAX_VALUE’
FromClause : <PrefixPath> (COMMA <PrefixPath>)?
WhereClause : <Condition> [(AND | OR) <Condition>]*
Condition : <Expression> [(AND | OR) <Expression>]*
Expression : [NOT | !]? <TimeExpr> | [NOT | !]? <SensorExpr>
TimeExpr : TIME PrecedenceEqualOperator <TimeValue>
SensorExpr : (<Timeseries> | <Path>) PrecedenceEqualOperator <PointValue>
Eg: IoTDB > SELECT status, temperature FROM root.ln.wf01.wt01 WHERE temperature < 24 and time > 2017-11-1 0:13:00
Eg. IoTDB > SELECT * FROM root
Eg. IoTDB > SELECT COUNT(temperature) FROM root.ln.wf01.wt01 WHERE root.ln.wf01.wt01.temperature < 25
Eg. IoTDB > SELECT MIN_TIME(temperature) FROM root.ln.wf01.wt01 WHERE root.ln.wf01.wt01.temperature < 25
Eg. IoTDB > SELECT MAX_TIME(temperature) FROM root.ln.wf01.wt01 WHERE root.ln.wf01.wt01.temperature > 24
Eg. IoTDB > SELECT MIN_VALUE(temperature) FROM root.ln.wf01.wt01 WHERE root.ln.wf01.wt01.temperature > 23
Eg. IoTDB > SELECT MAX_VALUE(temperature) FROM root.ln.wf01.wt01 WHERE root.ln.wf01.wt01.temperature < 25
Note: the statement needs to satisfy this constraint: <Path>(SelectClause) + <PrefixPath>(FromClause) = <Timeseries>
Note: If the <SensorExpr>(WhereClause) is started with <Path> and not with ROOT, the statement needs to satisfy this constraint: <PrefixPath>(FromClause) + <Path>(SensorExpr) = <Timeseries>
Note: In Version 0.7.0, if <WhereClause> includes `OR`, time filter can not be used.
```
* Group By语句
```
SELECT <SelectClause> FROM <FromClause> WHERE <WhereClause> GROUP BY <GroupByClause>
SelectClause : <Function> [COMMA < Function >]*
Function : <AggregationFunction> LPAREN <Path> RPAREN
FromClause : <PrefixPath>
WhereClause : <Condition> [(AND | OR) <Condition>]*
Condition : <Expression> [(AND | OR) <Expression>]*
Expression : [NOT | !]? <TimeExpr> | [NOT | !]? <SensorExpr>
TimeExpr : TIME PrecedenceEqualOperator <TimeValue>
SensorExpr : (<Timeseries> | <Path>) PrecedenceEqualOperator <PointValue>
GroupByClause : LPAREN <TimeUnit> (COMMA TimeValue)? COMMA <TimeInterval> (COMMA <TimeInterval>)* RPAREN
TimeUnit : Integer <DurationUnit>
DurationUnit : "ms" | "s" | "m" | "h" | "d" | "w"
TimeInterval: LBRACKET <TimeValue> COMMA <TimeValue> RBRACKET
Eg: SELECT COUNT(status), COUNT(temperature) FROM root.ln.wf01.wt01 where temperature < 24 GROUP BY(5m, [1509465720000, 1509466380000])
Eg. SELECT COUNT (status), MAX_VALUE(temperature) FROM root.ln.wf01.wt01 WHERE time < 1509466500000 GROUP BY(5m, 1509465660000, [1509465720000, 1509466380000])
Eg. SELECT MIN_TIME(status), MIN_VALUE(temperature) FROM root.ln.wf01.wt01 WHERE temperature < 25 and time < 1509466800000 GROUP BY (3m, 1509465600000, [1509466140000, 1509466380000], [1509466440000, 1509466620000])
Note: the statement needs to satisfy this constraint: <Path>(SelectClause) + <PrefixPath>(FromClause) = <Timeseries>
Note: If the <SensorExpr>(WhereClause) is started with <Path> and not with ROOT, the statement needs to satisfy this constraint: <PrefixPath>(FromClause) + <Path>(SensorExpr) = <Timeseries>
Note: <TimeValue>(TimeInterval) needs to be greater than 0
Note: First <TimeValue>(TimeInterval) in needs to be smaller than second <TimeValue>(TimeInterval)
```
* Fill语句
```
SELECT <SelectClause> FROM <FromClause> WHERE <WhereClause> FILL <FillClause>
SelectClause : <Path> [COMMA <Path>]*
FromClause : < PrefixPath > [COMMA < PrefixPath >]*
WhereClause : <WhereExpression>
WhereExpression : TIME EQUAL <TimeValue>
FillClause : LPAREN <TypeClause> [COMMA <TypeClause>]* RPAREN
TypeClause : <Int32Clause> | <Int64Clause> | <FloatClause> | <DoubleClause> | <BoolClause> | <TextClause>
Int32Clause: INT32 LBRACKET (<LinearClause> | <PreviousClause>) RBRACKET
Int64Clause: INT64 LBRACKET (<LinearClause> | <PreviousClause>) RBRACKET
FloatClause: FLOAT LBRACKET (<LinearClause> | <PreviousClause>) RBRACKET
DoubleClause: DOUBLE LBRACKET (<LinearClause> | <PreviousClause>) RBRACKET
BoolClause: BOOLEAN LBRACKET (<LinearClause> | <PreviousClause>) RBRACKET
TextClause: TEXT LBRACKET (<LinearClause> | <PreviousClause>) RBRACKET
PreviousClause : PREVIOUS [COMMA <ValidPreviousTime>]?
LinearClause : LINEAR [COMMA <ValidPreviousTime> COMMA <ValidBehindTime>]?
ValidPreviousTime, ValidBehindTime: <TimeUnit>
TimeUnit : Integer <DurationUnit>
DurationUnit : "ms" | "s" | "m" | "h" | "d" | "w"
Eg: SELECT temperature FROM root.ln.wf01.wt01 WHERE time = 2017-11-01T16:37:50.000 FILL(float[previous, 1m])
Eg: SELECT temperature,status FROM root.ln.wf01.wt01 WHERE time = 2017-11-01T16:37:50.000 FILL (float[linear, 1m, 1m], boolean[previous, 1m])
Eg: SELECT temperature,status,hardware FROM root.ln.wf01.wt01 WHERE time = 2017-11-01T16:37:50.000 FILL (float[linear, 1m, 1m], boolean[previous, 1m], text[previous])
Eg: SELECT temperature,status,hardware FROM root.ln.wf01.wt01 WHERE time = 2017-11-01T16:37:50.000 FILL (float[linear], boolean[previous, 1m], text[previous])
Note: the statement needs to satisfy this constraint: <PrefixPath>(FromClause) + <Path>(SelectClause) = <Timeseries>
Note: Integer in <TimeUnit> needs to be greater than 0
```
* Limit语句
```
SELECT <SelectClause> FROM <FromClause> [WHERE <WhereClause>] [LIMIT <LIMITClause>] [SLIMIT <SLIMITClause>]
SelectClause : [<Path> | Function]+
Function : <AggregationFunction> LPAREN <Path> RPAREN
FromClause : <Path>
WhereClause : <Condition> [(AND | OR) <Condition>]*
Condition : <Expression> [(AND | OR) <Expression>]*
Expression: [NOT|!]?<TimeExpr> | [NOT|!]?<SensorExpr>
TimeExpr : TIME PrecedenceEqualOperator <TimeValue>
SensorExpr : (<Timeseries>|<Path>) PrecedenceEqualOperator <PointValue>
LIMITClause : <N> [OFFSETClause]?
N : NonNegativeInteger
OFFSETClause : OFFSET <OFFSETValue>
OFFSETValue : NonNegativeInteger
SLIMITClause : <SN> [SOFFSETClause]?
SN : NonNegativeInteger
SOFFSETClause : SOFFSET <SOFFSETValue>
SOFFSETValue : NonNegativeInteger
NonNegativeInteger:= ('+')? Digit+
Eg: IoTDB > SELECT status, temperature FROM root.ln.wf01.wt01 WHERE temperature < 24 and time > 2017-11-1 0:13:00 LIMIT 3 OFFSET 2
Eg. IoTDB > SELECT COUNT (status), MAX_VALUE(temperature) FROM root.ln.wf01.wt01 WHERE time < 1509466500000 GROUP BY(5m, 1509465660000, [1509465720000, 1509466380000]) LIMIT 3
Note: The order of <LIMITClause> and <SLIMITClause> does not affect the grammatical correctness.
Note: <SLIMITClause> can only effect in Prefixpath and StarPath.
Note: <FillClause> can not use <LIMITClause> but not <SLIMITClause>.
```
### 数据库管理语句
* 创建用户
```
CREATE USER <userName> <password>;
userName:=identifier
password:=identifier
Eg: IoTDB > CREATE USER thulab pwd;
```
* 删除用户
```
DROP USER <userName>;
userName:=identifier
Eg: IoTDB > DROP USER xiaoming;
```
* 创建角色
```
CREATE ROLE <roleName>;
roleName:=identifie
Eg: IoTDB > CREATE ROLE admin;
```
* 删除角色
```
DROP ROLE <roleName>;
roleName:=identifier
Eg: IoTDB > DROP ROLE admin;
```
* 赋予用户权限
```
GRANT USER <userName> PRIVILEGES <privileges> ON <nodeName>;
userName:=identifier
nodeName:=identifier (DOT identifier)*
privileges:= string (COMMA string)*
Eg: IoTDB > GRANT USER tempuser PRIVILEGES 'DELETE_TIMESERIES' on root.ln;
```
* 赋予角色权限
```
GRANT ROLE <roleName> PRIVILEGES <privileges> ON <nodeName>;
privileges:= string (COMMA string)*
roleName:=identifier
nodeName:=identifier (DOT identifier)*
Eg: IoTDB > GRANT ROLE temprole PRIVILEGES 'DELETE_TIMESERIES' ON root.ln;
```
* 赋予用户角色
```
GRANT <roleName> TO <userName>;
roleName:=identifier
userName:=identifier
Eg: IoTDB > GRANT temprole TO tempuser;
```
* 撤销用户权限
```
REVOKE USER <userName> PRIVILEGES <privileges> ON <nodeName>;
privileges:= string (COMMA string)*
userName:=identifier
nodeName:=identifier (DOT identifier)*
Eg: IoTDB > REVOKE USER tempuser PRIVILEGES 'DELETE_TIMESERIES' on root.ln;
```
* 撤销角色权限
```
REVOKE ROLE <roleName> PRIVILEGES <privileges> ON <nodeName>;
privileges:= string (COMMA string)*
roleName:= identifier
nodeName:=identifier (DOT identifier)*
Eg: IoTDB > REVOKE ROLE temprole PRIVILEGES 'DELETE_TIMESERIES' ON root.ln;
```
* 撤销用户角色
```
REVOKE <roleName> FROM <userName>;
roleName:=identifier
userName:=identifier
Eg: IoTDB > REVOKE temproleFROM tempuser;
```
* 列出用户
```
LIST USER
Eg: IoTDB > LIST USER
```
* 列出角色
```
LIST ROLE
Eg: IoTDB > LIST ROLE
```
* 列出权限
```
LIST PRIVILEGES USER <username> ON <path>;
username:=identifier
path=‘root’ (DOT identifier)*
Eg: IoTDB > LIST PRIVIEGES USER sgcc_wirte_user ON root.sgcc;
```
* 列出角色权限
```
LIST PRIVILEGES ROLE <roleName> ON <path>;
roleName:=identifier
path=‘root’ (DOT identifier)*
Eg: IoTDB > LIST PRIVIEGES ROLE wirte_role ON root.sgcc;
```
* 列出用户权限
```
LIST USER PRIVILEGES <username> ;
username:=identifier
Eg: IoTDB > LIST USER PRIVIEGES tempuser;
```
* 列出角色权限
```
LIST ROLE PRIVILEGES <roleName>
roleName:=identifier
Eg: IoTDB > LIST ROLE PRIVIEGES actor;
```
* 列出用户角色
```
LIST ALL ROLE OF USER <username> ;
username:=identifier
Eg: IoTDB > LIST ALL ROLE OF USER tempuser;
```
* 列出角色用户
```
LIST ALL USER OF ROLE <roleName>;
roleName:=identifier
Eg: IoTDB > LIST ALL USER OF ROLE roleuser;
```
* 更新密码
```
UPDATE USER <username> SET PASSWORD <password>;
roleName:=identifier
password:=identifier
Eg: IoTDB > UPDATE USER tempuser SET PASSWORD newpwd;
```
### 功能
* COUNT
```
SELECT COUNT(Path) (COMMA COUNT(Path))* FROM <FromClause> [WHERE <WhereClause>]?
Eg. SELECT COUNT(status), COUNT(temperature) FROM root.ln.wf01.wt01 WHERE root.ln.wf01.wt01.temperature < 24
Note: the statement needs to satisfy this constraint: <PrefixPath> + <Path> = <Timeseries>
```
* FIRST
```
SELECT FIRST (Path) (COMMA FIRST (Path))* FROM <FromClause> [WHERE <WhereClause>]?
Eg. SELECT FIRST (status), FIRST (temperature) FROM root.ln.wf01.wt01 WHERE root.ln.wf01.wt01.temperature < 24
Note: the statement needs to satisfy this constraint: <PrefixPath> + <Path> = <Timeseries>
```
* MAX_TIME
```
SELECT MAX_TIME (Path) (COMMA MAX_TIME (Path))* FROM <FromClause> [WHERE <WhereClause>]?
Eg. SELECT MAX_TIME(status), MAX_TIME(temperature) FROM root.ln.wf01.wt01 WHERE root.ln.wf01.wt01.temperature < 24
Note: the statement needs to satisfy this constraint: <PrefixPath> + <Path> = <Timeseries>
```
* MAX_VALUE
```
SELECT MAX_VALUE (Path) (COMMA MAX_VALUE (Path))* FROM <FromClause> [WHERE <WhereClause>]?
Eg. SELECT MAX_VALUE(status), MAX_VALUE(temperature) FROM root.ln.wf01.wt01 WHERE root.ln.wf01.wt01.temperature < 24
Note: the statement needs to satisfy this constraint: <PrefixPath> + <Path> = <Timeseries>
```
* MEAN
```
SELECT MEAN (Path) (COMMA MEAN (Path))* FROM <FromClause> [WHERE <WhereClause>]?
Eg. SELECT MEAN (temperature) FROM root.ln.wf01.wt01 WHERE root.ln.wf01.wt01.temperature < 24
Note: the statement needs to satisfy this constraint: <PrefixPath> + <Path> = <Timeseries>
```
* MIN_TIME
```
SELECT MIN_TIME (Path) (COMMA MIN_TIME (Path))*FROM <FromClause> [WHERE <WhereClause>]?
Eg. SELECT MIN_TIME(status), MIN_TIME(temperature) FROM root.ln.wf01.wt01 WHERE root.ln.wf01.wt01.temperature < 24
Note: the statement needs to satisfy this constraint: <PrefixPath> + <Path> = <Timeseries>
```
* MIN_VALUE
```
SELECT MIN_VALUE (Path) (COMMA MIN_VALUE (Path))* FROM <FromClause> [WHERE <WhereClause>]?
Eg. SELECT MIN_VALUE(status),MIN_VALUE(temperature) FROM root.ln.wf01.wt01 WHERE root.ln.wf01.wt01.temperature < 24
Note: the statement needs to satisfy this constraint: <PrefixPath> + <Path> = <Timeseries>
```
* NOW
```
NOW()
Eg. INSERT INTO root.ln.wf01.wt01(timestamp,status) VALUES(NOW(), false)
Eg. UPDATE root.ln.wf01.wt01 SET temperature = 23 WHERE time < NOW()
Eg. DELETE FROM root.ln.wf01.wt01.status, root.ln.wf01.wt01.temperature WHERE time < NOW()
Eg. SELECT * FROM root WHERE time < NOW()
Eg. SELECT COUNT(temperature) FROM root.ln.wf01.wt01 WHERE time < NOW()
```
* SUM
```
SELECT SUM(Path) (COMMA SUM(Path))* FROM <FromClause> [WHERE <WhereClause>]?
Eg. SELECT SUM(temperature) FROM root.ln.wf01.wt01 WHERE root.ln.wf01.wt01.temperature < 24
Note: the statement needs to satisfy this constraint: <PrefixPath> + <Path> = <Timeseries>
```
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
# 第5章: IoTDB SQL文档
## 参考
### 关键字
```
Keywords for IoTDB (case insensitive):
ADD, BY, COMPRESSOR, CREATE, DATATYPE, DELETE, DESCRIBE, DROP, ENCODING, EXIT, FROM, GRANT, GROUP, LABLE, LINK, INDEX, INSERT, INTO, LOAD, MAX_POINT_NUMBER, MERGE, METADATA, ON, ORDER, PASSWORD, PRIVILEGES, PROPERTY, QUIT, REVOKE, ROLE, ROOT, SELECT, SET, SHOW, STORAGE, TIME, TIMESERIES, TIMESTAMP, TO, UNLINK, UPDATE, USER, USING, VALUE, VALUES, WHERE, WITH
Keywords with special meanings (case sensitive):
* Data Types: BOOLEAN, DOUBLE, FLOAT, INT32, INT64, TEXT (Only capitals is acceptable)
* Encoding Methods: BITMAP, DFT, GORILLA, PLAIN, RLE, TS_2DIFF (Only capitals is acceptable)
* Compression Methods: UNCOMPRESSED, SNAPPY (Only capitals is acceptable)
* Logical symbol: AND, &, &&, OR, | , ||, NOT, !, TRUE, FALSE
```
### 标识符
```
QUOTE := '\'';
DOT := '.';
COLON : ':' ;
COMMA := ',' ;
SEMICOLON := ';' ;
LPAREN := '(' ;
RPAREN := ')' ;
LBRACKET := '[';
RBRACKET := ']';
EQUAL := '=' | '==';
NOTEQUAL := '<>' | '!=';
LESSTHANOREQUALTO := '<=';
LESSTHAN := '<';
GREATERTHANOREQUALTO := '>=';
GREATERTHAN := '>';
DIVIDE := '/';
PLUS := '+';
MINUS := '-';
STAR := '*';
Letter := 'a'..'z' | 'A'..'Z';
HexDigit := 'a'..'f' | 'A'..'F';
Digit := '0'..'9';
Boolean := TRUE | FALSE | 0 | 1 (case insensitive)
```
```
StringLiteral := ( '\'' ( ~('\'') )* '\'' | '\"' ( ~('\"') )* '\"');
eg. ‘abc’
eg. “abc”
```
```
Integer := ('-' | '+')? Digit+;
eg. 123
eg. -222
```
```
Float := ('-' | '+')? Digit+ DOT Digit+ (('e' | 'E') ('-' | '+')? Digit+)?;
eg. 3.1415
eg. 1.2E10
eg. -1.33
```
```
Identifier := (Letter | '_') (Letter | Digit | '_' | MINUS)*;
eg. a123
eg. _abc123
```
### 常量
```
PointValue : Integer | Float | StringLiteral | Boolean
```
```
TimeValue : Integer | DateTime | ISO8601 | NOW()
Note: Integer means timestamp type.
DateTime :
eg. 2016-11-16T16:22:33+08:00
eg. 2016-11-16 16:22:33+08:00
eg. 2016-11-16T16:22:33.000+08:00
eg. 2016-11-16 16:22:33.000+08:00
Note: DateTime Type can support several types, see Chapter 3 Datetime section for details.
```
```
PrecedenceEqualOperator : EQUAL | NOTEQUAL | LESSTHANOREQUALTO | LESSTHAN | GREATERTHANOREQUALTO | GREATERTHAN
```
```
Timeseries : ROOT [DOT <LayerName>]* DOT <SensorName>
LayerName : Identifier
SensorName : Identifier
eg. root.ln.wf01.wt01.status
eg. root.sgcc.wf03.wt01.temperature
Note: Timeseries must be start with `root`(case insensitive) and end with sensor name.
```
```
PrefixPath : ROOT (DOT <LayerName>)*
LayerName : Identifier | STAR
eg. root.sgcc
eg. root.*
```
```
Path: (ROOT | <LayerName>) (DOT <LayerName>)*
LayerName: Identifier | STAR
eg. root.ln.wf01.wt01.status
eg. root.*.wf01.wt01.status
eg. root.ln.wf01.wt01.*
eg. *.wt01.*
eg. *
```
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
# 第6章: JDBC API
Comming Soon.
\ No newline at end of file
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
# Cli / Shell工具
IOTDB为用户提供CLI/Shell工具用于启动客户端和服务端程序。下面介绍每个CLI/Shell工具的运行方式和相关参数。
> \$IOTDB\_HOME表示IoTDB的安装目录所在路径。
## Cli / Shell运行方式
安装后的IoTDB中有一个默认用户:`root`,默认密码为`root`。用户可以使用该用户尝试运行IoTDB客户端以测试服务器是否正常启动。客户端启动脚本为$IOTDB_HOME/bin文件夹下的`start-client`脚本。启动脚本时需要指定运行IP和PORT。以下为服务器在本机启动,且用户未更改运行端口号的示例,默认端口为6667。若用户尝试连接远程服务器或更改了服务器运行的端口号,请在-h和-p项处使用服务器的IP和PORT。
Linux系统与MacOS系统启动命令如下:
```
Shell > ./bin/start-client.sh -h 127.0.0.1 -p 6667 -u root -pw root
```
Windows系统启动命令如下:
```
Shell > \bin\start-client.bat -h 127.0.0.1 -p 6667 -u root -pw root
```
回车后即可成功启动客户端。启动后出现如图提示即为启动成功。
```
_____ _________ ______ ______
|_ _| | _ _ ||_ _ `.|_ _ \
| | .--.|_/ | | \_| | | `. \ | |_) |
| | / .'`\ \ | | | | | | | __'.
_| |_| \__. | _| |_ _| |_.' /_| |__) |
|_____|'.__.' |_____| |______.'|_______/ version <version>
IoTDB> login successfully
IoTDB>
```
输入`quit``exit`可退出Client结束本次会话,Client输出`quit normally`表示退出成功。
## Cli / Shell运行参数
|参数名|参数类型|是否为必需参数| 说明| 例子 |
|:---|:---|:---|:---|:---|
|-disableIS08601 |没有参数 | 否 |如果设置了这个参数,IoTDB将以数字的形式打印时间戳(timestamp)。|-disableIS08601|
|-h <`host`> |string类型,不需要引号|是|IoTDB客户端连接IoTDB服务器的IP地址。|-h 10.129.187.21|
|-help|没有参数|否|打印IoTDB的帮助信息|-help|
|-p <`port`>|int类型|是|IoTDB连接服务器的端口号,IoTDB默认运行在6667端口。|-p 6667|
|-pw <`password`>|string类型,不需要引号|否|IoTDB连接服务器所使用的密码。如果没有输入密码IoTDB会在Cli端提示输入密码。|-pw root|
|-u <`username`>|string类型,不需要引号|是|IoTDB连接服务器锁使用的用户名。|-u root|
|-maxPRC <`maxPrintRowCount`>|int类型|否|设置IoTDB返回客户端命令行中所显示的最大行数。|-maxPRC 10|
下面展示一条客户端命令,功能是连接IP为10.129.187.21的主机,端口为6667 ,用户名为root,密码为root,以数字的形式打印时间戳,IoTDB命令行显示的最大行数为10。
Linux系统与MacOS系统启动命令如下:
```
Shell >./bin/start-client.sh -h 10.129.187.21 -p 6667 -u root -pw root -disableIS08601 -maxPRC 10
```
Windows系统启动命令如下:
```
Shell > \bin\start-client.bat -h 10.129.187.21 -p 6667 -u root -pw root -disableIS08601 -maxPRC 10
```
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
# IoTDB-Grafana
Grafana是开源的指标量监测和可视化工具,可用于展示时序数据和应用程序运行分析。Grafana支持Graphite,InfluxDB等国际主流时序时序数据库作为数据源。在IoTDB项目中,我们开发了Grafana展现IoTDB中时序数据的连接器IoTDB-Grafana,为您提供使用Grafana展示IoTDB数据库中的时序数据的可视化方法。
## Grafana的安装与部署
### 安装
* Grafana组件下载地址:https://grafana.com/grafana/download
* 版本 >= 4.4.1
### simple-json-datasource数据源插件安装
* 插件名称: simple-json-datasource
* 下载地址: https://github.com/grafana/simple-json-datasource
具体下载方法是:到Grafana的插件目录中:`{Grafana文件目录}/data/plugin/`(Windows系统,启动Grafana后会自动创建`data/plugin`目录)或`/var/lib/grafana/plugins` (Linux系统,plugins目录需要手动创建)或`/usr/local/var/lib/grafana/plugins`(MacOS系统,具体位置参看使用`brew install`安装Grafana后命令行给出的位置提示。
执行下面的命令:
```
Shell > git clone https://github.com/grafana/simple-json-datasource.git
```
然后重启Grafana服务器,在浏览器中登录Grafana,在“Add data source”页面中“Type”选项出现“SimpleJson”即为安装成功。
### 启动Grafana
进入Grafana的安装目录,使用以下命令启动Grafana:
* Windows系统:
```
Shell > bin\grafana-server.exe
```
* Linux系统:
```
Shell > sudo service grafana-server start
```
* MacOS系统:
```
Shell > grafana-server --config=/usr/local/etc/grafana/grafana.ini --homepath /usr/local/share/grafana cfg:default.paths.logs=/usr/local/var/log/grafana cfg:default.paths.data=/usr/local/var/lib/grafana cfg:default.paths.plugins=/usr/local/var/lib/grafana/plugins
```
## IoTDB安装
参见[https://github.com/apache/incubator-iotdb](https://github.com/apache/incubator-iotdb)
## IoTDB-Grafana连接器安装
```shell
git clone https://github.com/apache/incubator-iotdb.git
mvn clean package -pl grafana -am -Dmaven.test.skip=true
cd grafana
```
编译成功后,您需将`application.properties`文件从`conf/`目录复制到`target/`目录下,并在该文件中插入以下(编辑属性值):
```
# ip and port of IoTDB
spring.datasource.url = jdbc:iotdb://127.0.0.1:6667/
spring.datasource.username = root
spring.datasource.password = root
spring.datasource.driver-class-name=org.apache.iotdb.jdbc.IoTDBDriver
server.port = 8888
```
### 启动IoTDB-Grafana
```shell
cd grafana/target/
java -jar iotdb-grafana-{version}-SNAPSHOT.war
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.5.4.RELEASE)
...
```
## 使用Grafana
Grafana以网页的dashboard形式为您展示数据,在使用时请您打开浏览器,访问http://\<ip\>:\<port\>
注:IP为您的Grafana所在的服务器IP,Port为Grafana的运行端口(默认3000)。默认登录的用户名和密码都是“admin”。
### 添加IoTDB数据源
点击左上角的“Grafana”图标,选择`Data Source`选项,然后再点击`Add data source`
<img style="width:100%; max-width:800px; max-height:600px; margin-left:auto; margin-right:auto; display:block;" src="https://user-images.githubusercontent.com/13203019/51664777-2766ae00-1ff5-11e9-9d2f-7489f8ccbfc2.png">
在编辑数据源的时候,`Type`一栏选择`Simplejson``URL`一栏填写http://\<ip\>:\<port\>,IP为您的IoTDB-Grafana连接器所在的服务器IP,Port为运行端口(默认8888)。之后确保IoTDB已经启动,点击“Save & Test”,出现“Data Source is working”提示表示配置成功。
<img style="width:100%; max-width:800px; max-height:600px; margin-left:auto; margin-right:auto; display:block;" src="https://user-images.githubusercontent.com/13203019/51664842-554bf280-1ff5-11e9-97d2-54eebe0b2ca1.png">
### 操作Grafana
进入Grafana可视化页面后,可以选择添加时间序列,如图 6.9。您也可以按照Grafana官方文档进行相应的操作,详情可参看Grafana官方文档:http://docs.grafana.org/guides/getting_started/。
<img style="width:100%; max-width:800px; max-height:600px; margin-left:auto; margin-right:auto; display:block;" src="https://user-images.githubusercontent.com/13203019/51664878-6e54a380-1ff5-11e9-9718-4d0e24627fa8.png">
\ No newline at end of file
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
# TsFile-Hadoop-Connector User Guide
Comming Soon.
\ No newline at end of file
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
# TsFile-Spark-Connector User Guide
Comming Soon.
\ No newline at end of file
......@@ -169,7 +169,7 @@ IoTDB can support LONG types and DATETIME-DISPLAY types when displaying timestam
* Value
The value of a time series is actually the value sent by a sensor to IoTDB. This value can be stored by IoTDB according to the data type. At the same time, users can select the compression mode and the corresponding encoding mode according to the data type of this value. See [Data Type](#data-type) and [Encoding](#encoding) of this document for details on data type and corresponding encoding.
The value of a time series is actually the value sent by a sensor to IoTDB. This value can be stored by IoTDB according to the data type. At the same time, users can select the compression mode and the corresponding encoding mode according to the data type of this value. See [Data Type](/#/Documents/latest/chap2/sec2) and [Encoding](/#/Documents/latest/chap2/sec3) of this document for details on data type and corresponding encoding.
* Point
......
......@@ -25,7 +25,7 @@
IoTDB supports six data types in total: BOOLEAN (Boolean), INT32 (Integer), INT64 (Long Integer), FLOAT (Single Precision Floating Point), DOUBLE (Double Precision Floating Point), TEXT (String).
The time series of FLOAT and DOUBLE type can specify (MAX\_POINT\_NUMBER, see [this page](#iotdb-query-statement) for more information on how to specify), which is the number of digits after the decimal point of the floating point number, if the encoding method is [RLE](#encoding) or [TS\_2DIFF](#encoding) (Refer to [Create Timeseries Statement](#chapter-5-iotdb-sql-documentation) for more information on how to specify). If MAX\_POINT\_NUMBER is not specified, the system will use [float\_precision](#encoding) in the configuration file "tsfile-format.properties" for configuration for the configuration method.
The time series of FLOAT and DOUBLE type can specify (MAX\_POINT\_NUMBER, see [this page](/#/Documents/latest/chap5/sec1) for more information on how to specify), which is the number of digits after the decimal point of the floating point number, if the encoding method is [RLE](/#/Documents/latest/chap2/sec3) or [TS\_2DIFF](/#/Documents/latest/chap2/sec3) (Refer to [Create Timeseries Statement](/#/Documents/latest/chap5/sec1) for more information on how to specify). If MAX\_POINT\_NUMBER is not specified, the system will use [float\_precision](/#/Documents/latest/chap2/sec3) in the configuration file "tsfile-format.properties" for configuration for the configuration method.
* For Float data value, The data range is (-Integer.MAX_VALUE, Integer.MAX_VALUE), rather than Float.MAX_VALUE, and the max_point_number is 19, it is because of the limition of function Math.round(float) in Java.
* For Double data value, The data range is (-Long.MAX_VALUE, Long.MAX_VALUE), rather than Double.MAX_VALUE, and the max_point_number is 19, it is because of the limition of function Math.round(double) in Java (Long.MAX_VALUE=9.22E18).
......
......@@ -32,13 +32,13 @@ PLAIN encoding, the default encoding mode, i.e, no encoding, supports multiple d
Second-order differential encoding is more suitable for encoding monotonically increasing or decreasing sequence data, and is not recommended for sequence data with large fluctuations.
Second-order differential encoding can also be used to encode floating-point numbers, but it is necessary to specify reserved decimal digits (MAX\_POINT\_NUMBER, see [this page](#iotdb-query-statement) for more information on how to specify) when creating time series. It is more suitable for storing sequence data where floating-point values appear continuously, monotonously increase or decrease, and it is not suitable for storing sequence data with high precision requirements after the decimal point or with large fluctuations.
Second-order differential encoding can also be used to encode floating-point numbers, but it is necessary to specify reserved decimal digits (MAX\_POINT\_NUMBER, see [this page](/#/Documents/latest/chap5/sec1) for more information on how to specify) when creating time series. It is more suitable for storing sequence data where floating-point values appear continuously, monotonously increase or decrease, and it is not suitable for storing sequence data with high precision requirements after the decimal point or with large fluctuations.
* RLE
Run-length encoding is more suitable for storing sequence with continuous integer values, and is not recommended for sequence data with most of the time different values.
Run-length encoding can also be used to encode floating-point numbers, but it is necessary to specify reserved decimal digits (MAX\_POINT\_NUMBER, see [this page](#iotdb-query-statement) for more information on how to specify) when creating time series. It is more suitable for storing sequence data where floating-point values appear continuously, monotonously increase or decrease, and it is not suitable for storing sequence data with high precision requirements after the decimal point or with large fluctuations.
Run-length encoding can also be used to encode floating-point numbers, but it is necessary to specify reserved decimal digits (MAX\_POINT\_NUMBER, see [this page](/#/Documents/latest/chap5/sec1) for more information on how to specify) when creating time series. It is more suitable for storing sequence data where floating-point values appear continuously, monotonously increase or decrease, and it is not suitable for storing sequence data with high precision requirements after the decimal point or with large fluctuations.
* GORILLA
......
......@@ -25,4 +25,4 @@
When the time series is written and encoded as binary data according to the specified type, IoTDB compresses the data using compression technology to further improve space storage efficiency. Although both encoding and compression are designed to improve storage efficiency, encoding techniques are usually only available for specific data types (e.g., second-order differential encoding is only suitable for INT32 or INT64 data type, and storing floating-point numbers requires multiplying them by 10m to convert to integers), after which the data is converted to a binary stream. The compression method (SNAPPY) compresses the binary stream, so the use of the compression method is no longer limited by the data type.
IoTDB allows you to specify the compression method of the column when creating a time series. IoTDB now supports two kinds of compression: UNCOMPRESSED (no compression) and SNAPPY compression. The specified syntax for compression is detailed in [Create Timeseries Statement](#chapter-5-iotdb-sql-documentation).
\ No newline at end of file
IoTDB allows you to specify the compression method of the column when creating a time series. IoTDB now supports two kinds of compression: UNCOMPRESSED (no compression) and SNAPPY compression. The specified syntax for compression is detailed in [Create Timeseries Statement](/#/Documents/latest/chap5/sec1).
\ No newline at end of file
......@@ -23,6 +23,6 @@
## Sample Data
To make this manual more practical, we will use a specific scenario example to illustrate how to operate IoTDB databases at all stages of use. See [this page](Material-SampleData) for a look. For your convenience, we also provide you with a sample data file in real scenario to import into the IoTDB system for trial and operation.
To make this manual more practical, we will use a specific scenario example to illustrate how to operate IoTDB databases at all stages of use. See [this page](https://github.com/apache/incubator-iotdb/blob/master/docs/Documentation/OtherMaterial-Sample%20Data.txt) for a look. For your convenience, we also provide you with a sample data file in real scenario to import into the IoTDB system for trial and operation.
Download file: [IoTDB-SampleData.txt](sampledata文件下载链接).
Download file: [IoTDB-SampleData.txt](https://raw.githubusercontent.com/apache/incubator-iotdb/master/docs/Documentation/OtherMaterial-Sample%20Data.txt).
......@@ -23,10 +23,10 @@
## Data Model Selection
Before importing data to IoTDB, we first select the appropriate data storage model according to the [sample data](Material-SampleData), and then create the storage group and timeseries using [SET STORAGE GROUP](Chapter5,setstoragegroup) statement and [CREATE TIMESERIES](Chapter5,createtimeseries) statement respectively.
Before importing data to IoTDB, we first select the appropriate data storage model according to the [sample data](/#/Documents/latest/chap3/sec1), and then create the storage group and timeseries using [SET STORAGE GROUP](/#/Documents/latest/chap5/sec1) statement and [CREATE TIMESERIES](/#/Documents/latest/chap5/sec1) statement respectively.
### Storage Model Selection
According to the data attribute layers described in [sample data](Material-SampleData), we can express it as an attribute hierarchy structure based on the coverage of attributes and the subordinate relationship between them, as shown in Figure 3.1 below. Its hierarchical relationship is: power group layer - power plant layer - device layer - sensor layer. ROOT is the root node, and each node of sensor layer is called a leaf node. In the process of using IoTDB, you can directly connect the attributes on the path from ROOT node to each leaf node with ".", thus forming the name of a timeseries in IoTDB. For example, The left-most path in Figure 3.1 can generate a timeseries named `ROOT.ln.wf01.wt01.status`.
According to the data attribute layers described in [sample data](/#/Documents/latest/chap3/sec1), we can express it as an attribute hierarchy structure based on the coverage of attributes and the subordinate relationship between them, as shown in Figure 3.1 below. Its hierarchical relationship is: power group layer - power plant layer - device layer - sensor layer. ROOT is the root node, and each node of sensor layer is called a leaf node. In the process of using IoTDB, you can directly connect the attributes on the path from ROOT node to each leaf node with ".", thus forming the name of a timeseries in IoTDB. For example, The left-most path in Figure 3.1 can generate a timeseries named `ROOT.ln.wf01.wt01.status`.
<center><img style="width:100%; max-width:800px; max-height:600px; margin-left:auto; margin-right:auto; display:block;" src="https://user-images.githubusercontent.com/13203019/51577327-7aa50780-1ef4-11e9-9d75-cadabb62444e.jpg">
......@@ -52,7 +52,7 @@ error: The prefix of root.ln.wf01 has been set to the storage group.
```
### Show Storage Group
After the storage group is created, we can use the [SHOW STORAGE GROUP](Chapter5,showstoragegroup) statement to view all the storage groups. The SQL statement is as follows:
After the storage group is created, we can use the [SHOW STORAGE GROUP](/#/Documents/latest/chap5/sec1) statement to view all the storage groups. The SQL statement is as follows:
```
IoTDB> show storage group
......@@ -80,7 +80,7 @@ IoTDB> create timeseries root.ln.wf02.wt02.status WITH DATATYPE=BOOLEAN, ENCODIN
error: encoding TS_2DIFF does not support BOOLEAN
```
Please refer to [Encoding](Chapter2,encoding) for correspondence between data type and encoding.
Please refer to [Encoding](/#/Documents/latest/chap2/sec3) for correspondence between data type and encoding.
### Show Timeseries
......@@ -110,6 +110,6 @@ Msg: Failed to fetch timeseries root.ln.wf03's metadata because: Timeseries does
Version 0.7.0 imposes some limitations on the scale of data that users can operate:
Limit 1: Assuming that the JVM memory allocated to IoTDB at runtime is p and the user-defined size of data in memory written to disk ([group\_size\_in\_byte](Chap4group_size_in_byte)) is Q, then the number of storage groups should not exceed p/q.
Limit 1: Assuming that the JVM memory allocated to IoTDB at runtime is p and the user-defined size of data in memory written to disk ([group\_size\_in\_byte](/#/Documents/latest/chap4/sec2)) is Q, then the number of storage groups should not exceed p/q.
Limit 2: The number of timeseries should not exceed the ratio of JVM memory allocated to IoTDB at run time to 20KB.
......@@ -28,12 +28,12 @@ This feature is not supported in version 0.7.0.
### Import Real-time Data
IoTDB provides users with a variety of ways to insert real-time data, such as directly inputting [INSERT SQL statement](chapter5.InsertRecordStatement) in [Cli/Shell tools](cli-page), or using [Java JDBC](Java-api-page,commingsoon) to perform single or batch execution of [INSERT SQL statement](chapter5.InsertRecordStatement).
IoTDB provides users with a variety of ways to insert real-time data, such as directly inputting [INSERT SQL statement](/#/Documents/latest/chap5/sec1) in [Cli/Shell tools](/#/Tools/Cli), or using [Java JDBC](/#/Documents/latest/chap6/sec1) to perform single or batch execution of [INSERT SQL statement](/#/Documents/latest/chap5/sec1).
This section mainly introduces the use of [INSERT SQL statement](chapter5.InsertRecordStatement) for real-time data import in the scenario. See Section 7.1.3.1 for a detailed syntax of [INSERT SQL statement](chapter5.InsertRecordStatement).
This section mainly introduces the use of [INSERT SQL statement](/#/Documents/latest/chap5/sec1) for real-time data import in the scenario. See Section 7.1.3.1 for a detailed syntax of [INSERT SQL statement](/#/Documents/latest/chap5/sec1).
#### Use of INSERT Statements
The [INSERT SQL statement](chapter5.InsertRecordStatement) statement can be used to insert data into one or more specified timeseries that have been created. For each point of data inserted, it consists of a [timestamp](chap2,timestamp) and a sensor acquisition value of a numerical type (see [Data Type](Chapter2datatype)).
The [INSERT SQL statement](/#/Documents/latest/chap5/sec1) statement can be used to insert data into one or more specified timeseries that have been created. For each point of data inserted, it consists of a [timestamp](/#/Documents/latest/chap2/sec1) and a sensor acquisition value of a numerical type (see [Data Type](/#/Documents/latest/chap2/sec2)).
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.
......
......@@ -24,7 +24,7 @@
## Data Query
### Time Slice Query
This chapter mainly introduces the relevant examples of time slice query using IoTDB SELECT statements. Detailed SQL syntax and usage specifications can be found in [SQL Documentation](Chpater5). You can also use the [Java JDBC](Java-api-page,commingsoon) standard interface to execute related queries.
This chapter mainly introduces the relevant examples of time slice query using IoTDB SELECT statements. Detailed SQL syntax and usage specifications can be found in [SQL Documentation](/#/Documents/latest/chap5/sec1). You can also use the [Java JDBC](/#/Documents/latest/chap6/sec1) standard interface to execute related queries.
#### Select a Column of Data Based on a Time Interval
......@@ -83,7 +83,7 @@ The execution result of this SQL statement is as follows:
<center><img style="width:100%; max-width:800px; max-height:600px; margin-left:auto; margin-right:auto; display:block;" src="https://user-images.githubusercontent.com/13203019/51577450-dcfe0800-1ef4-11e9-9399-4ba2b2b7fb73.jpg"></center>
### Down-Frequency Aggregate Query
This section mainly introduces the related examples of down-frequency aggregation query, using the [GROUP BY clause](Chap5-groupbystatement), which is used to partition the result set according to the user's given partitioning conditions and aggregate the partitioned result set. IoTDB supports partitioning result sets according to time intervals, and by default results are sorted by time in ascending order. You can also use the [Java JDBC](Java-api-page,commingsoon) standard interface to execute related queries.
This section mainly introduces the related examples of down-frequency aggregation query, using the [GROUP BY clause](/#/Documents/latest/chap5/sec1), which is used to partition the result set according to the user's given partitioning conditions and aggregate the partitioned result set. IoTDB supports partitioning result sets according to time intervals, and by default results are sorted by time in ascending order. You can also use the [Java JDBC](/#/Documents/latest/chap6/sec1) standard interface to execute related queries.
The GROUP BY statement provides users with three types of specified parameters:
......@@ -199,7 +199,7 @@ which means:
Because the timeseries root.sgcc.wf03.wt01.temperature is null at 2017-11-01T16:37:50.000, the system uses the previous timestamp of 2017-11-01T16:37:50.000 (and the timestamp is in the [2017-11-01T16:36:50.000, 2017-11-01T16:37:50.000] time range) for fill and display.
On the [sample data](Material-SampleData), the execution result of this statement is shown below:
On the [sample data](/#/Documents/latest/chap3/sec1), the execution result of this statement is shown below:
<center><img style="width:100%; max-width:800px; max-height:600px; margin-left:auto; margin-right:auto; display:block;" src="https://user-images.githubusercontent.com/13203019/51577616-67df0280-1ef5-11e9-9dff-2eb8342074eb.jpg"></center>
It is worth noting that if there is no value in the specified valid time range, the system will not fill the null value, as shown below:
......@@ -233,7 +233,7 @@ which means:
Because the timeseries root.sgcc.wf03.wt01.temperature is null at 2017-11-01T16:37:50.000, the system uses the previous timestamp 2017-11-01T16:37:00.000 (and the timestamp is in the [2017-11-01T16:36:50.000, 2017-11-01T16:37:50.000] time range) and its value 21.927326, the next timestamp 2017-11-01T16:39:00.000 (and the timestamp is in the [2017-11-01T16:36:50.000, 2017-11-01T16:37:50.000] time range) and its value 25.311783 to perform linear fitting calculation: 21.927326 + (25.311783-21.927326)/60s*50s = 24.747707
On the [sample data](Material-SampleData), the execution result of this statement is shown below:
On the [sample data](/#/Documents/latest/chap3/sec1), the execution result of this statement is shown below:
<center><img style="width:100%; max-width:800px; max-height:600px; margin-left:auto; margin-right:auto; display:block;" src="https://user-images.githubusercontent.com/13203019/51577727-d4f29800-1ef5-11e9-8ff3-3bb519da3993.jpg"></center>
#### Correspondence between Data Type and Fill Method
......@@ -273,9 +273,9 @@ When the fill method is not specified, each data type bears its own default fill
### Row and Column Control over Query Results
IoTDB provides [LIMIT/SLIMIT](Chpater5,LimitStatement) clause and [OFFSET/SOFFSET](Chpater5,LimitStatement) clause in order to make users have more control over query results. The use of LIMIT and SLIMIT clauses allows users to control the number of rows and columns of query results, and the use of OFFSET and SOFSET clauses allows users to set the starting position of the results for display.
IoTDB provides [LIMIT/SLIMIT](/#/Documents/latest/chap5/sec1) clause and [OFFSET/SOFFSET](/#/Documents/latest/chap5/sec1) clause in order to make users have more control over query results. The use of LIMIT and SLIMIT clauses allows users to control the number of rows and columns of query results, and the use of OFFSET and SOFSET clauses allows users to set the starting position of the results for display.
This chapter mainly introduces related examples of row and column control of query results. You can also use the [Java JDBC](Java-api-page,commingsoon) standard interface to execute queries.
This chapter mainly introduces related examples of row and column control of query results. You can also use the [Java JDBC](/#/Documents/latest/chap6/sec1) standard interface to execute queries.
#### Row Control over Query Results
By using LIMIT and OFFSET clauses, users can control the query results in a row-related manner. We will demonstrate how to use LIMIT and OFFSET clauses through the following examples.
......
......@@ -24,9 +24,9 @@
## Data Maintenance
### Data Update
Users can use [UPDATE statements](Chap5,updatestatement) to update data over a period of time in a specified timeseries. When updating data, users can select a timeseries to be updated (version 0.7.0 does not support multiple timeseries updates) and specify a time point or period to be updated (version 0.7.0 must have time filtering conditions).
Users can use [UPDATE statements](/#/Documents/latest/chap5/sec1) to update data over a period of time in a specified timeseries. When updating data, users can select a timeseries to be updated (version 0.7.0 does not support multiple timeseries updates) and specify a time point or period to be updated (version 0.7.0 must have time filtering conditions).
In a JAVA programming environment, you can use the [Java JDBC](Java-api-page,commingsoon) to execute single or batch UPDATE statements.
In a JAVA programming environment, you can use the [Java JDBC](/#/Documents/latest/chap6/sec1) to execute single or batch UPDATE statements.
#### Update Single Timeseries
Taking the power supply status of ln group wf02 plant wt02 device as an example, there exists such a usage scenario:
......@@ -50,9 +50,9 @@ error: do not select any existing path
```
### Data Deletion
Users can delete data that meet the deletion condition in the specified timeseries by using the [DELETE statement](Chap5,deletestatement). When deleting data, users can select one or more timeseries paths, prefix paths, or paths with star to delete data before a certain time (version 0.7.0 does not support the deletion of data within a closed time interval).
Users can delete data that meet the deletion condition in the specified timeseries by using the [DELETE statement](/#/Documents/latest/chap5/sec1). When deleting data, users can select one or more timeseries paths, prefix paths, or paths with star to delete data before a certain time (version 0.7.0 does not support the deletion of data within a closed time interval).
In a JAVA programming environment, you can use the [Java JDBC](Java-api-page,commingsoon) to execute single or batch UPDATE statements.
In a JAVA programming environment, you can use the [Java JDBC](/#/Documents/latest/chap6/sec1) to execute single or batch UPDATE statements.
#### Delete Single Timeseries
Taking ln Group as an example, there exists such a usage scenario:
......
......@@ -24,7 +24,7 @@
## Priviledge Management
IoTDB provides users with priviledge management operations, so as to ensure data security.
We will show you basic user priviledge management operations through the following specific examples. Detailed SQL syntax and usage details can be found in [Chapter5.SQL Documentation](chap5). At the same time, in the JAVA programming environment, you can use the [Java JDBC](Java-api-page,commingsoon) to execute priviledge management statements in a single or batch mode.
We will show you basic user priviledge management operations through the following specific examples. Detailed SQL syntax and usage details can be found in [Chapter 5: SQL Documentation](/#/Documents/latest/chap5/sec1). At the same time, in the JAVA programming environment, you can use the [Java JDBC](/#/Documents/latest/chap6/sec1) to execute priviledge management statements in a single or batch mode.
### Basic Concepts
#### User
......@@ -40,7 +40,7 @@ A role is a set of priviledges and has a unique role name as an identifier. A us
There is a default user in IoTDB after the initial installation: root, and the default password is root. This user is an administrator user, who cannot be deleted and has all the priviledges. Neither can new priviledges be granted to the root user nor can priviledges owned by the root user be deleted.
### Priviledge Management Operation Examples
According to the [sample data](material-sampledata), the sample data of IoTDB may belong to different power generation groups such as ln, sgcc, etc. Different power generation groups do not want others to obtain their own database data, so we need to have data priviledge isolated at the group layer.
According to the [sample data](/#/Documents/latest/chap3/sec1), the sample data of IoTDB may belong to different power generation groups such as ln, sgcc, etc. Different power generation groups do not want others to obtain their own database data, so we need to have data priviledge isolated at the group layer.
#### Create User
......
......@@ -206,7 +206,7 @@ The detail of each variables are as follows:
|Name| data\_dirs |
|:---:|:---|
|Description| The directories of data files. Multiple directories are separated by comma. See the [mult\_dir\_strategy](chapter4,multdirstrategy) configuration item for data distribution strategy. The starting directory of the relative path is related to the operating system. It is recommended to use an absolute path. If the path does not exist, the system will automatically create it.|
|Description| The directories of data files. Multiple directories are separated by comma. See the [mult\_dir\_strategy](/#/Documents/latest/chap4/sec2) configuration item for data distribution strategy. The starting directory of the relative path is related to the operating system. It is recommended to use an absolute path. If the path does not exist, the system will automatically create it.|
|Type|String[]|
|Default| data/data |
|Effective|After restart system|
......
......@@ -150,15 +150,15 @@ There are several attributes under Monitor, including the numbers of files opene
This module is the statistical monitoring method provided by IoTDB for users to store data information. We will record the statistical data in the system and store it in the database. The current 0.7.0 version of IoTDB provides statistics for writing data.
The user can choose to enable or disable the data statistics monitoring function (set the `enable_stat_monitor` item in the configuration file, see [Engine Layer](chapter4,enginelayer) for details).
The user can choose to enable or disable the data statistics monitoring function (set the `enable_stat_monitor` item in the configuration file, see [Engine Layer](/#/Documents/latest/chap4/sec2) for details).
#### Writing Data Monitor
The current statistics of writing data by the system can be divided into two major modules: **Global Writing Data Statistics** and **Storage Group Writing Data Statistics**. **Global Writing Data Statistics** records the point number written by the user and the number of requests. **Storage Group Writing Data Statistics** records data of a certain storage group.
The system defaults to collect data every 5 seconds, and writes the statistics to the IoTDB and stores them in a system-specified locate. (If you need to change the statistic frequency, you can set The `back_loop_period_sec entry` in the configuration file, see Section [Engine Layer](chapter4,enginelayer) for details). After the system is refreshed or restarted, IoTDB does not recover the statistics, and the statistics data will restart from zero.
The system defaults to collect data every 5 seconds, and writes the statistics to the IoTDB and stores them in a system-specified locate. (If you need to change the statistic frequency, you can set The `back_loop_period_sec entry` in the configuration file, see Section [Engine Layer](/#/Documents/latest/chap4/sec2) for details). After the system is refreshed or restarted, IoTDB does not recover the statistics, and the statistics data will restart from zero.
In order to avoid the excessive use of statistical information, we add a mechanism to periodically clear invalid data for statistical information. The system will delete invalid data at regular intervals. The user can set the trigger frequency (`stat_monitor_retain_interval_sec`, default is 600s, see section [Engine Layer](chapter4,enginelayer) for details) to set the frequency of deleting data. By setting the valid data duration (`stat_monitor_detect_freq_sec entry`, the default is 600s, see section [Engine Layer](chapter4,enginelayer) for details) to set the time period of valid data, that is, the data within the time of the clear operation trigger time is stat_monitor_detect_freq_sec is valid data. In order to ensure the stability of the system, it is not allowed to delete the statistics frequently. Therefore, if the configuration parameter time is less than the default value (600s), the system will abort the configuration parameter and uses the default parameter.
In order to avoid the excessive use of statistical information, we add a mechanism to periodically clear invalid data for statistical information. The system will delete invalid data at regular intervals. The user can set the trigger frequency (`stat_monitor_retain_interval_sec`, default is 600s, see section [Engine Layer](/#/Documents/latest/chap4/sec2) for details) to set the frequency of deleting data. By setting the valid data duration (`stat_monitor_detect_freq_sec entry`, the default is 600s, see section [Engine Layer](/#/Documents/latest/chap4/sec2) for details) to set the time period of valid data, that is, the data within the time of the clear operation trigger time is stat_monitor_detect_freq_sec is valid data. In order to ensure the stability of the system, it is not allowed to delete the statistics frequently. Therefore, if the configuration parameter time is less than the default value (600s), the system will abort the configuration parameter and uses the default parameter.
It's convenient for you to use `select` clause to get the writing data statistics the same as other timeseires.
......
......@@ -27,7 +27,7 @@ IoTDB allows users to configure IoTDB system logs (such as log output level) by
The default log configuration file is named logback.xml. The user can modify the configuration of the system running log by adding or changing the xml tree node parameters. It should be noted that the configuration of the system log using the log configuration file does not take effect immediately after the modification, instead, it will take effect after restarting the system. The usage of logback.xml is just as usual.
At the same time, in order to facilitate the debugging of the system by the developers and DBAs, we provide several JMX interface to dynamically modify the log configuration, and configure the Log module of the system in real time without restarting the system. For detailed usage, see [Dynamic System Log Configuration](Chap4dynamicsystemlog) section.
At the same time, in order to facilitate the debugging of the system by the developers and DBAs, we provide several JMX interface to dynamically modify the log configuration, and configure the Log module of the system in real time without restarting the system. For detailed usage, see [Dynamic System Log Configuration](/#/Documents/latest/chap4/sec4) section.
### Dynamic System Log Configuration
......
......@@ -30,17 +30,17 @@ The data that IoTDB stores is divided into three categories, namely data files,
### Data Files
Data files store all the data that the user wrote to IoTDB, which contains TsFile and other files. TsFile storage directory can be configured with the `tsfile_dir` configuration item (see [file layer](Chap4filelayer) for details). Other files can be configured through [data_dir](chap4datadir) configuration item (see [Engine Layer](chapter4,enginelayer) for details).
Data files store all the data that the user wrote to IoTDB, which contains TsFile and other files. TsFile storage directory can be configured with the `tsfile_dir` configuration item (see [file layer](/#/Documents/latest/chap4/sec2) for details). Other files can be configured through [data_dir](/#/Documents/latest/chap4/sec2) configuration item (see [Engine Layer](/#/Documents/latest/chap4/sec2) for details).
In order to better support users' storage requirements such as disk space expansion, IoTDB supports multiple file directorys storage methods for TsFile storage configuration. Users can set multiple storage paths as data storage locations( see [tsfile_dir](Chap4,tsfiledir) configuration item), and you can specify or customize the directory selection policy (see [mult_dir_strategy](chapter4,enginelayer) configuration item for details).
In order to better support users' storage requirements such as disk space expansion, IoTDB supports multiple file directorys storage methods for TsFile storage configuration. Users can set multiple storage paths as data storage locations( see [tsfile_dir](/#/Documents/latest/chap4/sec2) configuration item), and you can specify or customize the directory selection policy (see [mult_dir_strategy](/#/Documents/latest/chap4/sec2) configuration item for details).
### System Files
System files include restore files and schema files, which store metadata information of data in IoTDB. It can be configured through the `sys_dir` configuration item (see [System Layer](chapter4,systemlayer) for details).
System files include restore files and schema files, which store metadata information of data in IoTDB. It can be configured through the `sys_dir` configuration item (see [System Layer](/#/Documents/latest/chap4/sec2) for details).
### Pre-write Log Files
Pre-write log files store WAL files. It can be configured through the `wal_dir` configuration item (see [System Layer](chapter4,systemlayer) for details).
Pre-write log files store WAL files. It can be configured through the `wal_dir` configuration item (see [System Layer](/#/Documents/latest/chap4/sec2) for details).
### Example of Setting Data storage Directory
......
......@@ -19,4 +19,6 @@
-->
# Chaper6: JDBC API
\ No newline at end of file
# Chaper6: JDBC API
Comming Soon.
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册