Skip to content

Commit 1ab9631

Browse files
authored
Added comment for table & column
1 parent 8fe8547 commit 1ab9631

File tree

43 files changed

+1191
-129
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1191
-129
lines changed

integration-test/src/test/java/org/apache/iotdb/pipe/it/dual/tablemodel/manual/enhanced/IoTDBPipeIdempotentIT.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,18 @@ public void testTableRevokeIdempotent() throws Exception {
144144
"revoke all from user newUser");
145145
}
146146

147+
@Test
148+
public void testSetTableCommentIdempotent() throws Exception {
149+
testTableConfigIdempotent(
150+
Collections.singletonList("create table test(a tag)"), "COMMENT ON TABLE test is 'tag'");
151+
}
152+
153+
@Test
154+
public void testSetTableColumnCommentIdempotent() throws Exception {
155+
testTableConfigIdempotent(
156+
Collections.singletonList("create table test(a tag)"), "COMMENT ON COLUMN test.a IS 'tag'");
157+
}
158+
147159
private void testTableConfigIdempotent(final List<String> beforeSqlList, final String testSql)
148160
throws Exception {
149161
final String database = "test";

integration-test/src/test/java/org/apache/iotdb/relational/it/schema/IoTDBDatabaseIT.java

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,8 @@ public void testInformationSchema() throws SQLException {
394394
"database,STRING,TAG,",
395395
"table_name,STRING,TAG,",
396396
"ttl(ms),STRING,ATTRIBUTE,",
397-
"status,STRING,ATTRIBUTE,")));
397+
"status,STRING,ATTRIBUTE,",
398+
"comment,STRING,ATTRIBUTE,")));
398399
TestUtils.assertResultSetEqual(
399400
statement.executeQuery("desc columns"),
400401
"ColumnName,DataType,Category,",
@@ -405,7 +406,8 @@ public void testInformationSchema() throws SQLException {
405406
"column_name,STRING,TAG,",
406407
"datatype,STRING,ATTRIBUTE,",
407408
"category,STRING,ATTRIBUTE,",
408-
"status,STRING,ATTRIBUTE,")));
409+
"status,STRING,ATTRIBUTE,",
410+
"comment,STRING,ATTRIBUTE,")));
409411
TestUtils.assertResultSetEqual(
410412
statement.executeQuery("desc queries"),
411413
"ColumnName,DataType,Category,",
@@ -456,7 +458,8 @@ public void testInformationSchema() throws SQLException {
456458

457459
// Test table query
458460
statement.execute("create database test");
459-
statement.execute("create table test.test (a tag, b attribute, c int32)");
461+
statement.execute(
462+
"create table test.test (a tag, b attribute, c int32 comment 'turbine') comment 'test'");
460463

461464
TestUtils.assertResultSetEqual(
462465
statement.executeQuery("select * from databases"),
@@ -467,39 +470,39 @@ public void testInformationSchema() throws SQLException {
467470
"test,INF,1,1,604800000,0,0,")));
468471
TestUtils.assertResultSetEqual(
469472
statement.executeQuery("show devices from tables where status = 'USING'"),
470-
"database,table_name,ttl(ms),status,",
473+
"database,table_name,ttl(ms),status,comment,",
471474
new HashSet<>(
472475
Arrays.asList(
473-
"information_schema,databases,INF,USING,",
474-
"information_schema,tables,INF,USING,",
475-
"information_schema,columns,INF,USING,",
476-
"information_schema,queries,INF,USING,",
477-
"information_schema,regions,INF,USING,",
478-
"information_schema,topics,INF,USING,",
479-
"information_schema,pipe_plugins,INF,USING,",
480-
"information_schema,pipes,INF,USING,",
481-
"information_schema,subscriptions,INF,USING,",
482-
"test,test,INF,USING,")));
476+
"information_schema,databases,INF,USING,null,",
477+
"information_schema,tables,INF,USING,null,",
478+
"information_schema,columns,INF,USING,null,",
479+
"information_schema,queries,INF,USING,null,",
480+
"information_schema,regions,INF,USING,null,",
481+
"information_schema,topics,INF,USING,null,",
482+
"information_schema,pipe_plugins,INF,USING,null,",
483+
"information_schema,pipes,INF,USING,null,",
484+
"information_schema,subscriptions,INF,USING,null,",
485+
"test,test,INF,USING,test,")));
483486
TestUtils.assertResultSetEqual(
484487
statement.executeQuery("count devices from tables where status = 'USING'"),
485488
"count(devices),",
486489
Collections.singleton("10,"));
487490
TestUtils.assertResultSetEqual(
488491
statement.executeQuery(
489492
"select * from columns where table_name = 'queries' or database = 'test'"),
490-
"database,table_name,column_name,datatype,category,status,",
493+
"database,table_name,column_name,datatype,category,status,comment,",
491494
new HashSet<>(
492495
Arrays.asList(
493-
"information_schema,queries,query_id,STRING,TAG,USING,",
494-
"information_schema,queries,start_time,TIMESTAMP,ATTRIBUTE,USING,",
495-
"information_schema,queries,datanode_id,INT32,ATTRIBUTE,USING,",
496-
"information_schema,queries,elapsed_time,FLOAT,ATTRIBUTE,USING,",
497-
"information_schema,queries,statement,STRING,ATTRIBUTE,USING,",
498-
"information_schema,queries,user,STRING,ATTRIBUTE,USING,",
499-
"test,test,time,TIMESTAMP,TIME,USING,",
500-
"test,test,a,STRING,TAG,USING,",
501-
"test,test,b,STRING,ATTRIBUTE,USING,",
502-
"test,test,c,INT32,FIELD,USING,")));
496+
"information_schema,queries,query_id,STRING,TAG,USING,null,",
497+
"information_schema,queries,start_time,TIMESTAMP,ATTRIBUTE,USING,null,",
498+
"information_schema,queries,datanode_id,INT32,ATTRIBUTE,USING,null,",
499+
"information_schema,queries,elapsed_time,FLOAT,ATTRIBUTE,USING,null,",
500+
"information_schema,queries,statement,STRING,ATTRIBUTE,USING,null,",
501+
"information_schema,queries,user,STRING,ATTRIBUTE,USING,null,",
502+
"test,test,time,TIMESTAMP,TIME,USING,null,",
503+
"test,test,a,STRING,TAG,USING,null,",
504+
"test,test,b,STRING,ATTRIBUTE,USING,null,",
505+
"test,test,c,INT32,FIELD,USING,turbine,")));
503506

504507
statement.execute(
505508
"create pipe a2b with source('double-living'='true') with sink ('sink'='write-back-sink')");

integration-test/src/test/java/org/apache/iotdb/relational/it/schema/IoTDBTableIT.java

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import static org.apache.iotdb.commons.schema.column.ColumnHeaderConstant.describeTableDetailsColumnHeaders;
4545
import static org.apache.iotdb.commons.schema.column.ColumnHeaderConstant.showDBColumnHeaders;
4646
import static org.apache.iotdb.commons.schema.column.ColumnHeaderConstant.showTablesColumnHeaders;
47+
import static org.apache.iotdb.commons.schema.column.ColumnHeaderConstant.showTablesDetailsColumnHeaders;
4748
import static org.junit.Assert.assertEquals;
4849
import static org.junit.Assert.assertFalse;
4950
import static org.junit.Assert.fail;
@@ -96,7 +97,7 @@ public void testManageTable() {
9697
// "FIELD" can be omitted when type is specified
9798
// "STRING" can be omitted when tag/attribute is specified
9899
statement.execute(
99-
"create table test1.table1(region_id STRING TAG, plant_id STRING TAG, device_id TAG, model STRING ATTRIBUTE, temperature FLOAT FIELD, humidity DOUBLE) with (TTL='INF')");
100+
"create table test1.table1(region_id STRING TAG, plant_id STRING TAG, device_id TAG, model STRING ATTRIBUTE, temperature FLOAT FIELD, humidity DOUBLE) comment 'test' with (TTL='INF')");
100101

101102
try {
102103
statement.execute(
@@ -108,23 +109,27 @@ public void testManageTable() {
108109

109110
String[] tableNames = new String[] {"table1"};
110111
String[] ttls = new String[] {"INF"};
112+
String[] statuses = new String[] {"USING"};
113+
String[] comments = new String[] {"test"};
111114

112115
statement.execute("use test2");
113116

114117
// show tables by specifying another database
115118
// Check duplicate create table won't affect table state
116119
// using SHOW tables in
117-
try (final ResultSet resultSet = statement.executeQuery("SHOW tables in test1")) {
120+
try (final ResultSet resultSet = statement.executeQuery("SHOW tables details in test1")) {
118121
int cnt = 0;
119122
ResultSetMetaData metaData = resultSet.getMetaData();
120-
assertEquals(showTablesColumnHeaders.size(), metaData.getColumnCount());
121-
for (int i = 0; i < showTablesColumnHeaders.size(); i++) {
123+
assertEquals(showTablesDetailsColumnHeaders.size(), metaData.getColumnCount());
124+
for (int i = 0; i < showTablesDetailsColumnHeaders.size(); i++) {
122125
assertEquals(
123-
showTablesColumnHeaders.get(i).getColumnName(), metaData.getColumnName(i + 1));
126+
showTablesDetailsColumnHeaders.get(i).getColumnName(), metaData.getColumnName(i + 1));
124127
}
125128
while (resultSet.next()) {
126129
assertEquals(tableNames[cnt], resultSet.getString(1));
127130
assertEquals(ttls[cnt], resultSet.getString(2));
131+
assertEquals(statuses[cnt], resultSet.getString(3));
132+
assertEquals(comments[cnt], resultSet.getString(4));
128133
cnt++;
129134
}
130135
assertEquals(tableNames.length, cnt);
@@ -151,18 +156,21 @@ public void testManageTable() {
151156
assertEquals("701: Table property 'nonsupport' is currently not allowed.", e.getMessage());
152157
}
153158

159+
statement.execute("comment on table test1.table1 is 'new_test'");
160+
comments = new String[] {"new_test"};
154161
// using SHOW tables from
155-
try (final ResultSet resultSet = statement.executeQuery("SHOW tables from test1")) {
162+
try (final ResultSet resultSet = statement.executeQuery("SHOW tables details from test1")) {
156163
int cnt = 0;
157164
final ResultSetMetaData metaData = resultSet.getMetaData();
158-
assertEquals(showTablesColumnHeaders.size(), metaData.getColumnCount());
159-
for (int i = 0; i < showTablesColumnHeaders.size(); i++) {
165+
assertEquals(showTablesDetailsColumnHeaders.size(), metaData.getColumnCount());
166+
for (int i = 0; i < showTablesDetailsColumnHeaders.size(); i++) {
160167
assertEquals(
161-
showTablesColumnHeaders.get(i).getColumnName(), metaData.getColumnName(i + 1));
168+
showTablesDetailsColumnHeaders.get(i).getColumnName(), metaData.getColumnName(i + 1));
162169
}
163170
while (resultSet.next()) {
164171
assertEquals(tableNames[cnt], resultSet.getString(1));
165172
assertEquals(ttls[cnt], resultSet.getString(2));
173+
assertEquals(comments[cnt], resultSet.getString(4));
166174
cnt++;
167175
}
168176
assertEquals(tableNames.length, cnt);
@@ -260,7 +268,7 @@ public void testManageTable() {
260268
statement.execute(
261269
"create table table2(region_id STRING TAG, plant_id STRING TAG, color STRING ATTRIBUTE, temperature FLOAT FIELD) with (TTL=6600000)");
262270

263-
statement.execute("alter table table2 add column speed DOUBLE FIELD");
271+
statement.execute("alter table table2 add column speed DOUBLE FIELD COMMENT 'fast'");
264272

265273
try {
266274
statement.execute("alter table table2 add column speed DOUBLE FIELD");
@@ -395,10 +403,16 @@ public void testManageTable() {
395403
// Test drop column
396404
statement.execute("alter table table2 drop column color");
397405

406+
// Test comment
407+
statement.execute("COMMENT ON COLUMN table2.region_id IS '重庆'");
408+
statement.execute("COMMENT ON COLUMN table2.region_id IS NULL");
409+
statement.execute("COMMENT ON COLUMN test2.table2.time IS 'recent'");
410+
398411
columnNames = new String[] {"time", "region_id", "plant_id", "temperature", "speed"};
399412
dataTypes = new String[] {"TIMESTAMP", "STRING", "STRING", "FLOAT", "DOUBLE"};
400413
categories = new String[] {"TIME", "TAG", "TAG", "FIELD", "FIELD"};
401-
final String[] statuses = new String[] {"USING", "USING", "USING", "USING", "USING"};
414+
statuses = new String[] {"USING", "USING", "USING", "USING", "USING"};
415+
comments = new String[] {"recent", "", "", "", "fast"};
402416
try (final ResultSet resultSet = statement.executeQuery("describe table2 details")) {
403417
int cnt = 0;
404418
ResultSetMetaData metaData = resultSet.getMetaData();
@@ -413,6 +427,7 @@ public void testManageTable() {
413427
assertEquals(dataTypes[cnt], resultSet.getString(2));
414428
assertEquals(categories[cnt], resultSet.getString(3));
415429
assertEquals(statuses[cnt], resultSet.getString(4));
430+
assertEquals(comments[cnt], resultSet.getString(5));
416431
cnt++;
417432
}
418433
assertEquals(columnNames.length, cnt);

iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/consensus/request/ConfigPhysicalPlan.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@
109109
import org.apache.iotdb.confignode.consensus.request.write.table.PreDeleteTablePlan;
110110
import org.apache.iotdb.confignode.consensus.request.write.table.RenameTableColumnPlan;
111111
import org.apache.iotdb.confignode.consensus.request.write.table.RollbackCreateTablePlan;
112+
import org.apache.iotdb.confignode.consensus.request.write.table.SetTableColumnCommentPlan;
113+
import org.apache.iotdb.confignode.consensus.request.write.table.SetTableCommentPlan;
112114
import org.apache.iotdb.confignode.consensus.request.write.table.SetTablePropertiesPlan;
113115
import org.apache.iotdb.confignode.consensus.request.write.template.CommitSetSchemaTemplatePlan;
114116
import org.apache.iotdb.confignode.consensus.request.write.template.CreateSchemaTemplatePlan;
@@ -407,6 +409,12 @@ public static ConfigPhysicalPlan create(final ByteBuffer buffer) throws IOExcept
407409
case CommitDeleteColumn:
408410
plan = new CommitDeleteColumnPlan();
409411
break;
412+
case SetTableComment:
413+
plan = new SetTableCommentPlan();
414+
break;
415+
case SetTableColumnComment:
416+
plan = new SetTableColumnCommentPlan();
417+
break;
410418
case CreatePipeSinkV1:
411419
plan = new CreatePipeSinkPlanV1();
412420
break;

iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/consensus/request/ConfigPhysicalPlanType.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ public enum ConfigPhysicalPlanType {
207207
DescTable((short) 862),
208208
ShowTable4InformationSchema((short) 863),
209209
DescTable4InformationSchema((short) 864),
210+
SetTableColumnComment((short) 865),
211+
SetTableComment((short) 866),
210212

211213
/** Deprecated types for sync, restored them for upgrade. */
212214
@Deprecated

iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/consensus/request/ConfigPhysicalPlanVisitor.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
import org.apache.iotdb.confignode.consensus.request.write.table.CommitDeleteColumnPlan;
3535
import org.apache.iotdb.confignode.consensus.request.write.table.CommitDeleteTablePlan;
3636
import org.apache.iotdb.confignode.consensus.request.write.table.RenameTableColumnPlan;
37+
import org.apache.iotdb.confignode.consensus.request.write.table.SetTableColumnCommentPlan;
38+
import org.apache.iotdb.confignode.consensus.request.write.table.SetTableCommentPlan;
3739
import org.apache.iotdb.confignode.consensus.request.write.table.SetTablePropertiesPlan;
3840
import org.apache.iotdb.confignode.consensus.request.write.template.CommitSetSchemaTemplatePlan;
3941
import org.apache.iotdb.confignode.consensus.request.write.template.CreateSchemaTemplatePlan;
@@ -159,6 +161,10 @@ public R process(final ConfigPhysicalPlan plan, final C context) {
159161
return visitCommitDeleteTable((CommitDeleteTablePlan) plan, context);
160162
case PipeDeleteDevices:
161163
return visitPipeDeleteDevices((PipeDeleteDevicesPlan) plan, context);
164+
case SetTableComment:
165+
return visitSetTableComment((SetTableCommentPlan) plan, context);
166+
case SetTableColumnComment:
167+
return visitSetTableColumnComment((SetTableColumnCommentPlan) plan, context);
162168
default:
163169
return visitPlan(plan, context);
164170
}
@@ -419,4 +425,13 @@ public R visitPipeDeleteDevices(
419425
final PipeDeleteDevicesPlan pipeDeleteDevicesPlan, final C context) {
420426
return visitPlan(pipeDeleteDevicesPlan, context);
421427
}
428+
429+
public R visitSetTableComment(final SetTableCommentPlan setTableCommentPlan, final C context) {
430+
return visitPlan(setTableCommentPlan, context);
431+
}
432+
433+
public R visitSetTableColumnComment(
434+
final SetTableColumnCommentPlan setTableColumnCommentPlan, final C context) {
435+
return visitPlan(setTableColumnCommentPlan, context);
436+
}
422437
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.iotdb.confignode.consensus.request.write.table;
21+
22+
import org.apache.iotdb.confignode.consensus.request.ConfigPhysicalPlanType;
23+
24+
import org.apache.tsfile.utils.ReadWriteIOUtils;
25+
26+
import java.io.DataOutputStream;
27+
import java.io.IOException;
28+
import java.nio.ByteBuffer;
29+
30+
public class SetTableColumnCommentPlan extends AbstractTableColumnPlan {
31+
32+
private String comment;
33+
34+
public SetTableColumnCommentPlan() {
35+
super(ConfigPhysicalPlanType.SetTableColumnComment);
36+
}
37+
38+
public SetTableColumnCommentPlan(
39+
final String database,
40+
final String tableName,
41+
final String columnName,
42+
final String comment) {
43+
super(ConfigPhysicalPlanType.SetTableColumnComment, database, tableName, columnName);
44+
this.comment = comment;
45+
}
46+
47+
public String getComment() {
48+
return comment;
49+
}
50+
51+
@Override
52+
protected void serializeImpl(final DataOutputStream stream) throws IOException {
53+
super.serializeImpl(stream);
54+
ReadWriteIOUtils.write(comment, stream);
55+
}
56+
57+
@Override
58+
protected void deserializeImpl(final ByteBuffer buffer) throws IOException {
59+
super.deserializeImpl(buffer);
60+
this.comment = ReadWriteIOUtils.readString(buffer);
61+
}
62+
}

0 commit comments

Comments
 (0)