Skip to content

Commit 676621b

Browse files
authored
add alter datatype from 2082 to timecho (#1013)
1 parent 6ec8c0b commit 676621b

24 files changed

Lines changed: 366 additions & 47 deletions

File tree

src/UserGuide/Master/Table/Basic-Concept/Table-Management_timecho.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ Total line number = 1
259259

260260
### 1.5 Update Tables
261261

262-
Used to update a table, including adding or deleting columns and configuring table properties.
262+
Used to update a table, including adding or deleting columns, modify column type (V2.0.8.2) and configuring table properties.
263263

264264
**Syntax:**
265265

@@ -273,13 +273,19 @@ ALTER TABLE (IF EXISTS)? tableName=qualifiedName ADD COLUMN (IF NOT EXISTS)? col
273273
| ALTER TABLE (IF EXISTS)? tableName=qualifiedName SET PROPERTIES propertyAssignments;
274274
| COMMENT ON TABLE tableName=qualifiedName IS 'table_comment';
275275
| COMMENT ON COLUMN tableName.column IS 'column_comment';
276+
#changeColumndatatype;
277+
| ALTER TABLE (IF EXISTS)? tableName=qualifiedName ALTER COLUMN (IF EXISTS)? column=identifier SET DATA TYPE new_type=type;
276278
```
277279

278280
**Note::**
279281

280282
1. The `SET PROPERTIES` operation currently only supports configuring the `TTL` property of a table
281283
2. The delete column function only supports deleting the ATTRIBUTE and FILD columns, and the TAG column does not support deletion.
282284
3. The modified comment will overwrite the original comment. If null is specified, the previous comment will be erased.
285+
4. Since version V2.0.8.2, modifying the data type of a column is supported. Currently, only columns with Category type FIELD can be modified.
286+
287+
* If the time series is concurrently deleted during the modification process, an error will be reported.
288+
* The new data type must be compatible with the original type. The specific compatibility is shown in the following table:
283289

284290
**Example:**
285291

@@ -289,6 +295,7 @@ ALTER TABLE table1 ADD COLUMN IF NOT EXISTS b FLOAT FIELD COMMENT 'b';
289295
ALTER TABLE table1 set properties TTL=3600;
290296
COMMENT ON TABLE table1 IS 'table1';
291297
COMMENT ON COLUMN table1.a IS null;
298+
ALTER TABLE table1 ALTER COLUMN IF EXISTS b SET DATA TYPE DOUBLE;
292299
```
293300

294301
### 1.6 Delete Tables

src/UserGuide/Master/Table/SQL-Manual/SQL-Metadata-Operations_timecho.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,8 @@ ALTER TABLE (IF EXISTS)? tableName=qualifiedName ADD COLUMN (IF NOT EXISTS)? col
341341
| ALTER TABLE (IF EXISTS)? tableName=qualifiedName SET PROPERTIES propertyAssignments;
342342
| COMMENT ON TABLE tableName=qualifiedName IS 'table_comment';
343343
| COMMENT ON COLUMN tableName.column IS 'column_comment';
344+
#changeColumndatatype;
345+
| ALTER TABLE (IF EXISTS)? tableName=qualifiedName ALTER COLUMN (IF EXISTS)? column=identifier SET DATA TYPE new_type=type;
344346
```
345347

346348
**Examples:**
@@ -351,6 +353,7 @@ ALTER TABLE table1 ADD COLUMN IF NOT EXISTS b FLOAT FIELD COMMENT 'b';
351353
ALTER TABLE table1 set properties TTL=3600;
352354
COMMENT ON TABLE table1 IS 'table1';
353355
COMMENT ON COLUMN table1.a IS null;
356+
ALTER TABLE table1 ALTER COLUMN IF EXISTS b SET DATA TYPE DOUBLE;
354357
```
355358

356359
### 2.6 Drop Table

src/UserGuide/Master/Table/User-Manual/Tree-to-Table_timecho.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ AS root.db.**
161161
### 2.2 Modifying a Table View
162162
#### 2.2.1 Syntax Definition
163163

164-
The ALTER VIEW function supports modifying the view name, adding columns, renaming columns, deleting columns, setting the view's TTL property, and adding comments via COMMENT.
164+
The ALTER VIEW function supports modifying the view name, adding columns, renaming columns, modifying FIELD column data type (supported since V2.0.8), deleting columns, setting the view's TTL property, and adding comments via COMMENT.
165165

166166
```SQL
167167
-- Rename view
@@ -176,6 +176,9 @@ viewColumnDefinition
176176
-- Rename a column in the view
177177
ALTER VIEW [IF EXISTS] viewName RENAME COLUMN [IF EXISTS] oldName TO newName
178178

179+
-- Modify the data type of a FIELD column
180+
ALTER VIEW [IF EXISTS] viewName ALTER COLUMN [IF EXISTS] columnName SET DATA TYPE new_type
181+
179182
-- Delete a column from the view
180183
ALTER VIEW [IF EXISTS] viewName DROP COLUMN [IF EXISTS] columnName
181184

@@ -191,6 +194,21 @@ COMMENT ON COLUMN qualifiedName '.' column=identifier IS (string | NULL) #commen
191194
1. The `SET PROPERTIES`operation currently only supports configuring the TTL property for the table view.
192195
2. The `DROP COLUMN`function only supports deleting FIELD columns; TAG columns cannot be deleted.
193196
3. Modifying the comment will overwrite the original comment. If set to `null`, the previous comment will be erased.
197+
4. When modifying the data type of a FIELD column, the new data type must be compatible with the original type. The specific compatibility is shown in the following table:
198+
199+
| Original Type | Convertible To Type |
200+
|---------------|----------------------------------------------|
201+
| INT32 | INT64, FLOAT, DOUBLE, TIMESTAMP, STRING, TEXT |
202+
| INT64 | TIMESTAMP, DOUBLE, STRING, TEXT |
203+
| FLOAT | DOUBLE, STRING, TEXT |
204+
| DOUBLE | STRING, TEXT |
205+
| BOOLEAN | STRING, TEXT |
206+
| TEXT | BLOB, STRING |
207+
| STRING | TEXT, BLOB |
208+
| BLOB | STRING, TEXT |
209+
| DATE | STRING, TEXT |
210+
| TIMESTAMP | INT64, DOUBLE, STRING, TEXT |
211+
194212
#### 2.2.3 Usage Examples
195213

196214
```SQL
@@ -203,6 +221,9 @@ ALTER VIEW IF EXISTS tableview ADD COLUMN IF NOT EXISTS temperature float field
203221
-- Rename a column in the view
204222
ALTER VIEW IF EXISTS tableview RENAME COLUMN IF EXISTS temperature TO temp
205223

224+
-- Modify the data type of a FIELD column
225+
ALTER VIEW IF EXISTS tableview ALTER COLUMN IF EXISTS temperature SET DATA TYPE double
226+
206227
-- Delete a column from the view
207228
ALTER VIEW IF EXISTS tableview DROP COLUMN IF EXISTS temp
208229

src/UserGuide/Master/Tree/Basic-Concept/Operate-Metadata_timecho.md

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,43 @@ You can set different datatype, encoding, and compression for the timeseries in
421421

422422
It is also supported to set an alias, tag, and attribute for aligned timeseries.
423423

424-
### 2.3 Modifying Timeseries Name
424+
425+
### 2.3 Modifying Timseries Data Types
426+
427+
Starting from version V2.0.8, modifying the data type of a timeseries via SQL statements is supported.
428+
429+
Syntax definition:
430+
431+
```SQL
432+
ALTER TIMESERIES fullPath SET DATA TYPE newType=type
433+
```
434+
435+
Notes:
436+
437+
* If the timeseries is concurrently deleted during the modification process, an error will be reported.
438+
439+
* The new data type must be compatible with the original type. The specific compatibility is shown in the following table:
440+
441+
| Original Type |Convertible To Type |
442+
| ----------- | ----------------------------------------------- |
443+
| INT32 | INT64, FLOAT, DOUBLE, TIMESTAMP, STRING, TEXT |
444+
| INT64 | TIMESTAMP, DOUBLE, STRING, TEXT |
445+
| FLOAT | DOUBLE, STRING, TEXT |
446+
| DOUBLE | STRING, TEXT |
447+
| BOOLEAN | STRING, TEXT |
448+
| TEXT | BLOB, STRING |
449+
| STRING | TEXT, BLOB |
450+
| BLOB | STRING, TEXT |
451+
| DATE | STRING, TEXT |
452+
| TIMESTAMP | INT64, DOUBLE, STRING, TEXT |
453+
454+
Usage example:
455+
456+
```SQL
457+
ALTER TIMESERIES root.ln.wf01.wt01.temperature set data type DOUBLE
458+
```
459+
460+
### 2.4 Modifying Timeseries Name
425461

426462
Since version V2.0.8, it has been supported to modify the full path name of a timeseries through SQL statements. After a successful modification, the original name becomes invalid but is still retained in the metadata storage.
427463

@@ -446,7 +482,7 @@ ALTER TIMESERIES root.ln.wf01.wt01.temperature RENAME TO root.newln.newwf.newwt.
446482
```
447483

448484

449-
### 2.4 Delete Timeseries
485+
### 2.5 Delete Timeseries
450486

451487
To delete the timeseries we created before, we are able to use `(DELETE | DROP) TimeSeries <PathPattern>` statement.
452488

@@ -459,7 +495,7 @@ delete timeseries root.ln.wf02.*;
459495
drop timeseries root.ln.wf02.*;
460496
```
461497

462-
### 2.5 Show Timeseries
498+
### 2.6 Show Timeseries
463499

464500
* SHOW LATEST? TIMESERIES pathPattern? whereClause? limitClause?
465501

@@ -618,7 +654,7 @@ IoTDB> show invalid timeSeries
618654
Explanation: The last column, "NewPath," in the returned result displays the new sequence corresponding to the invalidated sequence. This serves scenarios such as view construction and cluster migration (Load + rename).
619655

620656

621-
### 2.6 Count Timeseries
657+
### 2.7 Count Timeseries
622658

623659
IoTDB is able to use `COUNT TIMESERIES <Path>` to count the number of timeseries matching the path. SQL statements are as follows:
624660

@@ -703,7 +739,7 @@ It costs 0.002s
703739

704740
> Note: The path of timeseries is just a filter condition, which has no relationship with the definition of level.
705741
706-
### 2.7 Active Timeseries Query
742+
### 2.8 Active Timeseries Query
707743
By adding WHERE time filter conditions to the existing SHOW/COUNT TIMESERIES, we can obtain time series with data within the specified time range.
708744

709745
It is important to note that in metadata queries with time filters, views are not considered; only the time series actually stored in the TsFile are taken into account.
@@ -743,7 +779,7 @@ count timeseries where time >= 15000 and time < 16000;
743779
+-----------------+
744780
```
745781
Regarding the definition of active time series, data that can be queried normally is considered active, meaning time series that have been inserted but deleted are not included.
746-
### 2.8 Tag and Attribute Management
782+
### 2.9 Tag and Attribute Management
747783

748784
We can also add an alias, extra tag and attribute information while creating one timeseries.
749785

src/UserGuide/Master/Tree/SQL-Manual/Keywords.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@
208208
- TRIGGER
209209
- TRIGGERS
210210
- TTL
211+
- TYPE
211212
- UNLINK
212213
- UNLOAD
213214
- UNSET

src/UserGuide/Master/Tree/SQL-Manual/SQL-Manual_timecho.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,21 @@ error: encoding TS_2DIFF does not support BOOLEAN
142142
CREATE ALIGNED TIMESERIES root.ln.wf01.GPS(latitude FLOAT , longitude FLOAT);
143143
```
144144

145-
### 2.3 Modify Timeseries Name
145+
### 2.3 Modify Timeseries Data Type
146+
> Supported since V2.0.8
146147
148+
```SQL
149+
ALTER TIMESERIES root.ln.wf01.wt01.temperature set data type DOUBLE
150+
```
151+
152+
### 2.4 Modify Timeseries Name
147153
> This statement is supported from V2.0.8 onwards
148154
149155
```sql
150156
ALTER TIMESERIES root.ln.wf01.wt01.temperature RENAME TO root.newln.newwf.newwt.temperature
151157
```
152158

153-
### 2.4 Delete Timeseries
159+
### 2.5 Delete Timeseries
154160

155161
```sql
156162
delete timeseries root.ln.wf01.wt01.status;
@@ -159,7 +165,7 @@ delete timeseries root.ln.wf02.*;
159165
drop timeseries root.ln.wf02.*;
160166
```
161167

162-
### 2.5 Show Timeseries
168+
### 2.6 Show Timeseries
163169

164170
```sql
165171
show timeseries root.**;
@@ -172,7 +178,7 @@ show latest timeseries;
172178
show invalid timeseries; -- This statement is supported from V2.0.8.2 onwards;
173179
```
174180

175-
### 2.6 Count Timeseries
181+
### 2.7 Count Timeseries
176182

177183
```sql
178184
COUNT TIMESERIES root.**;
@@ -189,7 +195,7 @@ COUNT TIMESERIES root.ln.** GROUP BY LEVEL=2;
189195
COUNT TIMESERIES root.ln.wf01.* GROUP BY LEVEL=2;
190196
```
191197

192-
### 2.7 Tag and Attribute Management
198+
### 2.8 Tag and Attribute Management
193199

194200
```sql
195201
create timeseries root.turbine.d1.s1(temprature) with datatype=FLOAT tags(tag1=v1, tag2=v2) attributes(attr1=v1, attr2=v2);

src/UserGuide/latest-Table/Basic-Concept/Table-Management_timecho.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ Total line number = 1
259259

260260
### 1.5 Update Tables
261261

262-
Used to update a table, including adding or deleting columns and configuring table properties.
262+
Used to update a table, including adding or deleting columns, modify column type (V2.0.8.2) and configuring table properties.
263263

264264
**Syntax:**
265265

@@ -273,13 +273,19 @@ ALTER TABLE (IF EXISTS)? tableName=qualifiedName ADD COLUMN (IF NOT EXISTS)? col
273273
| ALTER TABLE (IF EXISTS)? tableName=qualifiedName SET PROPERTIES propertyAssignments;
274274
| COMMENT ON TABLE tableName=qualifiedName IS 'table_comment';
275275
| COMMENT ON COLUMN tableName.column IS 'column_comment';
276+
#changeColumndatatype;
277+
| ALTER TABLE (IF EXISTS)? tableName=qualifiedName ALTER COLUMN (IF EXISTS)? column=identifier SET DATA TYPE new_type=type;
276278
```
277279

278280
**Note::**
279281

280282
1. The `SET PROPERTIES` operation currently only supports configuring the `TTL` property of a table
281283
2. The delete column function only supports deleting the ATTRIBUTE and FILD columns, and the TAG column does not support deletion.
282284
3. The modified comment will overwrite the original comment. If null is specified, the previous comment will be erased.
285+
4. Since version V2.0.8.2, modifying the data type of a column is supported. Currently, only columns with Category type FIELD can be modified.
286+
287+
* If the time series is concurrently deleted during the modification process, an error will be reported.
288+
* The new data type must be compatible with the original type. The specific compatibility is shown in the following table:
283289

284290
**Example:**
285291

@@ -289,6 +295,7 @@ ALTER TABLE table1 ADD COLUMN IF NOT EXISTS b FLOAT FIELD COMMENT 'b';
289295
ALTER TABLE table1 set properties TTL=3600;
290296
COMMENT ON TABLE table1 IS 'table1';
291297
COMMENT ON COLUMN table1.a IS null;
298+
ALTER TABLE table1 ALTER COLUMN IF EXISTS b SET DATA TYPE DOUBLE;
292299
```
293300

294301
### 1.6 Delete Tables

src/UserGuide/latest-Table/SQL-Manual/SQL-Metadata-Operations_timecho.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,8 @@ ALTER TABLE (IF EXISTS)? tableName=qualifiedName ADD COLUMN (IF NOT EXISTS)? col
341341
| ALTER TABLE (IF EXISTS)? tableName=qualifiedName SET PROPERTIES propertyAssignments;
342342
| COMMENT ON TABLE tableName=qualifiedName IS 'table_comment';
343343
| COMMENT ON COLUMN tableName.column IS 'column_comment';
344+
#changeColumndatatype;
345+
| ALTER TABLE (IF EXISTS)? tableName=qualifiedName ALTER COLUMN (IF EXISTS)? column=identifier SET DATA TYPE new_type=type;
344346
```
345347

346348
**Examples:**
@@ -351,6 +353,7 @@ ALTER TABLE table1 ADD COLUMN IF NOT EXISTS b FLOAT FIELD COMMENT 'b';
351353
ALTER TABLE table1 set properties TTL=3600;
352354
COMMENT ON TABLE table1 IS 'table1';
353355
COMMENT ON COLUMN table1.a IS null;
356+
ALTER TABLE table1 ALTER COLUMN IF EXISTS b SET DATA TYPE DOUBLE;
354357
```
355358

356359
### 2.6 Drop Table

src/UserGuide/latest-Table/User-Manual/Tree-to-Table_timecho.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ AS root.db.**
161161
### 2.2 Modifying a Table View
162162
#### 2.2.1 Syntax Definition
163163

164-
The ALTER VIEW function supports modifying the view name, adding columns, renaming columns, deleting columns, setting the view's TTL property, and adding comments via COMMENT.
164+
The ALTER VIEW function supports modifying the view name, adding columns, renaming columns, modifying FIELD column data type (supported since V2.0.8), deleting columns, setting the view's TTL property, and adding comments via COMMENT.
165165

166166
```SQL
167167
-- Rename view
@@ -176,6 +176,9 @@ viewColumnDefinition
176176
-- Rename a column in the view
177177
ALTER VIEW [IF EXISTS] viewName RENAME COLUMN [IF EXISTS] oldName TO newName
178178

179+
-- Modify the data type of a FIELD column
180+
ALTER VIEW [IF EXISTS] viewName ALTER COLUMN [IF EXISTS] columnName SET DATA TYPE new_type
181+
179182
-- Delete a column from the view
180183
ALTER VIEW [IF EXISTS] viewName DROP COLUMN [IF EXISTS] columnName
181184

@@ -191,6 +194,21 @@ COMMENT ON COLUMN qualifiedName '.' column=identifier IS (string | NULL) #commen
191194
1. The `SET PROPERTIES`operation currently only supports configuring the TTL property for the table view.
192195
2. The `DROP COLUMN`function only supports deleting FIELD columns; TAG columns cannot be deleted.
193196
3. Modifying the comment will overwrite the original comment. If set to `null`, the previous comment will be erased.
197+
4. When modifying the data type of a FIELD column, the new data type must be compatible with the original type. The specific compatibility is shown in the following table:
198+
199+
| Original Type | Convertible To Type |
200+
|---------------|----------------------------------------------|
201+
| INT32 | INT64, FLOAT, DOUBLE, TIMESTAMP, STRING, TEXT |
202+
| INT64 | TIMESTAMP, DOUBLE, STRING, TEXT |
203+
| FLOAT | DOUBLE, STRING, TEXT |
204+
| DOUBLE | STRING, TEXT |
205+
| BOOLEAN | STRING, TEXT |
206+
| TEXT | BLOB, STRING |
207+
| STRING | TEXT, BLOB |
208+
| BLOB | STRING, TEXT |
209+
| DATE | STRING, TEXT |
210+
| TIMESTAMP | INT64, DOUBLE, STRING, TEXT |
211+
194212
#### 2.2.3 Usage Examples
195213

196214
```SQL
@@ -203,6 +221,9 @@ ALTER VIEW IF EXISTS tableview ADD COLUMN IF NOT EXISTS temperature float field
203221
-- Rename a column in the view
204222
ALTER VIEW IF EXISTS tableview RENAME COLUMN IF EXISTS temperature TO temp
205223

224+
-- Modify the data type of a FIELD column
225+
ALTER VIEW IF EXISTS tableview ALTER COLUMN IF EXISTS temperature SET DATA TYPE double
226+
206227
-- Delete a column from the view
207228
ALTER VIEW IF EXISTS tableview DROP COLUMN IF EXISTS temp
208229

0 commit comments

Comments
 (0)