diff --git a/src/.vuepress/sidebar/V1.3.x/en.ts b/src/.vuepress/sidebar/V1.3.x/en.ts index 7192865a8..2a4dcadb5 100644 --- a/src/.vuepress/sidebar/V1.3.x/en.ts +++ b/src/.vuepress/sidebar/V1.3.x/en.ts @@ -87,8 +87,16 @@ export const enSidebar = { }, ], }, - { text: 'Write & Delete', link: 'Write-Delete-Data' }, + { text: 'Write Data', link: 'Write-Data' }, { text: 'Query Data', link: 'Query-Data' }, + { + text: 'Delete Data', + collapsible: true, + children: [ + { text: 'Delete Data', link: 'Delete-Data' }, + { text: 'TTL Delete Data', link: 'TTL-Delete' }, + ], + }, ], }, { diff --git a/src/.vuepress/sidebar/V1.3.x/zh.ts b/src/.vuepress/sidebar/V1.3.x/zh.ts index 11fd28f48..bba878fda 100644 --- a/src/.vuepress/sidebar/V1.3.x/zh.ts +++ b/src/.vuepress/sidebar/V1.3.x/zh.ts @@ -76,8 +76,16 @@ export const zhSidebar = { { text: '测点管理', link: 'Operate-Metadata_apache' }, ], }, - { text: '写入&删除', link: 'Write-Delete-Data' }, + { text: '数据写入', link: 'Write-Data' }, { text: '数据查询', link: 'Query-Data' }, + { + text: '数据删除', + collapsible: true, + children: [ + { text: '数据删除', link: 'Delete-Data' }, + { text: '自动过期删除', link: 'TTL-Delete' }, + ], + }, ], }, { diff --git a/src/.vuepress/sidebar/V2.0.x/en-Tree.ts b/src/.vuepress/sidebar/V2.0.x/en-Tree.ts index abc4c9b42..c811aafe2 100644 --- a/src/.vuepress/sidebar/V2.0.x/en-Tree.ts +++ b/src/.vuepress/sidebar/V2.0.x/en-Tree.ts @@ -79,8 +79,16 @@ export const enSidebar = { text: 'Data Modeling', link: 'Operate-Metadata_apache', }, - { text: 'Write & Delete', link: 'Write-Delete-Data' }, + { text: 'Write Data', link: 'Write-Data' }, { text: 'Query Data', link: 'Query-Data' }, + { + text: 'Delete Data', + collapsible: true, + children: [ + { text: 'Delete Data', link: 'Delete-Data' }, + { text: 'TTL Delete Data', link: 'TTL-Delete' }, + ], + }, ], }, { diff --git a/src/.vuepress/sidebar/V2.0.x/zh-Tree.ts b/src/.vuepress/sidebar/V2.0.x/zh-Tree.ts index 7ef8114f0..d647a2824 100644 --- a/src/.vuepress/sidebar/V2.0.x/zh-Tree.ts +++ b/src/.vuepress/sidebar/V2.0.x/zh-Tree.ts @@ -68,8 +68,16 @@ export const zhSidebar = { prefix: 'Basic-Concept/', children: [ { text: '测点管理', link: 'Operate-Metadata_apache' }, - { text: '写入&删除', link: 'Write-Delete-Data' }, + { text: '数据写入', link: 'Write-Data' }, { text: '数据查询', link: 'Query-Data' }, + { + text: '数据删除', + collapsible: true, + children: [ + { text: '数据删除', link: 'Delete-Data' }, + { text: '自动过期删除', link: 'TTL-Delete' }, + ], + }, ], }, { diff --git a/src/.vuepress/sidebar_timecho/V1.3.x/en.ts b/src/.vuepress/sidebar_timecho/V1.3.x/en.ts index 80a59e57c..8c838d83a 100644 --- a/src/.vuepress/sidebar_timecho/V1.3.x/en.ts +++ b/src/.vuepress/sidebar_timecho/V1.3.x/en.ts @@ -96,8 +96,16 @@ export const enSidebar = { }, ], }, - { text: 'Write & Delete', link: 'Write-Delete-Data' }, + { text: 'Write Data', link: 'Write-Data' }, { text: 'Query Data', link: 'Query-Data' }, + { + text: 'Delete Data', + collapsible: true, + children: [ + { text: 'Delete Data', link: 'Delete-Data' }, + { text: 'TTL Delete Data', link: 'TTL-Delete' }, + ], + }, ], }, { diff --git a/src/.vuepress/sidebar_timecho/V1.3.x/zh.ts b/src/.vuepress/sidebar_timecho/V1.3.x/zh.ts index 443f24dbc..52ebf6fa5 100644 --- a/src/.vuepress/sidebar_timecho/V1.3.x/zh.ts +++ b/src/.vuepress/sidebar_timecho/V1.3.x/zh.ts @@ -79,8 +79,16 @@ export const zhSidebar = { { text: '测点管理', link: 'Operate-Metadata_timecho' }, ], }, - { text: '写入&删除', link: 'Write-Delete-Data' }, + { text: '数据写入', link: 'Write-Data' }, { text: '数据查询', link: 'Query-Data' }, + { + text: '数据删除', + collapsible: true, + children: [ + { text: '数据删除', link: 'Delete-Data' }, + { text: '自动过期删除', link: 'TTL-Delete' }, + ], + }, ], }, { diff --git a/src/.vuepress/sidebar_timecho/V2.0.x/en-Tree.ts b/src/.vuepress/sidebar_timecho/V2.0.x/en-Tree.ts index 5d04451ad..7f2db058b 100644 --- a/src/.vuepress/sidebar_timecho/V2.0.x/en-Tree.ts +++ b/src/.vuepress/sidebar_timecho/V2.0.x/en-Tree.ts @@ -88,8 +88,16 @@ export const enSidebar = { text: 'Data Modeling', link: 'Operate-Metadata_timecho', }, - { text: 'Write & Delete', link: 'Write-Delete-Data' }, + { text: 'Write Data', link: 'Write-Data' }, { text: 'Query Data', link: 'Query-Data' }, + { + text: 'Delete Data', + collapsible: true, + children: [ + { text: 'Delete Data', link: 'Delete-Data' }, + { text: 'TTL Delete Data', link: 'TTL-Delete' }, + ], + }, ], }, { diff --git a/src/.vuepress/sidebar_timecho/V2.0.x/zh-Tree.ts b/src/.vuepress/sidebar_timecho/V2.0.x/zh-Tree.ts index 434ec5d70..cceff4741 100644 --- a/src/.vuepress/sidebar_timecho/V2.0.x/zh-Tree.ts +++ b/src/.vuepress/sidebar_timecho/V2.0.x/zh-Tree.ts @@ -71,8 +71,16 @@ export const zhSidebar = { prefix: 'Basic-Concept/', children: [ { text: '测点管理', link: 'Operate-Metadata_timecho' }, - { text: '写入&删除', link: 'Write-Delete-Data' }, + { text: '数据写入', link: 'Write-Data' }, { text: '数据查询', link: 'Query-Data' }, + { + text: '数据删除', + collapsible: true, + children: [ + { text: '数据删除', link: 'Delete-Data' }, + { text: '自动过期删除', link: 'TTL-Delete' }, + ], + }, ], }, { diff --git a/src/UserGuide/Master/Tree/Basic-Concept/Delete-Data.md b/src/UserGuide/Master/Tree/Basic-Concept/Delete-Data.md new file mode 100644 index 000000000..2fa82332c --- /dev/null +++ b/src/UserGuide/Master/Tree/Basic-Concept/Delete-Data.md @@ -0,0 +1,104 @@ + +# Delete Data + +Users can delete data that meet the deletion condition in the specified timeseries by using the [DELETE statement](../SQL-Manual/SQL-Manual.md#delete-data). When deleting data, users can select one or more timeseries paths, prefix paths, or paths with star to delete data within a certain time interval. + +In a JAVA programming environment, you can use the [Java JDBC](../API/Programming-JDBC.md) to execute single or batch UPDATE statements. + +## 1. Delete Single Timeseries + +Taking ln Group as an example, there exists such a usage scenario: + +The wf02 plant's wt02 device has many segments of errors in its power supply status before 2017-11-01 16:26:00, and the data cannot be analyzed correctly. The erroneous data affected the correlation analysis with other devices. At this point, the data before this time point needs to be deleted. The SQL statement for this operation is + +```sql +delete from root.ln.wf02.wt02.status where time<=2017-11-01T16:26:00; +``` + +In case we hope to merely delete the data before 2017-11-01 16:26:00 in the year of 2017, The SQL statement is: + +```sql +delete from root.ln.wf02.wt02.status where time>=2017-01-01T00:00:00 and time<=2017-11-01T16:26:00; +``` + +IoTDB supports to delete a range of timeseries points. Users can write SQL expressions as follows to specify the delete interval: + +```sql +delete from root.ln.wf02.wt02.status where time < 10 +delete from root.ln.wf02.wt02.status where time <= 10 +delete from root.ln.wf02.wt02.status where time < 20 and time > 10 +delete from root.ln.wf02.wt02.status where time <= 20 and time >= 10 +delete from root.ln.wf02.wt02.status where time > 20 +delete from root.ln.wf02.wt02.status where time >= 20 +delete from root.ln.wf02.wt02.status where time = 20 +``` + +Please pay attention that multiple intervals connected by "OR" expression are not supported in delete statement: + +``` +delete from root.ln.wf02.wt02.status where time > 4 or time < 0 +Msg: 303: Check metadata error: For delete statement, where clause can only contain atomic +expressions like : time > XXX, time <= XXX, or two atomic expressions connected by 'AND' +``` + +If no "where" clause specified in a delete statement, all the data in a timeseries will be deleted. + +```sql +delete from root.ln.wf02.wt02.status +``` + + +## 2. Delete Multiple Timeseries + +If both the power supply status and hardware version of the ln group wf02 plant wt02 device before 2017-11-01 16:26:00 need to be deleted, [the prefix path with broader meaning or the path with star](../Basic-Concept/Operate-Metadata.md) can be used to delete the data. The SQL statement for this operation is: + +```sql +delete from root.ln.wf02.wt02 where time <= 2017-11-01T16:26:00; +``` + +or + +```sql +delete from root.ln.wf02.wt02.* where time <= 2017-11-01T16:26:00; +``` + +It should be noted that when the deleted path does not exist, IoTDB will not prompt that the path does not exist, but that the execution is successful, because SQL is a declarative programming method. Unless it is a syntax error, insufficient permissions and so on, it is not considered an error, as shown below: + +``` +IoTDB> delete from root.ln.wf03.wt02.status where time < now() +Msg: The statement is executed successfully. +``` + +## 3. Delete Time Partition (experimental) + +You may delete all data in a time partition of a database using the following grammar: + +```sql +DELETE PARTITION root.ln 0,1,2 +``` + +The `0,1,2` above is the id of the partition that is to be deleted, you can find it from the IoTDB +data folders or convert a timestamp manually to an id using `timestamp / partitionInterval +` (flooring), and the `partitionInterval` should be in your config (if time-partitioning is +supported in your version). + +Please notice that this function is experimental and mainly for development, please use it with care. \ No newline at end of file diff --git a/src/UserGuide/Master/Tree/Basic-Concept/TTL-Delete.md b/src/UserGuide/Master/Tree/Basic-Concept/TTL-Delete.md new file mode 100644 index 000000000..14b479fe2 --- /dev/null +++ b/src/UserGuide/Master/Tree/Basic-Concept/TTL-Delete.md @@ -0,0 +1,134 @@ + +# TTL Delete Data + +## 1. Overview + +IoTDB supports device-level TTL settings, which means it is able to delete old data automatically and periodically. The benefit of using TTL is that hopefully you can control the total disk space usage and prevent the machine from running out of disks. Moreover, the query performance may downgrade as the total number of files goes up and the memory usage also increases as there are more files. Timely removing such files helps to keep at a high query performance level and reduce memory usage. + +The default unit of TTL is milliseconds. If the time precision in the configuration file changes to another, the TTL is still set to milliseconds. + +When setting TTL, the system will look for all devices included in the set path and set TTL for these devices. The system will delete expired data at the device granularity. +After the device data expires, it will not be queryable. The data in the disk file cannot be guaranteed to be deleted immediately, but it can be guaranteed to be deleted eventually. +However, due to operational costs, the expired data will not be physically deleted right after expiring. The physical deletion is delayed until compaction. +Therefore, before the data is physically deleted, if the TTL is reduced or lifted, it may cause data that was previously invisible due to TTL to reappear. +The system can only set up to 1000 TTL rules, and when this limit is reached, some TTL rules need to be deleted before new rules can be set. + +## 2. Set TTL +### 2.1 TTL Path Rule +The path can only be prefix paths (i.e., the path cannot contain \* , except \*\* in the last level). +This path will match devices and also allows users to specify paths without asterisks as specific databases or devices. +When the path does not contain asterisks, the system will check if it matches a database; if it matches a database, both the path and path.\*\* will be set at the same time. Note: Device TTL settings do not verify the existence of metadata, i.e., it is allowed to set TTL for a non-existent device. +``` +qualified paths: +root.** +root.db.** +root.db.group1.** +root.db +root.db.group1.d1 + +unqualified paths: +root.*.db +root.**.db.* +root.db.* +``` +### 2.2 TTL Applicable Rules +When a device is subject to multiple TTL rules, the more precise and longer rules are prioritized. For example, for the device "root.bj.hd.dist001.turbine001", the rule "root.bj.hd.dist001.turbine001" takes precedence over "root.bj.hd.dist001.\*\*", and the rule "root.bj.hd.dist001.\*\*" takes precedence over "root.bj.hd.**". +### 2.3 Set TTL +The set ttl operation can be understood as setting a TTL rule, for example, setting ttl to root.sg.group1.** is equivalent to mounting ttl for all devices that can match this path pattern. +The unset ttl operation indicates unmounting TTL for the corresponding path pattern; if there is no corresponding TTL, nothing will be done. +If you want to set TTL to be infinitely large, you can use the INF keyword. +The SQL Statement for setting TTL is as follow: +``` +set ttl to pathPattern 360000; +``` +Set the Time to Live (TTL) to a pathPattern of 360,000 milliseconds; the pathPattern should not contain a wildcard (\*) in the middle and must end with a double asterisk (\*\*). The pathPattern is used to match corresponding devices. +To maintain compatibility with older SQL syntax, if the user-provided pathPattern matches a database (db), the path pattern is automatically expanded to include all sub-paths denoted by path.\*\*. +For instance, writing "set ttl to root.sg 360000" will automatically be transformed into "set ttl to root.sg.\*\* 360000", which sets the TTL for all devices under root.sg. However, if the specified pathPattern does not match a database, the aforementioned logic will not apply. For example, writing "set ttl to root.sg.group 360000" will not be expanded to "root.sg.group.\*\*" since root.sg.group does not match a database. +It is also permissible to specify a particular device without a wildcard (*). +## 3. Unset TTL + +To unset TTL, we can use follwing SQL statement: + +``` +IoTDB> unset ttl from root.ln +``` + +After unset TTL, all data will be accepted in `root.ln`. +``` +IoTDB> unset ttl from root.sgcc.** +``` + +Unset the TTL in the `root.sgcc` path. + +New syntax +``` +IoTDB> unset ttl from root.** +``` + +Old syntax +``` +IoTDB> unset ttl to root.** +``` +There is no functional difference between the old and new syntax, and they are compatible with each other. +The new syntax is just more conventional in terms of wording. + +Unset the TTL setting for all path pattern. + +## 4. Show TTL + +To Show TTL, we can use following SQL statement: + +show all ttl + +``` +IoTDB> SHOW ALL TTL ++--------------+--------+ +| path| TTL| +| root.**|55555555| +| root.sg2.a.**|44440000| ++--------------+--------+ +``` + +show ttl on pathPattern +``` +IoTDB> SHOW TTL ON root.db.**; ++--------------+--------+ +| path| TTL| +| root.db.**|55555555| +| root.db.a.**|44440000| ++--------------+--------+ +``` + +The SHOW ALL TTL example gives the TTL for all path patterns. +The SHOW TTL ON pathPattern shows the TTL for the path pattern specified. + +Display devices' ttl +``` +IoTDB> show devices ++---------------+---------+---------+ +| Device|IsAligned| TTL| ++---------------+---------+---------+ +|root.sg.device1| false| 36000000| +|root.sg.device2| true| INF| ++---------------+---------+---------+ +``` +All devices will definitely have a TTL, meaning it cannot be null. INF represents infinity. \ No newline at end of file diff --git a/src/UserGuide/Master/Tree/Basic-Concept/Write-Delete-Data.md b/src/UserGuide/Master/Tree/Basic-Concept/Write-Data.md similarity index 68% rename from src/UserGuide/Master/Tree/Basic-Concept/Write-Delete-Data.md rename to src/UserGuide/Master/Tree/Basic-Concept/Write-Data.md index 70f358c64..5709e15da 100644 --- a/src/UserGuide/Master/Tree/Basic-Concept/Write-Delete-Data.md +++ b/src/UserGuide/Master/Tree/Basic-Concept/Write-Data.md @@ -20,7 +20,7 @@ --> -# Write & Delete +# Write Data ## 1. CLI INSERT IoTDB provides users with a variety of ways to insert real-time data, such as directly inputting [INSERT SQL statement](../SQL-Manual/SQL-Manual.md#insert-data) in [Client/Shell tools](../Tools-System/CLI.md), or using [Java JDBC](../API/Programming-JDBC.md) to perform single or batch execution of [INSERT SQL statement](../SQL-Manual/SQL-Manual.md). @@ -32,9 +32,7 @@ Writing a repeat timestamp covers the original timestamp data, which can be rega ### 1.1 Use of INSERT Statements The [INSERT SQL statement](../SQL-Manual/SQL-Manual.md#insert-data) statement is used to insert data into one or more specified timeseries created. For each point of data inserted, it consists of a [timestamp](../Basic-Concept/Operate-Metadata.md) and a sensor acquisition value (see [Data Type](../Background-knowledge/Data-Type.md)). - -**Schema-less writing**: When metadata is not defined, data can be directly written through an insert statement, and the required metadata will be automatically recognized and registered in the database, achieving automatic modeling. - + In the scenario of this section, take two timeseries `root.ln.wf02.wt02.status` and `root.ln.wf02.wt02.hardware` as an example, and their data types are BOOLEAN and TEXT, respectively. The sample code for single column data insertion is as follows: @@ -193,88 +191,10 @@ TsFile is the file format of time series used in IoTDB. You can directly import CSV stores table data in plain text. You can write multiple formatted data into a CSV file and import the data into the IoTDB in batches. Before importing data, you are advised to create the corresponding metadata in the IoTDB. Don't worry if you forget to create one, the IoTDB can automatically infer the data in the CSV to its corresponding data type, as long as you have a unique data type for each column. In addition to a single file, the tool supports importing multiple CSV files as folders and setting optimization parameters such as time precision. For details, see [Data Import](../Tools-System/Data-Import-Tool.md). -## 6. DELETE - -Users can delete data that meet the deletion condition in the specified timeseries by using the [DELETE statement](../SQL-Manual/SQL-Manual.md#delete-data). When deleting data, users can select one or more timeseries paths, prefix paths, or paths with star to delete data within a certain time interval. - -In a JAVA programming environment, you can use the [Java JDBC](../API/Programming-JDBC.md) to execute single or batch UPDATE statements. - -### 6.1 Delete Single Timeseries - -Taking ln Group as an example, there exists such a usage scenario: - -The wf02 plant's wt02 device has many segments of errors in its power supply status before 2017-11-01 16:26:00, and the data cannot be analyzed correctly. The erroneous data affected the correlation analysis with other devices. At this point, the data before this time point needs to be deleted. The SQL statement for this operation is - -```sql -delete from root.ln.wf02.wt02.status where time<=2017-11-01T16:26:00; -``` - -In case we hope to merely delete the data before 2017-11-01 16:26:00 in the year of 2017, The SQL statement is: - -```sql -delete from root.ln.wf02.wt02.status where time>=2017-01-01T00:00:00 and time<=2017-11-01T16:26:00; -``` - -IoTDB supports to delete a range of timeseries points. Users can write SQL expressions as follows to specify the delete interval: - -```sql -delete from root.ln.wf02.wt02.status where time < 10 -delete from root.ln.wf02.wt02.status where time <= 10 -delete from root.ln.wf02.wt02.status where time < 20 and time > 10 -delete from root.ln.wf02.wt02.status where time <= 20 and time >= 10 -delete from root.ln.wf02.wt02.status where time > 20 -delete from root.ln.wf02.wt02.status where time >= 20 -delete from root.ln.wf02.wt02.status where time = 20 -``` - -Please pay attention that multiple intervals connected by "OR" expression are not supported in delete statement: - -``` -delete from root.ln.wf02.wt02.status where time > 4 or time < 0 -Msg: 303: Check metadata error: For delete statement, where clause can only contain atomic -expressions like : time > XXX, time <= XXX, or two atomic expressions connected by 'AND' -``` - -If no "where" clause specified in a delete statement, all the data in a timeseries will be deleted. - -```sql -delete from root.ln.wf02.wt02.status -``` - - -### 6.2 Delete Multiple Timeseries - -If both the power supply status and hardware version of the ln group wf02 plant wt02 device before 2017-11-01 16:26:00 need to be deleted, [the prefix path with broader meaning or the path with star](../Basic-Concept/Operate-Metadata.md) can be used to delete the data. The SQL statement for this operation is: - -```sql -delete from root.ln.wf02.wt02 where time <= 2017-11-01T16:26:00; -``` - -or +## 6. SCHEMALESS WRITING +In IoT scenarios, the types and quantities of devices may dynamically increase or decrease over time, and different devices may generate data with varying fields (e.g., temperature, humidity, status codes). Additionally, businesses often require rapid deployment and flexible integration of new devices without cumbersome predefined processes. Therefore, unlike traditional time-series databases that typically require predefining data models, IoTDB supports schema-less writing, where the database automatically identifies and registers the necessary metadata during data writing, enabling automatic modeling. -```sql -delete from root.ln.wf02.wt02.* where time <= 2017-11-01T16:26:00; -``` - -It should be noted that when the deleted path does not exist, IoTDB will not prompt that the path does not exist, but that the execution is successful, because SQL is a declarative programming method. Unless it is a syntax error, insufficient permissions and so on, it is not considered an error, as shown below: - -``` -IoTDB> delete from root.ln.wf03.wt02.status where time < now() -Msg: The statement is executed successfully. -``` - -### 6.3 Delete Time Partition (experimental) - -You may delete all data in a time partition of a database using the following grammar: - -```sql -DELETE PARTITION root.ln 0,1,2 -``` +Users can either use CLI `INSERT` statements or native APIs to write data in real-time, either in batches or row-by-row, for single or multiple devices. Alternatively, they can import historical data in formats such as CSV or TsFile using import tools, during which metadata like time series, data types, and compression encoding methods are automatically created. -The `0,1,2` above is the id of the partition that is to be deleted, you can find it from the IoTDB -data folders or convert a timestamp manually to an id using `timestamp / partitionInterval -` (flooring), and the `partitionInterval` should be in your config (if time-partitioning is -supported in your version). -Please notice that this function is experimental and mainly for development, please use it with care. diff --git a/src/UserGuide/Master/Tree/QuickStart/QuickStart_apache.md b/src/UserGuide/Master/Tree/QuickStart/QuickStart_apache.md index b9fe6b362..df4a289c3 100644 --- a/src/UserGuide/Master/Tree/QuickStart/QuickStart_apache.md +++ b/src/UserGuide/Master/Tree/QuickStart/QuickStart_apache.md @@ -53,7 +53,7 @@ This guide will assist you in quickly installing and deploying IoTDB. You can qu - Introduction to SQL syntax[SQL syntax](../Basic-Concept/Operate-Metadata_apache.md) -2. Write Data: In terms of data writing, IoTDB provides multiple ways to insert real-time data. Please refer to the basic data writing operations for details [Write Data](../Basic-Concept/Write-Delete-Data.md) +2. Write Data: In terms of data writing, IoTDB provides multiple ways to insert real-time data. Please refer to the basic data writing operations for details [Write Data](../Basic-Concept/Write-Data) 3. Query Data: IoTDB provides rich data query functions. Please refer to the basic introduction of data query [Query Data](../Basic-Concept/Query-Data.md) diff --git a/src/UserGuide/Master/Tree/QuickStart/QuickStart_timecho.md b/src/UserGuide/Master/Tree/QuickStart/QuickStart_timecho.md index d0feadb25..09f8fd14c 100644 --- a/src/UserGuide/Master/Tree/QuickStart/QuickStart_timecho.md +++ b/src/UserGuide/Master/Tree/QuickStart/QuickStart_timecho.md @@ -60,7 +60,7 @@ This guide will assist you in quickly installing and deploying IoTDB. You can qu - Introduction to SQL syntax[SQL syntax](../Basic-Concept/Operate-Metadata_timecho.md) -2. Write Data: In terms of data writing, IoTDB provides multiple ways to insert real-time data. Please refer to the basic data writing operations for details [Write Data](../Basic-Concept/Write-Delete-Data.md) +2. Write Data: In terms of data writing, IoTDB provides multiple ways to insert real-time data. Please refer to the basic data writing operations for details [Write Data](../Basic-Concept/Write-Data) 3. Query Data: IoTDB provides rich data query functions. Please refer to the basic introduction of data query [Query Data](../Basic-Concept/Query-Data.md) diff --git a/src/UserGuide/Master/Tree/SQL-Manual/SQL-Manual.md b/src/UserGuide/Master/Tree/SQL-Manual/SQL-Manual.md index 9e0b3582e..1f0353e55 100644 --- a/src/UserGuide/Master/Tree/SQL-Manual/SQL-Manual.md +++ b/src/UserGuide/Master/Tree/SQL-Manual/SQL-Manual.md @@ -409,7 +409,7 @@ IoTDB> count devices root.ln.** ### 5.1 Insert Data -For more details, see document [Write-Delete-Data](../Basic-Concept/Write-Delete-Data.md). +For more details, see document [Write-Data](../Basic-Concept/Write-Data). #### Use of INSERT Statements @@ -471,7 +471,7 @@ For more details, see document [Data Import](../Tools-System/Data-Import-Tool.md ## 6. DELETE DATA -For more details, see document [Write-Delete-Data](../Basic-Concept/Write-Delete-Data.md). +For more details, see document [Write-Delete-Data](../Basic-Concept/Write-Data). ### 6.1 Delete Single Timeseries diff --git a/src/UserGuide/V1.3.x/Basic-Concept/Delete-Data.md b/src/UserGuide/V1.3.x/Basic-Concept/Delete-Data.md new file mode 100644 index 000000000..a5da0a2f1 --- /dev/null +++ b/src/UserGuide/V1.3.x/Basic-Concept/Delete-Data.md @@ -0,0 +1,104 @@ + +# Delete Data + +Users can delete data that meet the deletion condition in the specified timeseries by using the [DELETE statement](../SQL-Manual/SQL-Manual.md#delete-data). When deleting data, users can select one or more timeseries paths, prefix paths, or paths with star to delete data within a certain time interval. + +In a JAVA programming environment, you can use the [Java JDBC](../API/Programming-JDBC.md) to execute single or batch UPDATE statements. + +## Delete Single Timeseries + +Taking ln Group as an example, there exists such a usage scenario: + +The wf02 plant's wt02 device has many segments of errors in its power supply status before 2017-11-01 16:26:00, and the data cannot be analyzed correctly. The erroneous data affected the correlation analysis with other devices. At this point, the data before this time point needs to be deleted. The SQL statement for this operation is + +```sql +delete from root.ln.wf02.wt02.status where time<=2017-11-01T16:26:00; +``` + +In case we hope to merely delete the data before 2017-11-01 16:26:00 in the year of 2017, The SQL statement is: + +```sql +delete from root.ln.wf02.wt02.status where time>=2017-01-01T00:00:00 and time<=2017-11-01T16:26:00; +``` + +IoTDB supports to delete a range of timeseries points. Users can write SQL expressions as follows to specify the delete interval: + +```sql +delete from root.ln.wf02.wt02.status where time < 10 +delete from root.ln.wf02.wt02.status where time <= 10 +delete from root.ln.wf02.wt02.status where time < 20 and time > 10 +delete from root.ln.wf02.wt02.status where time <= 20 and time >= 10 +delete from root.ln.wf02.wt02.status where time > 20 +delete from root.ln.wf02.wt02.status where time >= 20 +delete from root.ln.wf02.wt02.status where time = 20 +``` + +Please pay attention that multiple intervals connected by "OR" expression are not supported in delete statement: + +``` +delete from root.ln.wf02.wt02.status where time > 4 or time < 0 +Msg: 303: Check metadata error: For delete statement, where clause can only contain atomic +expressions like : time > XXX, time <= XXX, or two atomic expressions connected by 'AND' +``` + +If no "where" clause specified in a delete statement, all the data in a timeseries will be deleted. + +```sql +delete from root.ln.wf02.wt02.status +``` + + +## Delete Multiple Timeseries + +If both the power supply status and hardware version of the ln group wf02 plant wt02 device before 2017-11-01 16:26:00 need to be deleted, [the prefix path with broader meaning or the path with star](../Basic-Concept/Data-Model-and-Terminology.md) can be used to delete the data. The SQL statement for this operation is: + +```sql +delete from root.ln.wf02.wt02 where time <= 2017-11-01T16:26:00; +``` + +or + +```sql +delete from root.ln.wf02.wt02.* where time <= 2017-11-01T16:26:00; +``` + +It should be noted that when the deleted path does not exist, IoTDB will not prompt that the path does not exist, but that the execution is successful, because SQL is a declarative programming method. Unless it is a syntax error, insufficient permissions and so on, it is not considered an error, as shown below: + +``` +IoTDB> delete from root.ln.wf03.wt02.status where time < now() +Msg: The statement is executed successfully. +``` + +## Delete Time Partition (experimental) + +You may delete all data in a time partition of a database using the following grammar: + +```sql +DELETE PARTITION root.ln 0,1,2 +``` + +The `0,1,2` above is the id of the partition that is to be deleted, you can find it from the IoTDB +data folders or convert a timestamp manually to an id using `timestamp / partitionInterval +` (flooring), and the `partitionInterval` should be in your config (if time-partitioning is +supported in your version). + +Please notice that this function is experimental and mainly for development, please use it with care. diff --git a/src/UserGuide/V1.3.x/Basic-Concept/TTL-Delete.md b/src/UserGuide/V1.3.x/Basic-Concept/TTL-Delete.md new file mode 100644 index 000000000..467922752 --- /dev/null +++ b/src/UserGuide/V1.3.x/Basic-Concept/TTL-Delete.md @@ -0,0 +1,134 @@ + +# TTL Delete Data + +## Overview + +IoTDB supports device-level TTL settings, which means it is able to delete old data automatically and periodically. The benefit of using TTL is that hopefully you can control the total disk space usage and prevent the machine from running out of disks. Moreover, the query performance may downgrade as the total number of files goes up and the memory usage also increases as there are more files. Timely removing such files helps to keep at a high query performance level and reduce memory usage. + +The default unit of TTL is milliseconds. If the time precision in the configuration file changes to another, the TTL is still set to milliseconds. + +When setting TTL, the system will look for all devices included in the set path and set TTL for these devices. The system will delete expired data at the device granularity. +After the device data expires, it will not be queryable. The data in the disk file cannot be guaranteed to be deleted immediately, but it can be guaranteed to be deleted eventually. +However, due to operational costs, the expired data will not be physically deleted right after expiring. The physical deletion is delayed until compaction. +Therefore, before the data is physically deleted, if the TTL is reduced or lifted, it may cause data that was previously invisible due to TTL to reappear. +The system can only set up to 1000 TTL rules, and when this limit is reached, some TTL rules need to be deleted before new rules can be set. + +## Set TTL +### TTL Path Rule +The path can only be prefix paths (i.e., the path cannot contain \* , except \*\* in the last level). +This path will match devices and also allows users to specify paths without asterisks as specific databases or devices. +When the path does not contain asterisks, the system will check if it matches a database; if it matches a database, both the path and path.\*\* will be set at the same time. Note: Device TTL settings do not verify the existence of metadata, i.e., it is allowed to set TTL for a non-existent device. +``` +qualified paths: +root.** +root.db.** +root.db.group1.** +root.db +root.db.group1.d1 + +unqualified paths: +root.*.db +root.**.db.* +root.db.* +``` +### TTL Applicable Rules +When a device is subject to multiple TTL rules, the more precise and longer rules are prioritized. For example, for the device "root.bj.hd.dist001.turbine001", the rule "root.bj.hd.dist001.turbine001" takes precedence over "root.bj.hd.dist001.\*\*", and the rule "root.bj.hd.dist001.\*\*" takes precedence over "root.bj.hd.**". +### Set TTL +The set ttl operation can be understood as setting a TTL rule, for example, setting ttl to root.sg.group1.** is equivalent to mounting ttl for all devices that can match this path pattern. +The unset ttl operation indicates unmounting TTL for the corresponding path pattern; if there is no corresponding TTL, nothing will be done. +If you want to set TTL to be infinitely large, you can use the INF keyword. +The SQL Statement for setting TTL is as follow: +``` +set ttl to pathPattern 360000; +``` +Set the Time to Live (TTL) to a pathPattern of 360,000 milliseconds; the pathPattern should not contain a wildcard (\*) in the middle and must end with a double asterisk (\*\*). The pathPattern is used to match corresponding devices. +To maintain compatibility with older SQL syntax, if the user-provided pathPattern matches a database (db), the path pattern is automatically expanded to include all sub-paths denoted by path.\*\*. +For instance, writing "set ttl to root.sg 360000" will automatically be transformed into "set ttl to root.sg.\*\* 360000", which sets the TTL for all devices under root.sg. However, if the specified pathPattern does not match a database, the aforementioned logic will not apply. For example, writing "set ttl to root.sg.group 360000" will not be expanded to "root.sg.group.\*\*" since root.sg.group does not match a database. +It is also permissible to specify a particular device without a wildcard (*). +## Unset TTL + +To unset TTL, we can use follwing SQL statement: + +``` +IoTDB> unset ttl from root.ln +``` + +After unset TTL, all data will be accepted in `root.ln`. +``` +IoTDB> unset ttl from root.sgcc.** +``` + +Unset the TTL in the `root.sgcc` path. + +New syntax +``` +IoTDB> unset ttl from root.** +``` + +Old syntax +``` +IoTDB> unset ttl to root.** +``` +There is no functional difference between the old and new syntax, and they are compatible with each other. +The new syntax is just more conventional in terms of wording. + +Unset the TTL setting for all path pattern. + +## Show TTL + +To Show TTL, we can use following SQL statement: + +show all ttl + +``` +IoTDB> SHOW ALL TTL ++--------------+--------+ +| path| TTL| +| root.**|55555555| +| root.sg2.a.**|44440000| ++--------------+--------+ +``` + +show ttl on pathPattern +``` +IoTDB> SHOW TTL ON root.db.**; ++--------------+--------+ +| path| TTL| +| root.db.**|55555555| +| root.db.a.**|44440000| ++--------------+--------+ +``` + +The SHOW ALL TTL example gives the TTL for all path patterns. +The SHOW TTL ON pathPattern shows the TTL for the path pattern specified. + +Display devices' ttl +``` +IoTDB> show devices ++---------------+---------+---------+ +| Device|IsAligned| TTL| ++---------------+---------+---------+ +|root.sg.device1| false| 36000000| +|root.sg.device2| true| INF| ++---------------+---------+---------+ +``` +All devices will definitely have a TTL, meaning it cannot be null. INF represents infinity. \ No newline at end of file diff --git a/src/UserGuide/V1.3.x/Basic-Concept/Write-Delete-Data.md b/src/UserGuide/V1.3.x/Basic-Concept/Write-Data.md similarity index 68% rename from src/UserGuide/V1.3.x/Basic-Concept/Write-Delete-Data.md rename to src/UserGuide/V1.3.x/Basic-Concept/Write-Data.md index b445bf3ef..934aef190 100644 --- a/src/UserGuide/V1.3.x/Basic-Concept/Write-Delete-Data.md +++ b/src/UserGuide/V1.3.x/Basic-Concept/Write-Data.md @@ -20,7 +20,7 @@ --> -# Write & Delete Data +# Write Data ## CLI INSERT IoTDB provides users with a variety of ways to insert real-time data, such as directly inputting [INSERT SQL statement](../SQL-Manual/SQL-Manual.md#insert-data) in [Client/Shell tools](../Tools-System/CLI.md), or using [Java JDBC](../API/Programming-JDBC.md) to perform single or batch execution of [INSERT SQL statement](../SQL-Manual/SQL-Manual.md). @@ -33,8 +33,6 @@ Writing a repeat timestamp covers the original timestamp data, which can be rega The [INSERT SQL statement](../SQL-Manual/SQL-Manual.md#insert-data) statement is used to insert data into one or more specified timeseries created. For each point of data inserted, it consists of a [timestamp](../Basic-Concept/Data-Model-and-Terminology.md) and a sensor acquisition value (see [Data Type](../Background-knowledge/Data-Type.md)). -**Schema-less writing**: When metadata is not defined, data can be directly written through an insert statement, and the required metadata will be automatically recognized and registered in the database, achieving automatic modeling. - In the scenario of this section, take two timeseries `root.ln.wf02.wt02.status` and `root.ln.wf02.wt02.hardware` as an example, and their data types are BOOLEAN and TEXT, respectively. The sample code for single column data insertion is as follows: @@ -193,88 +191,10 @@ TsFile is the file format of time series used in IoTDB. You can directly import CSV stores table data in plain text. You can write multiple formatted data into a CSV file and import the data into the IoTDB in batches. Before importing data, you are advised to create the corresponding metadata in the IoTDB. Don't worry if you forget to create one, the IoTDB can automatically infer the data in the CSV to its corresponding data type, as long as you have a unique data type for each column. In addition to a single file, the tool supports importing multiple CSV files as folders and setting optimization parameters such as time precision. For details, see [Data Import](../Tools-System/Data-Import-Tool.md). -## DELETE - -Users can delete data that meet the deletion condition in the specified timeseries by using the [DELETE statement](../SQL-Manual/SQL-Manual.md#delete-data). When deleting data, users can select one or more timeseries paths, prefix paths, or paths with star to delete data within a certain time interval. - -In a JAVA programming environment, you can use the [Java JDBC](../API/Programming-JDBC.md) to execute single or batch UPDATE statements. - -### Delete Single Timeseries - -Taking ln Group as an example, there exists such a usage scenario: - -The wf02 plant's wt02 device has many segments of errors in its power supply status before 2017-11-01 16:26:00, and the data cannot be analyzed correctly. The erroneous data affected the correlation analysis with other devices. At this point, the data before this time point needs to be deleted. The SQL statement for this operation is - -```sql -delete from root.ln.wf02.wt02.status where time<=2017-11-01T16:26:00; -``` - -In case we hope to merely delete the data before 2017-11-01 16:26:00 in the year of 2017, The SQL statement is: - -```sql -delete from root.ln.wf02.wt02.status where time>=2017-01-01T00:00:00 and time<=2017-11-01T16:26:00; -``` - -IoTDB supports to delete a range of timeseries points. Users can write SQL expressions as follows to specify the delete interval: - -```sql -delete from root.ln.wf02.wt02.status where time < 10 -delete from root.ln.wf02.wt02.status where time <= 10 -delete from root.ln.wf02.wt02.status where time < 20 and time > 10 -delete from root.ln.wf02.wt02.status where time <= 20 and time >= 10 -delete from root.ln.wf02.wt02.status where time > 20 -delete from root.ln.wf02.wt02.status where time >= 20 -delete from root.ln.wf02.wt02.status where time = 20 -``` - -Please pay attention that multiple intervals connected by "OR" expression are not supported in delete statement: - -``` -delete from root.ln.wf02.wt02.status where time > 4 or time < 0 -Msg: 303: Check metadata error: For delete statement, where clause can only contain atomic -expressions like : time > XXX, time <= XXX, or two atomic expressions connected by 'AND' -``` - -If no "where" clause specified in a delete statement, all the data in a timeseries will be deleted. +## SCHEMALESS WRITING +In IoT scenarios, the types and quantities of devices may dynamically increase or decrease over time, and different devices may generate data with varying fields (e.g., temperature, humidity, status codes). Additionally, businesses often require rapid deployment and flexible integration of new devices without cumbersome predefined processes. Therefore, unlike traditional time-series databases that typically require predefining data models, IoTDB supports schema-less writing, where the database automatically identifies and registers the necessary metadata during data writing, enabling automatic modeling. -```sql -delete from root.ln.wf02.wt02.status -``` - - -### Delete Multiple Timeseries - -If both the power supply status and hardware version of the ln group wf02 plant wt02 device before 2017-11-01 16:26:00 need to be deleted, [the prefix path with broader meaning or the path with star](../Basic-Concept/Data-Model-and-Terminology.md) can be used to delete the data. The SQL statement for this operation is: - -```sql -delete from root.ln.wf02.wt02 where time <= 2017-11-01T16:26:00; -``` - -or - -```sql -delete from root.ln.wf02.wt02.* where time <= 2017-11-01T16:26:00; -``` - -It should be noted that when the deleted path does not exist, IoTDB will not prompt that the path does not exist, but that the execution is successful, because SQL is a declarative programming method. Unless it is a syntax error, insufficient permissions and so on, it is not considered an error, as shown below: - -``` -IoTDB> delete from root.ln.wf03.wt02.status where time < now() -Msg: The statement is executed successfully. -``` - -### Delete Time Partition (experimental) - -You may delete all data in a time partition of a database using the following grammar: - -```sql -DELETE PARTITION root.ln 0,1,2 -``` +Users can either use CLI `INSERT` statements or native APIs to write data in real-time, either in batches or row-by-row, for single or multiple devices. Alternatively, they can import historical data in formats such as CSV or TsFile using import tools, during which metadata like time series, data types, and compression encoding methods are automatically created. -The `0,1,2` above is the id of the partition that is to be deleted, you can find it from the IoTDB -data folders or convert a timestamp manually to an id using `timestamp / partitionInterval -` (flooring), and the `partitionInterval` should be in your config (if time-partitioning is -supported in your version). -Please notice that this function is experimental and mainly for development, please use it with care. diff --git a/src/UserGuide/V1.3.x/QuickStart/QuickStart_apache.md b/src/UserGuide/V1.3.x/QuickStart/QuickStart_apache.md index 7089ea692..a1bbdca9f 100644 --- a/src/UserGuide/V1.3.x/QuickStart/QuickStart_apache.md +++ b/src/UserGuide/V1.3.x/QuickStart/QuickStart_apache.md @@ -50,7 +50,7 @@ This document will help you quickly install and deploy IoTDB. You can quickly lo - SQL syntax introduction: [Operate Metadata](../Basic-Concept/Operate-Metadata_apache.md) -2. Write Data: In terms of data writing, IoTDB provides multiple ways to insert real-time data. Please refer to the basic data writing operations for details [Write Data](../Basic-Concept/Write-Delete-Data.md) +2. Write Data: In terms of data writing, IoTDB provides multiple ways to insert real-time data. Please refer to the basic data writing operations for details [Write Data](../Basic-Concept/Write-Data) 3. Query Data: IoTDB provides rich data query functions. Please refer to the basic introduction of data query [Query Data](../Basic-Concept/Query-Data.md) diff --git a/src/UserGuide/V1.3.x/QuickStart/QuickStart_timecho.md b/src/UserGuide/V1.3.x/QuickStart/QuickStart_timecho.md index 9fc5defa8..3a28f86c9 100644 --- a/src/UserGuide/V1.3.x/QuickStart/QuickStart_timecho.md +++ b/src/UserGuide/V1.3.x/QuickStart/QuickStart_timecho.md @@ -58,7 +58,7 @@ This document will help you quickly install and deploy IoTDB. You can quickly lo - SQL syntax introduction:[Operate Metadata](../Basic-Concept/Operate-Metadata_timecho.md) -2. Write Data: In terms of data writing, IoTDB provides multiple ways to insert real-time data. Please refer to the basic data writing operations for details [Write Data](../Basic-Concept/Write-Delete-Data.md) +2. Write Data: In terms of data writing, IoTDB provides multiple ways to insert real-time data. Please refer to the basic data writing operations for details [Write Data](../Basic-Concept/Write-Data) 3. Query Data: IoTDB provides rich data query functions. Please refer to the basic introduction of data query [Query Data](../Basic-Concept/Query-Data.md) diff --git a/src/UserGuide/V1.3.x/SQL-Manual/SQL-Manual.md b/src/UserGuide/V1.3.x/SQL-Manual/SQL-Manual.md index 7e0ee9dd0..3cb860dbf 100644 --- a/src/UserGuide/V1.3.x/SQL-Manual/SQL-Manual.md +++ b/src/UserGuide/V1.3.x/SQL-Manual/SQL-Manual.md @@ -409,7 +409,7 @@ IoTDB> count devices root.ln.** ### Insert Data -For more details, see document [Write-Delete-Data](../Basic-Concept/Write-Delete-Data.md). +For more details, see document [Write-Data](../Basic-Concept/Write-Data). #### Use of INSERT Statements @@ -471,7 +471,7 @@ For more details, see document [Data Import](../Tools-System/Data-Import-Tool.md ## DELETE DATA -For more details, see document [Write-Delete-Data](../Basic-Concept/Write-Delete-Data.md). +For more details, see document [Write-Delete-Data](../Basic-Concept/Write-Data). ### Delete Single Timeseries diff --git a/src/UserGuide/latest/Basic-Concept/Delete-Data.md b/src/UserGuide/latest/Basic-Concept/Delete-Data.md new file mode 100644 index 000000000..2fa82332c --- /dev/null +++ b/src/UserGuide/latest/Basic-Concept/Delete-Data.md @@ -0,0 +1,104 @@ + +# Delete Data + +Users can delete data that meet the deletion condition in the specified timeseries by using the [DELETE statement](../SQL-Manual/SQL-Manual.md#delete-data). When deleting data, users can select one or more timeseries paths, prefix paths, or paths with star to delete data within a certain time interval. + +In a JAVA programming environment, you can use the [Java JDBC](../API/Programming-JDBC.md) to execute single or batch UPDATE statements. + +## 1. Delete Single Timeseries + +Taking ln Group as an example, there exists such a usage scenario: + +The wf02 plant's wt02 device has many segments of errors in its power supply status before 2017-11-01 16:26:00, and the data cannot be analyzed correctly. The erroneous data affected the correlation analysis with other devices. At this point, the data before this time point needs to be deleted. The SQL statement for this operation is + +```sql +delete from root.ln.wf02.wt02.status where time<=2017-11-01T16:26:00; +``` + +In case we hope to merely delete the data before 2017-11-01 16:26:00 in the year of 2017, The SQL statement is: + +```sql +delete from root.ln.wf02.wt02.status where time>=2017-01-01T00:00:00 and time<=2017-11-01T16:26:00; +``` + +IoTDB supports to delete a range of timeseries points. Users can write SQL expressions as follows to specify the delete interval: + +```sql +delete from root.ln.wf02.wt02.status where time < 10 +delete from root.ln.wf02.wt02.status where time <= 10 +delete from root.ln.wf02.wt02.status where time < 20 and time > 10 +delete from root.ln.wf02.wt02.status where time <= 20 and time >= 10 +delete from root.ln.wf02.wt02.status where time > 20 +delete from root.ln.wf02.wt02.status where time >= 20 +delete from root.ln.wf02.wt02.status where time = 20 +``` + +Please pay attention that multiple intervals connected by "OR" expression are not supported in delete statement: + +``` +delete from root.ln.wf02.wt02.status where time > 4 or time < 0 +Msg: 303: Check metadata error: For delete statement, where clause can only contain atomic +expressions like : time > XXX, time <= XXX, or two atomic expressions connected by 'AND' +``` + +If no "where" clause specified in a delete statement, all the data in a timeseries will be deleted. + +```sql +delete from root.ln.wf02.wt02.status +``` + + +## 2. Delete Multiple Timeseries + +If both the power supply status and hardware version of the ln group wf02 plant wt02 device before 2017-11-01 16:26:00 need to be deleted, [the prefix path with broader meaning or the path with star](../Basic-Concept/Operate-Metadata.md) can be used to delete the data. The SQL statement for this operation is: + +```sql +delete from root.ln.wf02.wt02 where time <= 2017-11-01T16:26:00; +``` + +or + +```sql +delete from root.ln.wf02.wt02.* where time <= 2017-11-01T16:26:00; +``` + +It should be noted that when the deleted path does not exist, IoTDB will not prompt that the path does not exist, but that the execution is successful, because SQL is a declarative programming method. Unless it is a syntax error, insufficient permissions and so on, it is not considered an error, as shown below: + +``` +IoTDB> delete from root.ln.wf03.wt02.status where time < now() +Msg: The statement is executed successfully. +``` + +## 3. Delete Time Partition (experimental) + +You may delete all data in a time partition of a database using the following grammar: + +```sql +DELETE PARTITION root.ln 0,1,2 +``` + +The `0,1,2` above is the id of the partition that is to be deleted, you can find it from the IoTDB +data folders or convert a timestamp manually to an id using `timestamp / partitionInterval +` (flooring), and the `partitionInterval` should be in your config (if time-partitioning is +supported in your version). + +Please notice that this function is experimental and mainly for development, please use it with care. \ No newline at end of file diff --git a/src/UserGuide/latest/Basic-Concept/TTL-Delete.md b/src/UserGuide/latest/Basic-Concept/TTL-Delete.md new file mode 100644 index 000000000..14b479fe2 --- /dev/null +++ b/src/UserGuide/latest/Basic-Concept/TTL-Delete.md @@ -0,0 +1,134 @@ + +# TTL Delete Data + +## 1. Overview + +IoTDB supports device-level TTL settings, which means it is able to delete old data automatically and periodically. The benefit of using TTL is that hopefully you can control the total disk space usage and prevent the machine from running out of disks. Moreover, the query performance may downgrade as the total number of files goes up and the memory usage also increases as there are more files. Timely removing such files helps to keep at a high query performance level and reduce memory usage. + +The default unit of TTL is milliseconds. If the time precision in the configuration file changes to another, the TTL is still set to milliseconds. + +When setting TTL, the system will look for all devices included in the set path and set TTL for these devices. The system will delete expired data at the device granularity. +After the device data expires, it will not be queryable. The data in the disk file cannot be guaranteed to be deleted immediately, but it can be guaranteed to be deleted eventually. +However, due to operational costs, the expired data will not be physically deleted right after expiring. The physical deletion is delayed until compaction. +Therefore, before the data is physically deleted, if the TTL is reduced or lifted, it may cause data that was previously invisible due to TTL to reappear. +The system can only set up to 1000 TTL rules, and when this limit is reached, some TTL rules need to be deleted before new rules can be set. + +## 2. Set TTL +### 2.1 TTL Path Rule +The path can only be prefix paths (i.e., the path cannot contain \* , except \*\* in the last level). +This path will match devices and also allows users to specify paths without asterisks as specific databases or devices. +When the path does not contain asterisks, the system will check if it matches a database; if it matches a database, both the path and path.\*\* will be set at the same time. Note: Device TTL settings do not verify the existence of metadata, i.e., it is allowed to set TTL for a non-existent device. +``` +qualified paths: +root.** +root.db.** +root.db.group1.** +root.db +root.db.group1.d1 + +unqualified paths: +root.*.db +root.**.db.* +root.db.* +``` +### 2.2 TTL Applicable Rules +When a device is subject to multiple TTL rules, the more precise and longer rules are prioritized. For example, for the device "root.bj.hd.dist001.turbine001", the rule "root.bj.hd.dist001.turbine001" takes precedence over "root.bj.hd.dist001.\*\*", and the rule "root.bj.hd.dist001.\*\*" takes precedence over "root.bj.hd.**". +### 2.3 Set TTL +The set ttl operation can be understood as setting a TTL rule, for example, setting ttl to root.sg.group1.** is equivalent to mounting ttl for all devices that can match this path pattern. +The unset ttl operation indicates unmounting TTL for the corresponding path pattern; if there is no corresponding TTL, nothing will be done. +If you want to set TTL to be infinitely large, you can use the INF keyword. +The SQL Statement for setting TTL is as follow: +``` +set ttl to pathPattern 360000; +``` +Set the Time to Live (TTL) to a pathPattern of 360,000 milliseconds; the pathPattern should not contain a wildcard (\*) in the middle and must end with a double asterisk (\*\*). The pathPattern is used to match corresponding devices. +To maintain compatibility with older SQL syntax, if the user-provided pathPattern matches a database (db), the path pattern is automatically expanded to include all sub-paths denoted by path.\*\*. +For instance, writing "set ttl to root.sg 360000" will automatically be transformed into "set ttl to root.sg.\*\* 360000", which sets the TTL for all devices under root.sg. However, if the specified pathPattern does not match a database, the aforementioned logic will not apply. For example, writing "set ttl to root.sg.group 360000" will not be expanded to "root.sg.group.\*\*" since root.sg.group does not match a database. +It is also permissible to specify a particular device without a wildcard (*). +## 3. Unset TTL + +To unset TTL, we can use follwing SQL statement: + +``` +IoTDB> unset ttl from root.ln +``` + +After unset TTL, all data will be accepted in `root.ln`. +``` +IoTDB> unset ttl from root.sgcc.** +``` + +Unset the TTL in the `root.sgcc` path. + +New syntax +``` +IoTDB> unset ttl from root.** +``` + +Old syntax +``` +IoTDB> unset ttl to root.** +``` +There is no functional difference between the old and new syntax, and they are compatible with each other. +The new syntax is just more conventional in terms of wording. + +Unset the TTL setting for all path pattern. + +## 4. Show TTL + +To Show TTL, we can use following SQL statement: + +show all ttl + +``` +IoTDB> SHOW ALL TTL ++--------------+--------+ +| path| TTL| +| root.**|55555555| +| root.sg2.a.**|44440000| ++--------------+--------+ +``` + +show ttl on pathPattern +``` +IoTDB> SHOW TTL ON root.db.**; ++--------------+--------+ +| path| TTL| +| root.db.**|55555555| +| root.db.a.**|44440000| ++--------------+--------+ +``` + +The SHOW ALL TTL example gives the TTL for all path patterns. +The SHOW TTL ON pathPattern shows the TTL for the path pattern specified. + +Display devices' ttl +``` +IoTDB> show devices ++---------------+---------+---------+ +| Device|IsAligned| TTL| ++---------------+---------+---------+ +|root.sg.device1| false| 36000000| +|root.sg.device2| true| INF| ++---------------+---------+---------+ +``` +All devices will definitely have a TTL, meaning it cannot be null. INF represents infinity. \ No newline at end of file diff --git a/src/UserGuide/latest/Basic-Concept/Write-Delete-Data.md b/src/UserGuide/latest/Basic-Concept/Write-Data.md similarity index 68% rename from src/UserGuide/latest/Basic-Concept/Write-Delete-Data.md rename to src/UserGuide/latest/Basic-Concept/Write-Data.md index 70f358c64..5709e15da 100644 --- a/src/UserGuide/latest/Basic-Concept/Write-Delete-Data.md +++ b/src/UserGuide/latest/Basic-Concept/Write-Data.md @@ -20,7 +20,7 @@ --> -# Write & Delete +# Write Data ## 1. CLI INSERT IoTDB provides users with a variety of ways to insert real-time data, such as directly inputting [INSERT SQL statement](../SQL-Manual/SQL-Manual.md#insert-data) in [Client/Shell tools](../Tools-System/CLI.md), or using [Java JDBC](../API/Programming-JDBC.md) to perform single or batch execution of [INSERT SQL statement](../SQL-Manual/SQL-Manual.md). @@ -32,9 +32,7 @@ Writing a repeat timestamp covers the original timestamp data, which can be rega ### 1.1 Use of INSERT Statements The [INSERT SQL statement](../SQL-Manual/SQL-Manual.md#insert-data) statement is used to insert data into one or more specified timeseries created. For each point of data inserted, it consists of a [timestamp](../Basic-Concept/Operate-Metadata.md) and a sensor acquisition value (see [Data Type](../Background-knowledge/Data-Type.md)). - -**Schema-less writing**: When metadata is not defined, data can be directly written through an insert statement, and the required metadata will be automatically recognized and registered in the database, achieving automatic modeling. - + In the scenario of this section, take two timeseries `root.ln.wf02.wt02.status` and `root.ln.wf02.wt02.hardware` as an example, and their data types are BOOLEAN and TEXT, respectively. The sample code for single column data insertion is as follows: @@ -193,88 +191,10 @@ TsFile is the file format of time series used in IoTDB. You can directly import CSV stores table data in plain text. You can write multiple formatted data into a CSV file and import the data into the IoTDB in batches. Before importing data, you are advised to create the corresponding metadata in the IoTDB. Don't worry if you forget to create one, the IoTDB can automatically infer the data in the CSV to its corresponding data type, as long as you have a unique data type for each column. In addition to a single file, the tool supports importing multiple CSV files as folders and setting optimization parameters such as time precision. For details, see [Data Import](../Tools-System/Data-Import-Tool.md). -## 6. DELETE - -Users can delete data that meet the deletion condition in the specified timeseries by using the [DELETE statement](../SQL-Manual/SQL-Manual.md#delete-data). When deleting data, users can select one or more timeseries paths, prefix paths, or paths with star to delete data within a certain time interval. - -In a JAVA programming environment, you can use the [Java JDBC](../API/Programming-JDBC.md) to execute single or batch UPDATE statements. - -### 6.1 Delete Single Timeseries - -Taking ln Group as an example, there exists such a usage scenario: - -The wf02 plant's wt02 device has many segments of errors in its power supply status before 2017-11-01 16:26:00, and the data cannot be analyzed correctly. The erroneous data affected the correlation analysis with other devices. At this point, the data before this time point needs to be deleted. The SQL statement for this operation is - -```sql -delete from root.ln.wf02.wt02.status where time<=2017-11-01T16:26:00; -``` - -In case we hope to merely delete the data before 2017-11-01 16:26:00 in the year of 2017, The SQL statement is: - -```sql -delete from root.ln.wf02.wt02.status where time>=2017-01-01T00:00:00 and time<=2017-11-01T16:26:00; -``` - -IoTDB supports to delete a range of timeseries points. Users can write SQL expressions as follows to specify the delete interval: - -```sql -delete from root.ln.wf02.wt02.status where time < 10 -delete from root.ln.wf02.wt02.status where time <= 10 -delete from root.ln.wf02.wt02.status where time < 20 and time > 10 -delete from root.ln.wf02.wt02.status where time <= 20 and time >= 10 -delete from root.ln.wf02.wt02.status where time > 20 -delete from root.ln.wf02.wt02.status where time >= 20 -delete from root.ln.wf02.wt02.status where time = 20 -``` - -Please pay attention that multiple intervals connected by "OR" expression are not supported in delete statement: - -``` -delete from root.ln.wf02.wt02.status where time > 4 or time < 0 -Msg: 303: Check metadata error: For delete statement, where clause can only contain atomic -expressions like : time > XXX, time <= XXX, or two atomic expressions connected by 'AND' -``` - -If no "where" clause specified in a delete statement, all the data in a timeseries will be deleted. - -```sql -delete from root.ln.wf02.wt02.status -``` - - -### 6.2 Delete Multiple Timeseries - -If both the power supply status and hardware version of the ln group wf02 plant wt02 device before 2017-11-01 16:26:00 need to be deleted, [the prefix path with broader meaning or the path with star](../Basic-Concept/Operate-Metadata.md) can be used to delete the data. The SQL statement for this operation is: - -```sql -delete from root.ln.wf02.wt02 where time <= 2017-11-01T16:26:00; -``` - -or +## 6. SCHEMALESS WRITING +In IoT scenarios, the types and quantities of devices may dynamically increase or decrease over time, and different devices may generate data with varying fields (e.g., temperature, humidity, status codes). Additionally, businesses often require rapid deployment and flexible integration of new devices without cumbersome predefined processes. Therefore, unlike traditional time-series databases that typically require predefining data models, IoTDB supports schema-less writing, where the database automatically identifies and registers the necessary metadata during data writing, enabling automatic modeling. -```sql -delete from root.ln.wf02.wt02.* where time <= 2017-11-01T16:26:00; -``` - -It should be noted that when the deleted path does not exist, IoTDB will not prompt that the path does not exist, but that the execution is successful, because SQL is a declarative programming method. Unless it is a syntax error, insufficient permissions and so on, it is not considered an error, as shown below: - -``` -IoTDB> delete from root.ln.wf03.wt02.status where time < now() -Msg: The statement is executed successfully. -``` - -### 6.3 Delete Time Partition (experimental) - -You may delete all data in a time partition of a database using the following grammar: - -```sql -DELETE PARTITION root.ln 0,1,2 -``` +Users can either use CLI `INSERT` statements or native APIs to write data in real-time, either in batches or row-by-row, for single or multiple devices. Alternatively, they can import historical data in formats such as CSV or TsFile using import tools, during which metadata like time series, data types, and compression encoding methods are automatically created. -The `0,1,2` above is the id of the partition that is to be deleted, you can find it from the IoTDB -data folders or convert a timestamp manually to an id using `timestamp / partitionInterval -` (flooring), and the `partitionInterval` should be in your config (if time-partitioning is -supported in your version). -Please notice that this function is experimental and mainly for development, please use it with care. diff --git a/src/UserGuide/latest/QuickStart/QuickStart_apache.md b/src/UserGuide/latest/QuickStart/QuickStart_apache.md index b9fe6b362..df4a289c3 100644 --- a/src/UserGuide/latest/QuickStart/QuickStart_apache.md +++ b/src/UserGuide/latest/QuickStart/QuickStart_apache.md @@ -53,7 +53,7 @@ This guide will assist you in quickly installing and deploying IoTDB. You can qu - Introduction to SQL syntax[SQL syntax](../Basic-Concept/Operate-Metadata_apache.md) -2. Write Data: In terms of data writing, IoTDB provides multiple ways to insert real-time data. Please refer to the basic data writing operations for details [Write Data](../Basic-Concept/Write-Delete-Data.md) +2. Write Data: In terms of data writing, IoTDB provides multiple ways to insert real-time data. Please refer to the basic data writing operations for details [Write Data](../Basic-Concept/Write-Data) 3. Query Data: IoTDB provides rich data query functions. Please refer to the basic introduction of data query [Query Data](../Basic-Concept/Query-Data.md) diff --git a/src/UserGuide/latest/QuickStart/QuickStart_timecho.md b/src/UserGuide/latest/QuickStart/QuickStart_timecho.md index d0feadb25..09f8fd14c 100644 --- a/src/UserGuide/latest/QuickStart/QuickStart_timecho.md +++ b/src/UserGuide/latest/QuickStart/QuickStart_timecho.md @@ -60,7 +60,7 @@ This guide will assist you in quickly installing and deploying IoTDB. You can qu - Introduction to SQL syntax[SQL syntax](../Basic-Concept/Operate-Metadata_timecho.md) -2. Write Data: In terms of data writing, IoTDB provides multiple ways to insert real-time data. Please refer to the basic data writing operations for details [Write Data](../Basic-Concept/Write-Delete-Data.md) +2. Write Data: In terms of data writing, IoTDB provides multiple ways to insert real-time data. Please refer to the basic data writing operations for details [Write Data](../Basic-Concept/Write-Data) 3. Query Data: IoTDB provides rich data query functions. Please refer to the basic introduction of data query [Query Data](../Basic-Concept/Query-Data.md) diff --git a/src/UserGuide/latest/SQL-Manual/SQL-Manual.md b/src/UserGuide/latest/SQL-Manual/SQL-Manual.md index 9e0b3582e..1f0353e55 100644 --- a/src/UserGuide/latest/SQL-Manual/SQL-Manual.md +++ b/src/UserGuide/latest/SQL-Manual/SQL-Manual.md @@ -409,7 +409,7 @@ IoTDB> count devices root.ln.** ### 5.1 Insert Data -For more details, see document [Write-Delete-Data](../Basic-Concept/Write-Delete-Data.md). +For more details, see document [Write-Data](../Basic-Concept/Write-Data). #### Use of INSERT Statements @@ -471,7 +471,7 @@ For more details, see document [Data Import](../Tools-System/Data-Import-Tool.md ## 6. DELETE DATA -For more details, see document [Write-Delete-Data](../Basic-Concept/Write-Delete-Data.md). +For more details, see document [Write-Delete-Data](../Basic-Concept/Write-Data). ### 6.1 Delete Single Timeseries diff --git a/src/zh/UserGuide/Master/Tree/Basic-Concept/Delete-Data.md b/src/zh/UserGuide/Master/Tree/Basic-Concept/Delete-Data.md new file mode 100644 index 000000000..184429c5b --- /dev/null +++ b/src/zh/UserGuide/Master/Tree/Basic-Concept/Delete-Data.md @@ -0,0 +1,91 @@ + +# 数据删除 + +用户使用 [DELETE 语句](../SQL-Manual/SQL-Manual.md#删除数据) 可以删除指定的时间序列中符合时间删除条件的数据。在删除数据时,用户可以选择需要删除的一个或多个时间序列、时间序列的前缀、时间序列带、*路径对某一个时间区间内的数据进行删除。 + +在 JAVA 编程环境中,您可以使用 JDBC API 单条或批量执行 DELETE 语句。 + +## 1. 单传感器时间序列值删除 + +以测控 ln 集团为例,存在这样的使用场景: + +wf02 子站的 wt02 设备在 2017-11-01 16:26:00 之前的供电状态出现多段错误,且无法分析其正确数据,错误数据影响了与其他设备的关联分析。此时,需要将此时间段前的数据删除。进行此操作的 SQL 语句为: + +```sql +delete from root.ln.wf02.wt02.status where time<=2017-11-01T16:26:00; +``` + +如果我们仅仅想要删除 2017 年内的在 2017-11-01 16:26:00 之前的数据,可以使用以下 SQL: +```sql +delete from root.ln.wf02.wt02.status where time>=2017-01-01T00:00:00 and time<=2017-11-01T16:26:00; +``` + +IoTDB 支持删除一个时间序列任何一个时间范围内的所有时序点,用户可以使用以下 SQL 语句指定需要删除的时间范围: +```sql +delete from root.ln.wf02.wt02.status where time < 10 +delete from root.ln.wf02.wt02.status where time <= 10 +delete from root.ln.wf02.wt02.status where time < 20 and time > 10 +delete from root.ln.wf02.wt02.status where time <= 20 and time >= 10 +delete from root.ln.wf02.wt02.status where time > 20 +delete from root.ln.wf02.wt02.status where time >= 20 +delete from root.ln.wf02.wt02.status where time = 20 +``` + +需要注意,当前的删除语句不支持 where 子句后的时间范围为多个由 OR 连接成的时间区间。如下删除语句将会解析出错: +``` +delete from root.ln.wf02.wt02.status where time > 4 or time < 0 +Msg: 303: Check metadata error: For delete statement, where clause can only contain atomic +expressions like : time > XXX, time <= XXX, or two atomic expressions connected by 'AND' +``` + +如果 delete 语句中未指定 where 子句,则会删除时间序列中的所有数据。 +```sql +delete from root.ln.wf02.wt02.status +``` + +## 2. 多传感器时间序列值删除 + +当 ln 集团 wf02 子站的 wt02 设备在 2017-11-01 16:26:00 之前的供电状态和设备硬件版本都需要删除,此时可以使用含义更广的 [路径模式(Path Pattern)](../Basic-Concept/Operate-Metadata.md) 进行删除操作,进行此操作的 SQL 语句为: + + +```sql +delete from root.ln.wf02.wt02.* where time <= 2017-11-01T16:26:00; +``` + +需要注意的是,当删除的路径不存在时,IoTDB 不会提示路径不存在,而是显示执行成功,因为 SQL 是一种声明式的编程方式,除非是语法错误、权限不足等,否则都不认为是错误,如下所示。 + +```sql +IoTDB> delete from root.ln.wf03.wt02.status where time < now() +Msg: The statement is executed successfully. +``` + +## 3. 删除时间分区 (实验性功能) +您可以通过如下语句来删除某一个 database 下的指定时间分区: + +```sql +DELETE PARTITION root.ln 0,1,2 +``` + +上例中的 0,1,2 为待删除时间分区的 id,您可以通过查看 IoTDB 的数据文件夹找到它,或者可以通过计算`timestamp / partitionInterval`(向下取整), +手动地将一个时间戳转换为对应的 id,其中的`partitionInterval`可以在 IoTDB 的配置文件中找到(如果您使用的版本支持时间分区)。 + +请注意该功能目前只是实验性的,如果您不是开发者,使用时请务必谨慎。 \ No newline at end of file diff --git a/src/zh/UserGuide/Master/Tree/Basic-Concept/TTL-Delete.md b/src/zh/UserGuide/Master/Tree/Basic-Concept/TTL-Delete.md new file mode 100644 index 000000000..761d039a2 --- /dev/null +++ b/src/zh/UserGuide/Master/Tree/Basic-Concept/TTL-Delete.md @@ -0,0 +1,132 @@ + +# 过期自动删除 + +## 1. 概览 + +IoTDB 支持对 device 级别设置数据存活时间(TTL),这使得 IoTDB 可以定期、自动地删除一定时间之前的数据。合理使用 TTL +可以帮助您控制 IoTDB 占用的总磁盘空间以避免出现磁盘写满等异常。并且,随着文件数量的增多,查询性能往往随之下降, +内存占用也会有所提高。及时地删除一些较老的文件有助于使查询性能维持在一个较高的水平和减少内存资源的占用。 + +TTL的默认单位为毫秒,如果配置文件中的时间精度修改为其他单位,设置ttl时仍然使用毫秒单位。 + +当设置 TTL 时,系统会根据设置的路径寻找所包含的所有 device,并为这些 device 设置 TTL 时间,系统会按设备粒度对过期数据进行删除。 +当设备数据过期后,将不能被查询到,但磁盘文件中的数据不能保证立即删除(会在一定时间内删除),但可以保证最终被删除。 +考虑到操作代价,系统不会立即物理删除超过 TTL 的数据,而是通过合并来延迟地物理删除。因此,在数据被物理删除前,如果调小或者解除 TTL,可能会导致之前因 TTL 而不可见的数据重新出现。 +系统中仅能设置至多 1000 条 TTL 规则,达到该上限时,需要先删除部分 TTL 规则才能设置新的规则 + +## 2. 设置TTL +### 2.1 TTL Path 规则 +设置的路径 path 只支持前缀路径(即路径中间不能带 \* , 且必须以 \*\* 结尾),该路径会匹配到设备,也允许用户指定不带星的 path 为具体的 database 或 device,当 path 不带 \* 时,会检查是否匹配到 database,若匹配到 database,则会同时设置 path 和 path.\*\*。 +注意:设备 TTL 设置不会对元数据的存在性进行校验,即允许对一条不存在的设备设置 TTL。 +``` +合格的 path: +root.** +root.db.** +root.db.group1.** +root.db +root.db.group1.d1 + +不合格的 path: +root.*.db +root.**.db.* +root.db.* +``` +### 2.2 TTL 适用规则 +当一个设备适用多条TTL规则时,优先适用较精确和较长的规则。例如对于设备“root.bj.hd.dist001.turbine001”来说,规则“root.bj.hd.dist001.turbine001”比“root.bj.hd.dist001.\*\*”优先,而规则“root.bj.hd.dist001.\*\*”比“root.bj.hd.\*\*”优先; +### 2.3 设置 TTL +set ttl 操作可以理解为设置一条 TTL规则,比如 set ttl to root.sg.group1.\*\* 就相当于对所有可以匹配到该路径模式的设备挂载 ttl。 unset ttl 操作表示对相应路径模式卸载 TTL,若不存在对应 TTL,则不做任何事。若想把 TTL 调成无限大,则可以使用 INF 关键字 +设置 TTL 的 SQL 语句如下所示: +``` +set ttl to pathPattern 360000; +``` +pathPattern 是前缀路径,即路径中间不能带 \* 且必须以 \*\* 结尾。 +pathPattern 匹配对应的设备。为了兼容老版本 SQL 语法,允许用户输入的 pathPattern 匹配到 db,则自动将前缀路径扩展为 path.\*\*。 +例如,写set ttl to root.sg 360000 则会自动转化为set ttl to root.sg.\*\* 360000,转化后的语句对所有 root.sg 下的 device 设置TTL。 +但若写的 pathPattern 无法匹配到 db,则上述逻辑不会生效。 +如写set ttl to root.sg.group 360000 ,由于root.sg.group未匹配到 db,则不会被扩充为root.sg.group.\*\*。 也允许指定具体 device,不带 \*。 +## 3. 取消 TTL + +取消 TTL 的 SQL 语句如下所示: + +``` +IoTDB> unset ttl from root.ln +``` + +取消设置 TTL 后, `root.ln` 路径下所有的数据都会被保存。 +``` +IoTDB> unset ttl from root.sgcc.** +``` + +取消设置`root.sgcc`路径下的所有的 TTL 。 +``` +IoTDB> unset ttl from root.** +``` + +取消设置所有的 TTL 。 + +新语法 +``` +IoTDB> unset ttl from root.** +``` + +旧语法 +``` +IoTDB> unset ttl to root.** +``` +新旧语法在功能上没有区别并且同时兼容,仅是新语法在用词上更符合常规。 +## 4. 显示 TTL + +显示 TTL 的 SQL 语句如下所示: +show all ttl + +``` +IoTDB> SHOW ALL TTL ++--------------+--------+ +| path| TTL| +| root.**|55555555| +| root.sg2.a.**|44440000| ++--------------+--------+ +``` + +show ttl on pathPattern +``` +IoTDB> SHOW TTL ON root.db.**; ++--------------+--------+ +| path| TTL| +| root.db.**|55555555| +| root.db.a.**|44440000| ++--------------+--------+ +``` +SHOW ALL TTL 这个例子会给出所有的 TTL。 +SHOW TTL ON pathPattern 这个例子会显示指定路径的 TTL。 + +显示设备的 TTL。 +``` +IoTDB> show devices ++---------------+---------+---------+ +| Device|IsAligned| TTL| ++---------------+---------+---------+ +|root.sg.device1| false| 36000000| +|root.sg.device2| true| INF| ++---------------+---------+---------+ +``` +所有设备都一定会有 TTL,即不可能是 null。INF 表示无穷大。 \ No newline at end of file diff --git a/src/zh/UserGuide/latest/Basic-Concept/Write-Delete-Data.md b/src/zh/UserGuide/Master/Tree/Basic-Concept/Write-Data.md similarity index 68% rename from src/zh/UserGuide/latest/Basic-Concept/Write-Delete-Data.md rename to src/zh/UserGuide/Master/Tree/Basic-Concept/Write-Data.md index 630b607e1..e35ac1bcb 100644 --- a/src/zh/UserGuide/latest/Basic-Concept/Write-Delete-Data.md +++ b/src/zh/UserGuide/Master/Tree/Basic-Concept/Write-Data.md @@ -20,7 +20,7 @@ --> -# 写入&删除 +# 数据写入 ## 1. CLI写入数据 IoTDB 为用户提供多种插入实时数据的方式,例如在 [Cli/Shell 工具](../Tools-System/CLI.md) 中直接输入插入数据的 INSERT 语句,或使用 Java API(标准 [Java JDBC](../API/Programming-JDBC.md) 接口)单条或批量执行插入数据的 INSERT 语句。 @@ -33,8 +33,6 @@ IoTDB 为用户提供多种插入实时数据的方式,例如在 [Cli/Shell 使用 INSERT 语句可以向指定的已经创建的一条或多条时间序列中插入数据。对于每一条数据,均由一个时间戳类型的时间戳和一个数值或布尔值、字符串类型的传感器采集值组成。 -**无模式写入**:可以在未定义元数据时, 通过 insert 语句直接写入数据,数据库中将自动识别并注册所需的元数据,实现自动建模。 - 在本节的场景实例下,以其中的两个时间序列`root.ln.wf02.wt02.status`和`root.ln.wf02.wt02.hardware`为例 ,它们的数据类型分别为 BOOLEAN 和 TEXT。 单列数据插入示例代码如下: @@ -184,75 +182,7 @@ TsFile 是在 IoTDB 中使用的时间序列的文件格式,您可以通过CLI CSV 是以纯文本形式存储表格数据,您可以在CSV文件中写入多条格式化的数据,并批量的将这些数据导入到 IoTDB 中,在导入数据之前,建议在IoTDB中创建好对应的元数据信息。如果忘记创建元数据也不要担心,IoTDB 可以自动将CSV中数据推断为其对应的数据类型,前提是你每一列的数据类型必须唯一。除单个文件外,此工具还支持以文件夹的形式导入多个 CSV 文件,并且支持设置如时间精度等优化参数。具体操作方式请参考[数据导入](../Tools-System/Data-Import-Tool.md)。 -## 6. 删除数据 - -用户使用 [DELETE 语句](../SQL-Manual/SQL-Manual.md#删除数据) 可以删除指定的时间序列中符合时间删除条件的数据。在删除数据时,用户可以选择需要删除的一个或多个时间序列、时间序列的前缀、时间序列带、*路径对某一个时间区间内的数据进行删除。 - -在 JAVA 编程环境中,您可以使用 JDBC API 单条或批量执行 DELETE 语句。 - -### 6.1 单传感器时间序列值删除 - -以测控 ln 集团为例,存在这样的使用场景: - -wf02 子站的 wt02 设备在 2017-11-01 16:26:00 之前的供电状态出现多段错误,且无法分析其正确数据,错误数据影响了与其他设备的关联分析。此时,需要将此时间段前的数据删除。进行此操作的 SQL 语句为: - -```sql -delete from root.ln.wf02.wt02.status where time<=2017-11-01T16:26:00; -``` - -如果我们仅仅想要删除 2017 年内的在 2017-11-01 16:26:00 之前的数据,可以使用以下 SQL: -```sql -delete from root.ln.wf02.wt02.status where time>=2017-01-01T00:00:00 and time<=2017-11-01T16:26:00; -``` - -IoTDB 支持删除一个时间序列任何一个时间范围内的所有时序点,用户可以使用以下 SQL 语句指定需要删除的时间范围: -```sql -delete from root.ln.wf02.wt02.status where time < 10 -delete from root.ln.wf02.wt02.status where time <= 10 -delete from root.ln.wf02.wt02.status where time < 20 and time > 10 -delete from root.ln.wf02.wt02.status where time <= 20 and time >= 10 -delete from root.ln.wf02.wt02.status where time > 20 -delete from root.ln.wf02.wt02.status where time >= 20 -delete from root.ln.wf02.wt02.status where time = 20 -``` - -需要注意,当前的删除语句不支持 where 子句后的时间范围为多个由 OR 连接成的时间区间。如下删除语句将会解析出错: -``` -delete from root.ln.wf02.wt02.status where time > 4 or time < 0 -Msg: 303: Check metadata error: For delete statement, where clause can only contain atomic -expressions like : time > XXX, time <= XXX, or two atomic expressions connected by 'AND' -``` - -如果 delete 语句中未指定 where 子句,则会删除时间序列中的所有数据。 -```sql -delete from root.ln.wf02.wt02.status -``` - -### 6.2 多传感器时间序列值删除 - -当 ln 集团 wf02 子站的 wt02 设备在 2017-11-01 16:26:00 之前的供电状态和设备硬件版本都需要删除,此时可以使用含义更广的 [路径模式(Path Pattern)](../Basic-Concept/Operate-Metadata.md) 进行删除操作,进行此操作的 SQL 语句为: - - -```sql -delete from root.ln.wf02.wt02.* where time <= 2017-11-01T16:26:00; -``` - -需要注意的是,当删除的路径不存在时,IoTDB 不会提示路径不存在,而是显示执行成功,因为 SQL 是一种声明式的编程方式,除非是语法错误、权限不足等,否则都不认为是错误,如下所示。 - -```sql -IoTDB> delete from root.ln.wf03.wt02.status where time < now() -Msg: The statement is executed successfully. -``` - -### 6.3 删除时间分区 (实验性功能) -您可以通过如下语句来删除某一个 database 下的指定时间分区: - -```sql -DELETE PARTITION root.ln 0,1,2 -``` - -上例中的 0,1,2 为待删除时间分区的 id,您可以通过查看 IoTDB 的数据文件夹找到它,或者可以通过计算`timestamp / partitionInterval`(向下取整), -手动地将一个时间戳转换为对应的 id,其中的`partitionInterval`可以在 IoTDB 的配置文件中找到(如果您使用的版本支持时间分区)。 - -请注意该功能目前只是实验性的,如果您不是开发者,使用时请务必谨慎。 +## 6. 无模式写入 +在物联网场景中,由于设备的类型、数量可能随时间动态增减,不同设备可能产生不同字段的数据(如温度、湿度、状态码等),业务上又往往需要快速部署,需要灵活接入新设备且无需繁琐的预定义流程。因此,不同于传统时序数据库通常需要预先定义数据模型,IoTDB支持不提前创建元数据,在写入数据时,数据库中将自动识别并注册所需的元数据,实现自动建模。 +用户既可以通过CLI使用insert语句或者原生接口的方式,批量或者单行实时写入一个设备或者多个设备的测点数据,也可以通过导入工具导入csv,TsFile等格式的历史数据,在导入过程中会自动创建序列,数据类型,压缩编码方式等元数据。 diff --git a/src/zh/UserGuide/Master/Tree/QuickStart/QuickStart_apache.md b/src/zh/UserGuide/Master/Tree/QuickStart/QuickStart_apache.md index 842da6c2a..f7c9de22e 100644 --- a/src/zh/UserGuide/Master/Tree/QuickStart/QuickStart_apache.md +++ b/src/zh/UserGuide/Master/Tree/QuickStart/QuickStart_apache.md @@ -51,7 +51,7 @@ - SQL 语法介绍:[SQL 语法介绍](../Basic-Concept/Operate-Metadata_apache.md) -2. 数据写入:在数据写入方面,IoTDB 提供了多种方式来插入实时数据,基本的数据写入操作请查看 [数据写入](../Basic-Concept/Write-Delete-Data.md) +2. 数据写入:在数据写入方面,IoTDB 提供了多种方式来插入实时数据,基本的数据写入操作请查看 [数据写入](../Basic-Concept/Write-Data) 3. 数据查询:IoTDB 提供了丰富的数据查询功能,数据查询的基本介绍请查看 [数据查询](../Basic-Concept/Query-Data.md) diff --git a/src/zh/UserGuide/Master/Tree/QuickStart/QuickStart_timecho.md b/src/zh/UserGuide/Master/Tree/QuickStart/QuickStart_timecho.md index b9012e786..b7ec15ec5 100644 --- a/src/zh/UserGuide/Master/Tree/QuickStart/QuickStart_timecho.md +++ b/src/zh/UserGuide/Master/Tree/QuickStart/QuickStart_timecho.md @@ -59,7 +59,7 @@ - SQL 语法介绍:[SQL 语法介绍](../Basic-Concept/Operate-Metadata_timecho.md) -2. 数据写入:在数据写入方面,IoTDB 提供了多种方式来插入实时数据,基本的数据写入操作请查看 [数据写入](../Basic-Concept/Write-Delete-Data.md) +2. 数据写入:在数据写入方面,IoTDB 提供了多种方式来插入实时数据,基本的数据写入操作请查看 [数据写入](../Basic-Concept/Write-Data) 3. 数据查询:IoTDB 提供了丰富的数据查询功能,数据查询的基本介绍请查看 [数据查询](../Basic-Concept/Query-Data.md) diff --git a/src/zh/UserGuide/V1.3.x/Basic-Concept/Delete-Data.md b/src/zh/UserGuide/V1.3.x/Basic-Concept/Delete-Data.md new file mode 100644 index 000000000..b8466aa29 --- /dev/null +++ b/src/zh/UserGuide/V1.3.x/Basic-Concept/Delete-Data.md @@ -0,0 +1,91 @@ + +# 数据删除 + +用户使用 [DELETE 语句](../SQL-Manual/SQL-Manual.md#删除数据) 可以删除指定的时间序列中符合时间删除条件的数据。在删除数据时,用户可以选择需要删除的一个或多个时间序列、时间序列的前缀、时间序列带、*路径对某一个时间区间内的数据进行删除。 + +在 JAVA 编程环境中,您可以使用 JDBC API 单条或批量执行 DELETE 语句。 + +## 单传感器时间序列值删除 + +以测控 ln 集团为例,存在这样的使用场景: + +wf02 子站的 wt02 设备在 2017-11-01 16:26:00 之前的供电状态出现多段错误,且无法分析其正确数据,错误数据影响了与其他设备的关联分析。此时,需要将此时间段前的数据删除。进行此操作的 SQL 语句为: + +```sql +delete from root.ln.wf02.wt02.status where time<=2017-11-01T16:26:00; +``` + +如果我们仅仅想要删除 2017 年内的在 2017-11-01 16:26:00 之前的数据,可以使用以下 SQL: +```sql +delete from root.ln.wf02.wt02.status where time>=2017-01-01T00:00:00 and time<=2017-11-01T16:26:00; +``` + +IoTDB 支持删除一个时间序列任何一个时间范围内的所有时序点,用户可以使用以下 SQL 语句指定需要删除的时间范围: +```sql +delete from root.ln.wf02.wt02.status where time < 10 +delete from root.ln.wf02.wt02.status where time <= 10 +delete from root.ln.wf02.wt02.status where time < 20 and time > 10 +delete from root.ln.wf02.wt02.status where time <= 20 and time >= 10 +delete from root.ln.wf02.wt02.status where time > 20 +delete from root.ln.wf02.wt02.status where time >= 20 +delete from root.ln.wf02.wt02.status where time = 20 +``` + +需要注意,当前的删除语句不支持 where 子句后的时间范围为多个由 OR 连接成的时间区间。如下删除语句将会解析出错: +``` +delete from root.ln.wf02.wt02.status where time > 4 or time < 0 +Msg: 303: Check metadata error: For delete statement, where clause can only contain atomic +expressions like : time > XXX, time <= XXX, or two atomic expressions connected by 'AND' +``` + +如果 delete 语句中未指定 where 子句,则会删除时间序列中的所有数据。 +```sql +delete from root.ln.wf02.wt02.status +``` + +## 多传感器时间序列值删除 + +当 ln 集团 wf02 子站的 wt02 设备在 2017-11-01 16:26:00 之前的供电状态和设备硬件版本都需要删除,此时可以使用含义更广的 [路径模式(Path Pattern)](../Basic-Concept/Data-Model-and-Terminology.md) 进行删除操作,进行此操作的 SQL 语句为: + + +```sql +delete from root.ln.wf02.wt02.* where time <= 2017-11-01T16:26:00; +``` + +需要注意的是,当删除的路径不存在时,IoTDB 不会提示路径不存在,而是显示执行成功,因为 SQL 是一种声明式的编程方式,除非是语法错误、权限不足等,否则都不认为是错误,如下所示。 + +```sql +IoTDB> delete from root.ln.wf03.wt02.status where time < now() +Msg: The statement is executed successfully. +``` + +## 删除时间分区 (实验性功能) +您可以通过如下语句来删除某一个 database 下的指定时间分区: + +```sql +DELETE PARTITION root.ln 0,1,2 +``` + +上例中的 0,1,2 为待删除时间分区的 id,您可以通过查看 IoTDB 的数据文件夹找到它,或者可以通过计算`timestamp / partitionInterval`(向下取整), +手动地将一个时间戳转换为对应的 id,其中的`partitionInterval`可以在 IoTDB 的配置文件中找到(如果您使用的版本支持时间分区)。 + +请注意该功能目前只是实验性的,如果您不是开发者,使用时请务必谨慎。 \ No newline at end of file diff --git a/src/zh/UserGuide/V1.3.x/Basic-Concept/TTL-Delete.md b/src/zh/UserGuide/V1.3.x/Basic-Concept/TTL-Delete.md new file mode 100644 index 000000000..5cadcf96a --- /dev/null +++ b/src/zh/UserGuide/V1.3.x/Basic-Concept/TTL-Delete.md @@ -0,0 +1,132 @@ + +# 过期自动删除 + +## 概览 + +IoTDB 支持对 device 级别设置数据存活时间(TTL),这使得 IoTDB 可以定期、自动地删除一定时间之前的数据。合理使用 TTL +可以帮助您控制 IoTDB 占用的总磁盘空间以避免出现磁盘写满等异常。并且,随着文件数量的增多,查询性能往往随之下降, +内存占用也会有所提高。及时地删除一些较老的文件有助于使查询性能维持在一个较高的水平和减少内存资源的占用。 + +TTL的默认单位为毫秒,如果配置文件中的时间精度修改为其他单位,设置ttl时仍然使用毫秒单位。 + +当设置 TTL 时,系统会根据设置的路径寻找所包含的所有 device,并为这些 device 设置 TTL 时间,系统会按设备粒度对过期数据进行删除。 +当设备数据过期后,将不能被查询到,但磁盘文件中的数据不能保证立即删除(会在一定时间内删除),但可以保证最终被删除。 +考虑到操作代价,系统不会立即物理删除超过 TTL 的数据,而是通过合并来延迟地物理删除。因此,在数据被物理删除前,如果调小或者解除 TTL,可能会导致之前因 TTL 而不可见的数据重新出现。 +系统中仅能设置至多 1000 条 TTL 规则,达到该上限时,需要先删除部分 TTL 规则才能设置新的规则 + +## 设置TTL +### TTL Path 规则 +设置的路径 path 只支持前缀路径(即路径中间不能带 \* , 且必须以 \*\* 结尾),该路径会匹配到设备,也允许用户指定不带星的 path 为具体的 database 或 device,当 path 不带 \* 时,会检查是否匹配到 database,若匹配到 database,则会同时设置 path 和 path.\*\*。 +注意:设备 TTL 设置不会对元数据的存在性进行校验,即允许对一条不存在的设备设置 TTL。 +``` +合格的 path: +root.** +root.db.** +root.db.group1.** +root.db +root.db.group1.d1 + +不合格的 path: +root.*.db +root.**.db.* +root.db.* +``` +### TTL 适用规则 +当一个设备适用多条TTL规则时,优先适用较精确和较长的规则。例如对于设备“root.bj.hd.dist001.turbine001”来说,规则“root.bj.hd.dist001.turbine001”比“root.bj.hd.dist001.\*\*”优先,而规则“root.bj.hd.dist001.\*\*”比“root.bj.hd.\*\*”优先; +### 设置 TTL +set ttl 操作可以理解为设置一条 TTL规则,比如 set ttl to root.sg.group1.\*\* 就相当于对所有可以匹配到该路径模式的设备挂载 ttl。 unset ttl 操作表示对相应路径模式卸载 TTL,若不存在对应 TTL,则不做任何事。若想把 TTL 调成无限大,则可以使用 INF 关键字 +设置 TTL 的 SQL 语句如下所示: +``` +set ttl to pathPattern 360000; +``` +pathPattern 是前缀路径,即路径中间不能带 \* 且必须以 \*\* 结尾。 +pathPattern 匹配对应的设备。为了兼容老版本 SQL 语法,允许用户输入的 pathPattern 匹配到 db,则自动将前缀路径扩展为 path.\*\*。 +例如,写set ttl to root.sg 360000 则会自动转化为set ttl to root.sg.\*\* 360000,转化后的语句对所有 root.sg 下的 device 设置TTL。 +但若写的 pathPattern 无法匹配到 db,则上述逻辑不会生效。 +如写set ttl to root.sg.group 360000 ,由于root.sg.group未匹配到 db,则不会被扩充为root.sg.group.\*\*。 也允许指定具体 device,不带 \*。 +## 取消 TTL + +取消 TTL 的 SQL 语句如下所示: + +``` +IoTDB> unset ttl from root.ln +``` + +取消设置 TTL 后, `root.ln` 路径下所有的数据都会被保存。 +``` +IoTDB> unset ttl from root.sgcc.** +``` + +取消设置`root.sgcc`路径下的所有的 TTL 。 +``` +IoTDB> unset ttl from root.** +``` + +取消设置所有的 TTL 。 + +新语法 +``` +IoTDB> unset ttl from root.** +``` + +旧语法 +``` +IoTDB> unset ttl to root.** +``` +新旧语法在功能上没有区别并且同时兼容,仅是新语法在用词上更符合常规。 +## 显示 TTL + +显示 TTL 的 SQL 语句如下所示: +show all ttl + +``` +IoTDB> SHOW ALL TTL ++--------------+--------+ +| path| TTL| +| root.**|55555555| +| root.sg2.a.**|44440000| ++--------------+--------+ +``` + +show ttl on pathPattern +``` +IoTDB> SHOW TTL ON root.db.**; ++--------------+--------+ +| path| TTL| +| root.db.**|55555555| +| root.db.a.**|44440000| ++--------------+--------+ +``` +SHOW ALL TTL 这个例子会给出所有的 TTL。 +SHOW TTL ON pathPattern 这个例子会显示指定路径的 TTL。 + +显示设备的 TTL。 +``` +IoTDB> show devices ++---------------+---------+---------+ +| Device|IsAligned| TTL| ++---------------+---------+---------+ +|root.sg.device1| false| 36000000| +|root.sg.device2| true| INF| ++---------------+---------+---------+ +``` +所有设备都一定会有 TTL,即不可能是 null。INF 表示无穷大。 \ No newline at end of file diff --git a/src/zh/UserGuide/V1.3.x/Basic-Concept/Write-Delete-Data.md b/src/zh/UserGuide/V1.3.x/Basic-Concept/Write-Data.md similarity index 68% rename from src/zh/UserGuide/V1.3.x/Basic-Concept/Write-Delete-Data.md rename to src/zh/UserGuide/V1.3.x/Basic-Concept/Write-Data.md index 371198097..1b53fa8d4 100644 --- a/src/zh/UserGuide/V1.3.x/Basic-Concept/Write-Delete-Data.md +++ b/src/zh/UserGuide/V1.3.x/Basic-Concept/Write-Data.md @@ -20,7 +20,7 @@ --> -# 数据写入与删除 +# 数据写入 ## CLI写入数据 IoTDB 为用户提供多种插入实时数据的方式,例如在 [Cli/Shell 工具](../Tools-System/CLI.md) 中直接输入插入数据的 INSERT 语句,或使用 Java API(标准 [Java JDBC](../API/Programming-JDBC.md) 接口)单条或批量执行插入数据的 INSERT 语句。 @@ -33,8 +33,6 @@ IoTDB 为用户提供多种插入实时数据的方式,例如在 [Cli/Shell 使用 INSERT 语句可以向指定的已经创建的一条或多条时间序列中插入数据。对于每一条数据,均由一个时间戳类型的时间戳和一个数值或布尔值、字符串类型的传感器采集值组成。 -**无模式写入**:可以在未定义元数据时, 通过 insert 语句直接写入数据,数据库中将自动识别并注册所需的元数据,实现自动建模。 - 在本节的场景实例下,以其中的两个时间序列`root.ln.wf02.wt02.status`和`root.ln.wf02.wt02.hardware`为例 ,它们的数据类型分别为 BOOLEAN 和 TEXT。 单列数据插入示例代码如下: @@ -184,75 +182,11 @@ TsFile 是在 IoTDB 中使用的时间序列的文件格式,您可以通过CLI CSV 是以纯文本形式存储表格数据,您可以在CSV文件中写入多条格式化的数据,并批量的将这些数据导入到 IoTDB 中,在导入数据之前,建议在IoTDB中创建好对应的元数据信息。如果忘记创建元数据也不要担心,IoTDB 可以自动将CSV中数据推断为其对应的数据类型,前提是你每一列的数据类型必须唯一。除单个文件外,此工具还支持以文件夹的形式导入多个 CSV 文件,并且支持设置如时间精度等优化参数。具体操作方式请参考[数据导入](../Tools-System/Data-Import-Tool.md)。 -## 删除数据 - -用户使用 [DELETE 语句](../SQL-Manual/SQL-Manual.md#删除数据) 可以删除指定的时间序列中符合时间删除条件的数据。在删除数据时,用户可以选择需要删除的一个或多个时间序列、时间序列的前缀、时间序列带、*路径对某一个时间区间内的数据进行删除。 - -在 JAVA 编程环境中,您可以使用 JDBC API 单条或批量执行 DELETE 语句。 - -### 单传感器时间序列值删除 - -以测控 ln 集团为例,存在这样的使用场景: - -wf02 子站的 wt02 设备在 2017-11-01 16:26:00 之前的供电状态出现多段错误,且无法分析其正确数据,错误数据影响了与其他设备的关联分析。此时,需要将此时间段前的数据删除。进行此操作的 SQL 语句为: - -```sql -delete from root.ln.wf02.wt02.status where time<=2017-11-01T16:26:00; -``` +## 无模式写入 +在物联网场景中,由于设备的类型、数量可能随时间动态增减,不同设备可能产生不同字段的数据(如温度、湿度、状态码等),业务上又往往需要快速部署,需要灵活接入新设备且无需繁琐的预定义流程。因此,不同于传统时序数据库通常需要预先定义数据模型,IoTDB支持不提前创建元数据,在写入数据时,数据库中将自动识别并注册所需的元数据,实现自动建模。 -如果我们仅仅想要删除 2017 年内的在 2017-11-01 16:26:00 之前的数据,可以使用以下 SQL: -```sql -delete from root.ln.wf02.wt02.status where time>=2017-01-01T00:00:00 and time<=2017-11-01T16:26:00; -``` - -IoTDB 支持删除一个时间序列任何一个时间范围内的所有时序点,用户可以使用以下 SQL 语句指定需要删除的时间范围: -```sql -delete from root.ln.wf02.wt02.status where time < 10 -delete from root.ln.wf02.wt02.status where time <= 10 -delete from root.ln.wf02.wt02.status where time < 20 and time > 10 -delete from root.ln.wf02.wt02.status where time <= 20 and time >= 10 -delete from root.ln.wf02.wt02.status where time > 20 -delete from root.ln.wf02.wt02.status where time >= 20 -delete from root.ln.wf02.wt02.status where time = 20 -``` - -需要注意,当前的删除语句不支持 where 子句后的时间范围为多个由 OR 连接成的时间区间。如下删除语句将会解析出错: -``` -delete from root.ln.wf02.wt02.status where time > 4 or time < 0 -Msg: 303: Check metadata error: For delete statement, where clause can only contain atomic -expressions like : time > XXX, time <= XXX, or two atomic expressions connected by 'AND' -``` +用户既可以通过CLI使用insert语句或者原生接口的方式,批量或者单行实时写入一个设备或者多个设备的测点数据,也可以通过导入工具导入csv,TsFile等格式的历史数据,在导入过程中会自动创建序列,数据类型,压缩编码方式等元数据。 -如果 delete 语句中未指定 where 子句,则会删除时间序列中的所有数据。 -```sql -delete from root.ln.wf02.wt02.status -``` - -### 多传感器时间序列值删除 - -当 ln 集团 wf02 子站的 wt02 设备在 2017-11-01 16:26:00 之前的供电状态和设备硬件版本都需要删除,此时可以使用含义更广的 [路径模式(Path Pattern)](../Basic-Concept/Data-Model-and-Terminology.md) 进行删除操作,进行此操作的 SQL 语句为: - - -```sql -delete from root.ln.wf02.wt02.* where time <= 2017-11-01T16:26:00; -``` - -需要注意的是,当删除的路径不存在时,IoTDB 不会提示路径不存在,而是显示执行成功,因为 SQL 是一种声明式的编程方式,除非是语法错误、权限不足等,否则都不认为是错误,如下所示。 - -```sql -IoTDB> delete from root.ln.wf03.wt02.status where time < now() -Msg: The statement is executed successfully. -``` - -### 删除时间分区 (实验性功能) -您可以通过如下语句来删除某一个 database 下的指定时间分区: - -```sql -DELETE PARTITION root.ln 0,1,2 -``` -上例中的 0,1,2 为待删除时间分区的 id,您可以通过查看 IoTDB 的数据文件夹找到它,或者可以通过计算`timestamp / partitionInterval`(向下取整), -手动地将一个时间戳转换为对应的 id,其中的`partitionInterval`可以在 IoTDB 的配置文件中找到(如果您使用的版本支持时间分区)。 -请注意该功能目前只是实验性的,如果您不是开发者,使用时请务必谨慎。 diff --git a/src/zh/UserGuide/V1.3.x/QuickStart/QuickStart_apache.md b/src/zh/UserGuide/V1.3.x/QuickStart/QuickStart_apache.md index 16043b755..6594ea73f 100644 --- a/src/zh/UserGuide/V1.3.x/QuickStart/QuickStart_apache.md +++ b/src/zh/UserGuide/V1.3.x/QuickStart/QuickStart_apache.md @@ -51,7 +51,7 @@ - SQL 语法介绍:[SQL 语法介绍](../Basic-Concept/Operate-Metadata_apache.md) -2. 数据写入:在数据写入方面,IoTDB 提供了多种方式来插入实时数据,基本的数据写入操作请查看 [数据写入](../Basic-Concept/Write-Delete-Data.md) +2. 数据写入:在数据写入方面,IoTDB 提供了多种方式来插入实时数据,基本的数据写入操作请查看 [数据写入](../Basic-Concept/Write-Data) 3. 数据查询:IoTDB 提供了丰富的数据查询功能,数据查询的基本介绍请查看 [数据查询](../Basic-Concept/Query-Data.md) diff --git a/src/zh/UserGuide/V1.3.x/QuickStart/QuickStart_timecho.md b/src/zh/UserGuide/V1.3.x/QuickStart/QuickStart_timecho.md index bcd0285eb..e395f7732 100644 --- a/src/zh/UserGuide/V1.3.x/QuickStart/QuickStart_timecho.md +++ b/src/zh/UserGuide/V1.3.x/QuickStart/QuickStart_timecho.md @@ -59,7 +59,7 @@ - SQL 语法介绍:[SQL 语法介绍](../Basic-Concept/Operate-Metadata_timecho.md) -2. 数据写入:在数据写入方面,IoTDB 提供了多种方式来插入实时数据,基本的数据写入操作请查看 [数据写入](../Basic-Concept/Write-Delete-Data.md) +2. 数据写入:在数据写入方面,IoTDB 提供了多种方式来插入实时数据,基本的数据写入操作请查看 [数据写入](../Basic-Concept/Write-Data) 3. 数据查询:IoTDB 提供了丰富的数据查询功能,数据查询的基本介绍请查看 [数据查询](../Basic-Concept/Query-Data.md) diff --git a/src/zh/UserGuide/latest/Basic-Concept/Delete-Data.md b/src/zh/UserGuide/latest/Basic-Concept/Delete-Data.md new file mode 100644 index 000000000..184429c5b --- /dev/null +++ b/src/zh/UserGuide/latest/Basic-Concept/Delete-Data.md @@ -0,0 +1,91 @@ + +# 数据删除 + +用户使用 [DELETE 语句](../SQL-Manual/SQL-Manual.md#删除数据) 可以删除指定的时间序列中符合时间删除条件的数据。在删除数据时,用户可以选择需要删除的一个或多个时间序列、时间序列的前缀、时间序列带、*路径对某一个时间区间内的数据进行删除。 + +在 JAVA 编程环境中,您可以使用 JDBC API 单条或批量执行 DELETE 语句。 + +## 1. 单传感器时间序列值删除 + +以测控 ln 集团为例,存在这样的使用场景: + +wf02 子站的 wt02 设备在 2017-11-01 16:26:00 之前的供电状态出现多段错误,且无法分析其正确数据,错误数据影响了与其他设备的关联分析。此时,需要将此时间段前的数据删除。进行此操作的 SQL 语句为: + +```sql +delete from root.ln.wf02.wt02.status where time<=2017-11-01T16:26:00; +``` + +如果我们仅仅想要删除 2017 年内的在 2017-11-01 16:26:00 之前的数据,可以使用以下 SQL: +```sql +delete from root.ln.wf02.wt02.status where time>=2017-01-01T00:00:00 and time<=2017-11-01T16:26:00; +``` + +IoTDB 支持删除一个时间序列任何一个时间范围内的所有时序点,用户可以使用以下 SQL 语句指定需要删除的时间范围: +```sql +delete from root.ln.wf02.wt02.status where time < 10 +delete from root.ln.wf02.wt02.status where time <= 10 +delete from root.ln.wf02.wt02.status where time < 20 and time > 10 +delete from root.ln.wf02.wt02.status where time <= 20 and time >= 10 +delete from root.ln.wf02.wt02.status where time > 20 +delete from root.ln.wf02.wt02.status where time >= 20 +delete from root.ln.wf02.wt02.status where time = 20 +``` + +需要注意,当前的删除语句不支持 where 子句后的时间范围为多个由 OR 连接成的时间区间。如下删除语句将会解析出错: +``` +delete from root.ln.wf02.wt02.status where time > 4 or time < 0 +Msg: 303: Check metadata error: For delete statement, where clause can only contain atomic +expressions like : time > XXX, time <= XXX, or two atomic expressions connected by 'AND' +``` + +如果 delete 语句中未指定 where 子句,则会删除时间序列中的所有数据。 +```sql +delete from root.ln.wf02.wt02.status +``` + +## 2. 多传感器时间序列值删除 + +当 ln 集团 wf02 子站的 wt02 设备在 2017-11-01 16:26:00 之前的供电状态和设备硬件版本都需要删除,此时可以使用含义更广的 [路径模式(Path Pattern)](../Basic-Concept/Operate-Metadata.md) 进行删除操作,进行此操作的 SQL 语句为: + + +```sql +delete from root.ln.wf02.wt02.* where time <= 2017-11-01T16:26:00; +``` + +需要注意的是,当删除的路径不存在时,IoTDB 不会提示路径不存在,而是显示执行成功,因为 SQL 是一种声明式的编程方式,除非是语法错误、权限不足等,否则都不认为是错误,如下所示。 + +```sql +IoTDB> delete from root.ln.wf03.wt02.status where time < now() +Msg: The statement is executed successfully. +``` + +## 3. 删除时间分区 (实验性功能) +您可以通过如下语句来删除某一个 database 下的指定时间分区: + +```sql +DELETE PARTITION root.ln 0,1,2 +``` + +上例中的 0,1,2 为待删除时间分区的 id,您可以通过查看 IoTDB 的数据文件夹找到它,或者可以通过计算`timestamp / partitionInterval`(向下取整), +手动地将一个时间戳转换为对应的 id,其中的`partitionInterval`可以在 IoTDB 的配置文件中找到(如果您使用的版本支持时间分区)。 + +请注意该功能目前只是实验性的,如果您不是开发者,使用时请务必谨慎。 \ No newline at end of file diff --git a/src/zh/UserGuide/latest/Basic-Concept/TTL-Delete.md b/src/zh/UserGuide/latest/Basic-Concept/TTL-Delete.md new file mode 100644 index 000000000..761d039a2 --- /dev/null +++ b/src/zh/UserGuide/latest/Basic-Concept/TTL-Delete.md @@ -0,0 +1,132 @@ + +# 过期自动删除 + +## 1. 概览 + +IoTDB 支持对 device 级别设置数据存活时间(TTL),这使得 IoTDB 可以定期、自动地删除一定时间之前的数据。合理使用 TTL +可以帮助您控制 IoTDB 占用的总磁盘空间以避免出现磁盘写满等异常。并且,随着文件数量的增多,查询性能往往随之下降, +内存占用也会有所提高。及时地删除一些较老的文件有助于使查询性能维持在一个较高的水平和减少内存资源的占用。 + +TTL的默认单位为毫秒,如果配置文件中的时间精度修改为其他单位,设置ttl时仍然使用毫秒单位。 + +当设置 TTL 时,系统会根据设置的路径寻找所包含的所有 device,并为这些 device 设置 TTL 时间,系统会按设备粒度对过期数据进行删除。 +当设备数据过期后,将不能被查询到,但磁盘文件中的数据不能保证立即删除(会在一定时间内删除),但可以保证最终被删除。 +考虑到操作代价,系统不会立即物理删除超过 TTL 的数据,而是通过合并来延迟地物理删除。因此,在数据被物理删除前,如果调小或者解除 TTL,可能会导致之前因 TTL 而不可见的数据重新出现。 +系统中仅能设置至多 1000 条 TTL 规则,达到该上限时,需要先删除部分 TTL 规则才能设置新的规则 + +## 2. 设置TTL +### 2.1 TTL Path 规则 +设置的路径 path 只支持前缀路径(即路径中间不能带 \* , 且必须以 \*\* 结尾),该路径会匹配到设备,也允许用户指定不带星的 path 为具体的 database 或 device,当 path 不带 \* 时,会检查是否匹配到 database,若匹配到 database,则会同时设置 path 和 path.\*\*。 +注意:设备 TTL 设置不会对元数据的存在性进行校验,即允许对一条不存在的设备设置 TTL。 +``` +合格的 path: +root.** +root.db.** +root.db.group1.** +root.db +root.db.group1.d1 + +不合格的 path: +root.*.db +root.**.db.* +root.db.* +``` +### 2.2 TTL 适用规则 +当一个设备适用多条TTL规则时,优先适用较精确和较长的规则。例如对于设备“root.bj.hd.dist001.turbine001”来说,规则“root.bj.hd.dist001.turbine001”比“root.bj.hd.dist001.\*\*”优先,而规则“root.bj.hd.dist001.\*\*”比“root.bj.hd.\*\*”优先; +### 2.3 设置 TTL +set ttl 操作可以理解为设置一条 TTL规则,比如 set ttl to root.sg.group1.\*\* 就相当于对所有可以匹配到该路径模式的设备挂载 ttl。 unset ttl 操作表示对相应路径模式卸载 TTL,若不存在对应 TTL,则不做任何事。若想把 TTL 调成无限大,则可以使用 INF 关键字 +设置 TTL 的 SQL 语句如下所示: +``` +set ttl to pathPattern 360000; +``` +pathPattern 是前缀路径,即路径中间不能带 \* 且必须以 \*\* 结尾。 +pathPattern 匹配对应的设备。为了兼容老版本 SQL 语法,允许用户输入的 pathPattern 匹配到 db,则自动将前缀路径扩展为 path.\*\*。 +例如,写set ttl to root.sg 360000 则会自动转化为set ttl to root.sg.\*\* 360000,转化后的语句对所有 root.sg 下的 device 设置TTL。 +但若写的 pathPattern 无法匹配到 db,则上述逻辑不会生效。 +如写set ttl to root.sg.group 360000 ,由于root.sg.group未匹配到 db,则不会被扩充为root.sg.group.\*\*。 也允许指定具体 device,不带 \*。 +## 3. 取消 TTL + +取消 TTL 的 SQL 语句如下所示: + +``` +IoTDB> unset ttl from root.ln +``` + +取消设置 TTL 后, `root.ln` 路径下所有的数据都会被保存。 +``` +IoTDB> unset ttl from root.sgcc.** +``` + +取消设置`root.sgcc`路径下的所有的 TTL 。 +``` +IoTDB> unset ttl from root.** +``` + +取消设置所有的 TTL 。 + +新语法 +``` +IoTDB> unset ttl from root.** +``` + +旧语法 +``` +IoTDB> unset ttl to root.** +``` +新旧语法在功能上没有区别并且同时兼容,仅是新语法在用词上更符合常规。 +## 4. 显示 TTL + +显示 TTL 的 SQL 语句如下所示: +show all ttl + +``` +IoTDB> SHOW ALL TTL ++--------------+--------+ +| path| TTL| +| root.**|55555555| +| root.sg2.a.**|44440000| ++--------------+--------+ +``` + +show ttl on pathPattern +``` +IoTDB> SHOW TTL ON root.db.**; ++--------------+--------+ +| path| TTL| +| root.db.**|55555555| +| root.db.a.**|44440000| ++--------------+--------+ +``` +SHOW ALL TTL 这个例子会给出所有的 TTL。 +SHOW TTL ON pathPattern 这个例子会显示指定路径的 TTL。 + +显示设备的 TTL。 +``` +IoTDB> show devices ++---------------+---------+---------+ +| Device|IsAligned| TTL| ++---------------+---------+---------+ +|root.sg.device1| false| 36000000| +|root.sg.device2| true| INF| ++---------------+---------+---------+ +``` +所有设备都一定会有 TTL,即不可能是 null。INF 表示无穷大。 \ No newline at end of file diff --git a/src/zh/UserGuide/Master/Tree/Basic-Concept/Write-Delete-Data.md b/src/zh/UserGuide/latest/Basic-Concept/Write-Data.md similarity index 68% rename from src/zh/UserGuide/Master/Tree/Basic-Concept/Write-Delete-Data.md rename to src/zh/UserGuide/latest/Basic-Concept/Write-Data.md index 630b607e1..e35ac1bcb 100644 --- a/src/zh/UserGuide/Master/Tree/Basic-Concept/Write-Delete-Data.md +++ b/src/zh/UserGuide/latest/Basic-Concept/Write-Data.md @@ -20,7 +20,7 @@ --> -# 写入&删除 +# 数据写入 ## 1. CLI写入数据 IoTDB 为用户提供多种插入实时数据的方式,例如在 [Cli/Shell 工具](../Tools-System/CLI.md) 中直接输入插入数据的 INSERT 语句,或使用 Java API(标准 [Java JDBC](../API/Programming-JDBC.md) 接口)单条或批量执行插入数据的 INSERT 语句。 @@ -33,8 +33,6 @@ IoTDB 为用户提供多种插入实时数据的方式,例如在 [Cli/Shell 使用 INSERT 语句可以向指定的已经创建的一条或多条时间序列中插入数据。对于每一条数据,均由一个时间戳类型的时间戳和一个数值或布尔值、字符串类型的传感器采集值组成。 -**无模式写入**:可以在未定义元数据时, 通过 insert 语句直接写入数据,数据库中将自动识别并注册所需的元数据,实现自动建模。 - 在本节的场景实例下,以其中的两个时间序列`root.ln.wf02.wt02.status`和`root.ln.wf02.wt02.hardware`为例 ,它们的数据类型分别为 BOOLEAN 和 TEXT。 单列数据插入示例代码如下: @@ -184,75 +182,7 @@ TsFile 是在 IoTDB 中使用的时间序列的文件格式,您可以通过CLI CSV 是以纯文本形式存储表格数据,您可以在CSV文件中写入多条格式化的数据,并批量的将这些数据导入到 IoTDB 中,在导入数据之前,建议在IoTDB中创建好对应的元数据信息。如果忘记创建元数据也不要担心,IoTDB 可以自动将CSV中数据推断为其对应的数据类型,前提是你每一列的数据类型必须唯一。除单个文件外,此工具还支持以文件夹的形式导入多个 CSV 文件,并且支持设置如时间精度等优化参数。具体操作方式请参考[数据导入](../Tools-System/Data-Import-Tool.md)。 -## 6. 删除数据 - -用户使用 [DELETE 语句](../SQL-Manual/SQL-Manual.md#删除数据) 可以删除指定的时间序列中符合时间删除条件的数据。在删除数据时,用户可以选择需要删除的一个或多个时间序列、时间序列的前缀、时间序列带、*路径对某一个时间区间内的数据进行删除。 - -在 JAVA 编程环境中,您可以使用 JDBC API 单条或批量执行 DELETE 语句。 - -### 6.1 单传感器时间序列值删除 - -以测控 ln 集团为例,存在这样的使用场景: - -wf02 子站的 wt02 设备在 2017-11-01 16:26:00 之前的供电状态出现多段错误,且无法分析其正确数据,错误数据影响了与其他设备的关联分析。此时,需要将此时间段前的数据删除。进行此操作的 SQL 语句为: - -```sql -delete from root.ln.wf02.wt02.status where time<=2017-11-01T16:26:00; -``` - -如果我们仅仅想要删除 2017 年内的在 2017-11-01 16:26:00 之前的数据,可以使用以下 SQL: -```sql -delete from root.ln.wf02.wt02.status where time>=2017-01-01T00:00:00 and time<=2017-11-01T16:26:00; -``` - -IoTDB 支持删除一个时间序列任何一个时间范围内的所有时序点,用户可以使用以下 SQL 语句指定需要删除的时间范围: -```sql -delete from root.ln.wf02.wt02.status where time < 10 -delete from root.ln.wf02.wt02.status where time <= 10 -delete from root.ln.wf02.wt02.status where time < 20 and time > 10 -delete from root.ln.wf02.wt02.status where time <= 20 and time >= 10 -delete from root.ln.wf02.wt02.status where time > 20 -delete from root.ln.wf02.wt02.status where time >= 20 -delete from root.ln.wf02.wt02.status where time = 20 -``` - -需要注意,当前的删除语句不支持 where 子句后的时间范围为多个由 OR 连接成的时间区间。如下删除语句将会解析出错: -``` -delete from root.ln.wf02.wt02.status where time > 4 or time < 0 -Msg: 303: Check metadata error: For delete statement, where clause can only contain atomic -expressions like : time > XXX, time <= XXX, or two atomic expressions connected by 'AND' -``` - -如果 delete 语句中未指定 where 子句,则会删除时间序列中的所有数据。 -```sql -delete from root.ln.wf02.wt02.status -``` - -### 6.2 多传感器时间序列值删除 - -当 ln 集团 wf02 子站的 wt02 设备在 2017-11-01 16:26:00 之前的供电状态和设备硬件版本都需要删除,此时可以使用含义更广的 [路径模式(Path Pattern)](../Basic-Concept/Operate-Metadata.md) 进行删除操作,进行此操作的 SQL 语句为: - - -```sql -delete from root.ln.wf02.wt02.* where time <= 2017-11-01T16:26:00; -``` - -需要注意的是,当删除的路径不存在时,IoTDB 不会提示路径不存在,而是显示执行成功,因为 SQL 是一种声明式的编程方式,除非是语法错误、权限不足等,否则都不认为是错误,如下所示。 - -```sql -IoTDB> delete from root.ln.wf03.wt02.status where time < now() -Msg: The statement is executed successfully. -``` - -### 6.3 删除时间分区 (实验性功能) -您可以通过如下语句来删除某一个 database 下的指定时间分区: - -```sql -DELETE PARTITION root.ln 0,1,2 -``` - -上例中的 0,1,2 为待删除时间分区的 id,您可以通过查看 IoTDB 的数据文件夹找到它,或者可以通过计算`timestamp / partitionInterval`(向下取整), -手动地将一个时间戳转换为对应的 id,其中的`partitionInterval`可以在 IoTDB 的配置文件中找到(如果您使用的版本支持时间分区)。 - -请注意该功能目前只是实验性的,如果您不是开发者,使用时请务必谨慎。 +## 6. 无模式写入 +在物联网场景中,由于设备的类型、数量可能随时间动态增减,不同设备可能产生不同字段的数据(如温度、湿度、状态码等),业务上又往往需要快速部署,需要灵活接入新设备且无需繁琐的预定义流程。因此,不同于传统时序数据库通常需要预先定义数据模型,IoTDB支持不提前创建元数据,在写入数据时,数据库中将自动识别并注册所需的元数据,实现自动建模。 +用户既可以通过CLI使用insert语句或者原生接口的方式,批量或者单行实时写入一个设备或者多个设备的测点数据,也可以通过导入工具导入csv,TsFile等格式的历史数据,在导入过程中会自动创建序列,数据类型,压缩编码方式等元数据。 diff --git a/src/zh/UserGuide/latest/QuickStart/QuickStart_apache.md b/src/zh/UserGuide/latest/QuickStart/QuickStart_apache.md index 842da6c2a..f7c9de22e 100644 --- a/src/zh/UserGuide/latest/QuickStart/QuickStart_apache.md +++ b/src/zh/UserGuide/latest/QuickStart/QuickStart_apache.md @@ -51,7 +51,7 @@ - SQL 语法介绍:[SQL 语法介绍](../Basic-Concept/Operate-Metadata_apache.md) -2. 数据写入:在数据写入方面,IoTDB 提供了多种方式来插入实时数据,基本的数据写入操作请查看 [数据写入](../Basic-Concept/Write-Delete-Data.md) +2. 数据写入:在数据写入方面,IoTDB 提供了多种方式来插入实时数据,基本的数据写入操作请查看 [数据写入](../Basic-Concept/Write-Data) 3. 数据查询:IoTDB 提供了丰富的数据查询功能,数据查询的基本介绍请查看 [数据查询](../Basic-Concept/Query-Data.md) diff --git a/src/zh/UserGuide/latest/QuickStart/QuickStart_timecho.md b/src/zh/UserGuide/latest/QuickStart/QuickStart_timecho.md index b9012e786..b7ec15ec5 100644 --- a/src/zh/UserGuide/latest/QuickStart/QuickStart_timecho.md +++ b/src/zh/UserGuide/latest/QuickStart/QuickStart_timecho.md @@ -59,7 +59,7 @@ - SQL 语法介绍:[SQL 语法介绍](../Basic-Concept/Operate-Metadata_timecho.md) -2. 数据写入:在数据写入方面,IoTDB 提供了多种方式来插入实时数据,基本的数据写入操作请查看 [数据写入](../Basic-Concept/Write-Delete-Data.md) +2. 数据写入:在数据写入方面,IoTDB 提供了多种方式来插入实时数据,基本的数据写入操作请查看 [数据写入](../Basic-Concept/Write-Data) 3. 数据查询:IoTDB 提供了丰富的数据查询功能,数据查询的基本介绍请查看 [数据查询](../Basic-Concept/Query-Data.md)