Skip to content

Commit 25d624a

Browse files
authored
fix-ttl-chinese (#740)
1 parent cbceba1 commit 25d624a

24 files changed

Lines changed: 494 additions & 181 deletions
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<!--
2+
3+
Licensed to the Apache Software Foundation (ASF) under one
4+
or more contributor license agreements. See the NOTICE file
5+
distributed with this work for additional information
6+
regarding copyright ownership. The ASF licenses this file
7+
to you under the Apache License, Version 2.0 (the
8+
"License"); you may not use this file except in compliance
9+
with the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing,
14+
software distributed under the License is distributed on an
15+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
KIND, either express or implied. See the License for the
17+
specific language governing permissions and limitations
18+
under the License.
19+
20+
-->
21+
# Delete Data
22+
23+
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.
24+
25+
In a JAVA programming environment, you can use the [Java JDBC](../API/Programming-JDBC.md) to execute single or batch UPDATE statements.
26+
27+
## Delete Single Timeseries
28+
29+
Taking ln Group as an example, there exists such a usage scenario:
30+
31+
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
32+
33+
```sql
34+
delete from root.ln.wf02.wt02.status where time<=2017-11-01T16:26:00;
35+
```
36+
37+
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:
38+
39+
```sql
40+
delete from root.ln.wf02.wt02.status where time>=2017-01-01T00:00:00 and time<=2017-11-01T16:26:00;
41+
```
42+
43+
IoTDB supports to delete a range of timeseries points. Users can write SQL expressions as follows to specify the delete interval:
44+
45+
```sql
46+
delete from root.ln.wf02.wt02.status where time < 10
47+
delete from root.ln.wf02.wt02.status where time <= 10
48+
delete from root.ln.wf02.wt02.status where time < 20 and time > 10
49+
delete from root.ln.wf02.wt02.status where time <= 20 and time >= 10
50+
delete from root.ln.wf02.wt02.status where time > 20
51+
delete from root.ln.wf02.wt02.status where time >= 20
52+
delete from root.ln.wf02.wt02.status where time = 20
53+
```
54+
55+
Please pay attention that multiple intervals connected by "OR" expression are not supported in delete statement:
56+
57+
```
58+
delete from root.ln.wf02.wt02.status where time > 4 or time < 0
59+
Msg: 303: Check metadata error: For delete statement, where clause can only contain atomic
60+
expressions like : time > XXX, time <= XXX, or two atomic expressions connected by 'AND'
61+
```
62+
63+
If no "where" clause specified in a delete statement, all the data in a timeseries will be deleted.
64+
65+
```sql
66+
delete from root.ln.wf02.wt02.status
67+
```
68+
69+
70+
## Delete Multiple Timeseries
71+
72+
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:
73+
74+
```sql
75+
delete from root.ln.wf02.wt02 where time <= 2017-11-01T16:26:00;
76+
```
77+
78+
or
79+
80+
```sql
81+
delete from root.ln.wf02.wt02.* where time <= 2017-11-01T16:26:00;
82+
```
83+
84+
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:
85+
86+
```
87+
IoTDB> delete from root.ln.wf03.wt02.status where time < now()
88+
Msg: The statement is executed successfully.
89+
```
90+
91+
## Delete Time Partition (experimental)
92+
93+
You may delete all data in a time partition of a database using the following grammar:
94+
95+
```sql
96+
DELETE PARTITION root.ln 0,1,2
97+
```
98+
99+
The `0,1,2` above is the id of the partition that is to be deleted, you can find it from the IoTDB
100+
data folders or convert a timestamp manually to an id using `timestamp / partitionInterval
101+
` (flooring), and the `partitionInterval` should be in your config (if time-partitioning is
102+
supported in your version).
103+
104+
Please notice that this function is experimental and mainly for development, please use it with care.
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
<!--
2+
3+
Licensed to the Apache Software Foundation (ASF) under one
4+
or more contributor license agreements. See the NOTICE file
5+
distributed with this work for additional information
6+
regarding copyright ownership. The ASF licenses this file
7+
to you under the Apache License, Version 2.0 (the
8+
"License"); you may not use this file except in compliance
9+
with the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing,
14+
software distributed under the License is distributed on an
15+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
KIND, either express or implied. See the License for the
17+
specific language governing permissions and limitations
18+
under the License.
19+
20+
-->
21+
# TTL Delete Data
22+
23+
## Overview
24+
25+
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.
26+
27+
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.
28+
29+
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.
30+
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.
31+
However, due to operational costs, the expired data will not be physically deleted right after expiring. The physical deletion is delayed until compaction.
32+
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.
33+
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.
34+
35+
## Set TTL
36+
### TTL Path Rule
37+
The path can only be prefix paths (i.e., the path cannot contain \* , except \*\* in the last level).
38+
This path will match devices and also allows users to specify paths without asterisks as specific databases or devices.
39+
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.
40+
```
41+
qualified paths:
42+
root.**
43+
root.db.**
44+
root.db.group1.**
45+
root.db
46+
root.db.group1.d1
47+
48+
unqualified paths:
49+
root.*.db
50+
root.**.db.*
51+
root.db.*
52+
```
53+
### TTL Applicable Rules
54+
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.**".
55+
### Set TTL
56+
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.
57+
The unset ttl operation indicates unmounting TTL for the corresponding path pattern; if there is no corresponding TTL, nothing will be done.
58+
If you want to set TTL to be infinitely large, you can use the INF keyword.
59+
The SQL Statement for setting TTL is as follow:
60+
```
61+
set ttl to pathPattern 360000;
62+
```
63+
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.
64+
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.\*\*.
65+
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.
66+
It is also permissible to specify a particular device without a wildcard (*).
67+
## Unset TTL
68+
69+
To unset TTL, we can use follwing SQL statement:
70+
71+
```
72+
IoTDB> unset ttl from root.ln
73+
```
74+
75+
After unset TTL, all data will be accepted in `root.ln`.
76+
```
77+
IoTDB> unset ttl from root.sgcc.**
78+
```
79+
80+
Unset the TTL in the `root.sgcc` path.
81+
82+
New syntax
83+
```
84+
IoTDB> unset ttl from root.**
85+
```
86+
87+
Old syntax
88+
```
89+
IoTDB> unset ttl to root.**
90+
```
91+
There is no functional difference between the old and new syntax, and they are compatible with each other.
92+
The new syntax is just more conventional in terms of wording.
93+
94+
Unset the TTL setting for all path pattern.
95+
96+
## Show TTL
97+
98+
To Show TTL, we can use following SQL statement:
99+
100+
show all ttl
101+
102+
```
103+
IoTDB> SHOW ALL TTL
104+
+--------------+--------+
105+
| path| TTL|
106+
| root.**|55555555|
107+
| root.sg2.a.**|44440000|
108+
+--------------+--------+
109+
```
110+
111+
show ttl on pathPattern
112+
```
113+
IoTDB> SHOW TTL ON root.db.**;
114+
+--------------+--------+
115+
| path| TTL|
116+
| root.db.**|55555555|
117+
| root.db.a.**|44440000|
118+
+--------------+--------+
119+
```
120+
121+
The SHOW ALL TTL example gives the TTL for all path patterns.
122+
The SHOW TTL ON pathPattern shows the TTL for the path pattern specified.
123+
124+
Display devices' ttl
125+
```
126+
IoTDB> show devices
127+
+---------------+---------+---------+
128+
| Device|IsAligned| TTL|
129+
+---------------+---------+---------+
130+
|root.sg.device1| false| 36000000|
131+
|root.sg.device2| true| INF|
132+
+---------------+---------+---------+
133+
```
134+
All devices will definitely have a TTL, meaning it cannot be null. INF represents infinity.

src/UserGuide/dev-1.3/Basic-Concept/Write-Delete-Data.md renamed to src/UserGuide/dev-1.3/Basic-Concept/Write-Data.md

Lines changed: 4 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
-->
2121

2222

23-
# Write & Delete Data
23+
# Write Data
2424
## CLI INSERT
2525

2626
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
3333

3434
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)).
3535

36-
**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.
37-
3836
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.
3937

4038
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
193191

194192
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).
195193

196-
## DELETE
197-
198-
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.
199-
200-
In a JAVA programming environment, you can use the [Java JDBC](../API/Programming-JDBC.md) to execute single or batch UPDATE statements.
201-
202-
### Delete Single Timeseries
203-
204-
Taking ln Group as an example, there exists such a usage scenario:
205-
206-
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
207-
208-
```sql
209-
delete from root.ln.wf02.wt02.status where time<=2017-11-01T16:26:00;
210-
```
211-
212-
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:
213-
214-
```sql
215-
delete from root.ln.wf02.wt02.status where time>=2017-01-01T00:00:00 and time<=2017-11-01T16:26:00;
216-
```
217-
218-
IoTDB supports to delete a range of timeseries points. Users can write SQL expressions as follows to specify the delete interval:
219-
220-
```sql
221-
delete from root.ln.wf02.wt02.status where time < 10
222-
delete from root.ln.wf02.wt02.status where time <= 10
223-
delete from root.ln.wf02.wt02.status where time < 20 and time > 10
224-
delete from root.ln.wf02.wt02.status where time <= 20 and time >= 10
225-
delete from root.ln.wf02.wt02.status where time > 20
226-
delete from root.ln.wf02.wt02.status where time >= 20
227-
delete from root.ln.wf02.wt02.status where time = 20
228-
```
229-
230-
Please pay attention that multiple intervals connected by "OR" expression are not supported in delete statement:
231-
232-
```
233-
delete from root.ln.wf02.wt02.status where time > 4 or time < 0
234-
Msg: 303: Check metadata error: For delete statement, where clause can only contain atomic
235-
expressions like : time > XXX, time <= XXX, or two atomic expressions connected by 'AND'
236-
```
237-
238-
If no "where" clause specified in a delete statement, all the data in a timeseries will be deleted.
194+
## SCHEMALESS WRITING
195+
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.
239196

240-
```sql
241-
delete from root.ln.wf02.wt02.status
242-
```
243-
244-
245-
### Delete Multiple Timeseries
246-
247-
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:
248-
249-
```sql
250-
delete from root.ln.wf02.wt02 where time <= 2017-11-01T16:26:00;
251-
```
252-
253-
or
254-
255-
```sql
256-
delete from root.ln.wf02.wt02.* where time <= 2017-11-01T16:26:00;
257-
```
258-
259-
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:
260-
261-
```
262-
IoTDB> delete from root.ln.wf03.wt02.status where time < now()
263-
Msg: The statement is executed successfully.
264-
```
265-
266-
### Delete Time Partition (experimental)
267-
268-
You may delete all data in a time partition of a database using the following grammar:
269-
270-
```sql
271-
DELETE PARTITION root.ln 0,1,2
272-
```
197+
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.
273198

274-
The `0,1,2` above is the id of the partition that is to be deleted, you can find it from the IoTDB
275-
data folders or convert a timestamp manually to an id using `timestamp / partitionInterval
276-
` (flooring), and the `partitionInterval` should be in your config (if time-partitioning is
277-
supported in your version).
278199

279-
Please notice that this function is experimental and mainly for development, please use it with care.
280200

src/UserGuide/dev-1.3/QuickStart/QuickStart_apache.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ This document will help you quickly install and deploy IoTDB. You can quickly lo
5050

5151
- SQL syntax introduction: [Operate Metadata](../Basic-Concept/Operate-Metadata_apache.md)
5252

53-
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)
53+
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)
5454

5555
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)
5656

src/UserGuide/dev-1.3/QuickStart/QuickStart_timecho.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ This document will help you quickly install and deploy IoTDB. You can quickly lo
5858

5959
- SQL syntax introduction:[Operate Metadata](../Basic-Concept/Operate-Metadata_timecho.md)
6060

61-
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)
61+
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)
6262

6363
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)
6464

src/UserGuide/dev-1.3/SQL-Manual/SQL-Manual.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ IoTDB> count devices root.ln.**
409409

410410
### Insert Data
411411

412-
For more details, see document [Write-Delete-Data](../Basic-Concept/Write-Delete-Data.md).
412+
For more details, see document [Write-Data](../Basic-Concept/Write-Data).
413413

414414
#### Use of INSERT Statements
415415

@@ -471,7 +471,7 @@ For more details, see document [Data Import](../Tools-System/Data-Import-Tool.md
471471

472472
## DELETE DATA
473473

474-
For more details, see document [Write-Delete-Data](../Basic-Concept/Write-Delete-Data.md).
474+
For more details, see document [Write-Delete-Data](../Basic-Concept/Write-Data).
475475

476476
### Delete Single Timeseries
477477

0 commit comments

Comments
 (0)