Skip to content

Commit e948e49

Browse files
authored
Added show create pipe/database/topic (#17702)
* ut * show create * fix * Update IoTDBDatabaseIT.java * Update IoTDBSubscriptionTopicIT.java * Remove tree model show create topic syntax * Address show create review comments * Fixed
1 parent 1073715 commit e948e49

30 files changed

Lines changed: 1432 additions & 3 deletions

File tree

‎.github/scripts/package-client-cpp-manylinux228.sh‎

100755100644
File mode changed.

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

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,66 @@ public void testManageDatabase() {
293293
}
294294
}
295295

296+
@Test
297+
public void testShowCreateDatabase() throws SQLException {
298+
try (final Connection connection =
299+
EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT);
300+
final Statement statement = connection.createStatement()) {
301+
statement.execute(
302+
"create database test_show_create_db with (ttl=300, max_schema_region_group_num=DEFAULT, max_data_region_group_num=DEFAULT, time_partition_interval=100000)");
303+
304+
try (final ResultSet resultSet =
305+
statement.executeQuery("show create database test_show_create_db")) {
306+
assertTrue(resultSet.next());
307+
assertEquals("test_show_create_db", resultSet.getString("Database"));
308+
final String createDatabaseSQL = resultSet.getString("Create Database");
309+
assertTrue(
310+
createDatabaseSQL,
311+
createDatabaseSQL.startsWith("CREATE DATABASE \"test_show_create_db\" WITH ("));
312+
assertTrue(createDatabaseSQL, createDatabaseSQL.contains("ttl=300"));
313+
assertTrue(createDatabaseSQL, createDatabaseSQL.contains("time_partition_interval=100000"));
314+
assertTrue(createDatabaseSQL, createDatabaseSQL.contains("max_schema_region_group_num="));
315+
assertTrue(createDatabaseSQL, createDatabaseSQL.contains("max_data_region_group_num="));
316+
assertFalse(resultSet.next());
317+
}
318+
}
319+
}
320+
321+
@Test
322+
public void testShowCreatePipe() throws SQLException {
323+
try (final Connection connection =
324+
EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT);
325+
final Statement statement = connection.createStatement()) {
326+
statement.execute("create pipe test_show_create_pipe ('sink'='do-nothing-sink')");
327+
328+
TestUtils.assertResultSetEqual(
329+
statement.executeQuery("show create pipe test_show_create_pipe"),
330+
"Pipe,Create Pipe,",
331+
Collections.singleton(
332+
"test_show_create_pipe,CREATE PIPE \"test_show_create_pipe\" WITH SINK ('sink'='do-nothing-sink'),"));
333+
}
334+
}
335+
336+
@Test
337+
public void testShowCreateInformationSchemaDatabase() throws SQLException {
338+
try (final Connection connection =
339+
EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT);
340+
final Statement statement = connection.createStatement()) {
341+
assertShowCreateSystemDatabaseFails(statement, "information_schema");
342+
assertShowCreateSystemDatabaseFails(statement, "__audit");
343+
}
344+
}
345+
346+
private static void assertShowCreateSystemDatabaseFails(
347+
final Statement statement, final String database) throws SQLException {
348+
try {
349+
statement.executeQuery("show create database " + database);
350+
fail("show create database " + database + " shouldn't succeed");
351+
} catch (final SQLException e) {
352+
assertEquals("701: The system database does not support show create.", e.getMessage());
353+
}
354+
}
355+
296356
@Test
297357
public void testDatabaseWithSpecificCharacters() throws SQLException {
298358
try (final Connection connection =

‎integration-test/src/test/java/org/apache/iotdb/subscription/it/dual/tablemodel/IoTDBSubscriptionTopicIT.java‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.apache.iotdb.isession.ITableSession;
2929
import org.apache.iotdb.it.framework.IoTDBTestRunner;
3030
import org.apache.iotdb.itbase.category.MultiClusterIT2SubscriptionTableArchVerification;
31+
import org.apache.iotdb.itbase.env.BaseEnv;
3132
import org.apache.iotdb.pipe.it.dual.tablemodel.TableModelUtils;
3233
import org.apache.iotdb.rpc.RpcUtils;
3334
import org.apache.iotdb.rpc.subscription.config.TopicConstant;
@@ -52,6 +53,9 @@
5253
import org.slf4j.Logger;
5354
import org.slf4j.LoggerFactory;
5455

56+
import java.sql.Connection;
57+
import java.sql.Statement;
58+
import java.util.Collections;
5559
import java.util.List;
5660
import java.util.Objects;
5761
import java.util.Properties;
@@ -100,6 +104,29 @@ protected void setUpConfig() {
100104
.setIsPipeEnableMemoryCheck(false);
101105
}
102106

107+
@Ignore
108+
@Test
109+
public void testShowCreateTopic() throws Exception {
110+
TableModelUtils.createDataBaseAndTable(
111+
senderEnv, "test_show_create_topic_db", "test_show_create_topic_table");
112+
113+
try (final Connection connection = senderEnv.getConnection(BaseEnv.TABLE_SQL_DIALECT);
114+
final Statement statement = connection.createStatement()) {
115+
statement.execute(
116+
"create topic test_show_create_topic with ('database'='test_show_create_topic_db','table'='test_show_create_topic_table','format'='"
117+
+ TopicConstant.FORMAT_TS_FILE_VALUE
118+
+ "')");
119+
120+
TestUtils.assertResultSetEqual(
121+
statement.executeQuery("show create topic test_show_create_topic"),
122+
"Topic,Create Topic,",
123+
Collections.singleton(
124+
"test_show_create_topic,CREATE TOPIC \"test_show_create_topic\" WITH ('database'='test_show_create_topic_db','format'='"
125+
+ TopicConstant.FORMAT_TS_FILE_VALUE
126+
+ "','table'='test_show_create_topic_table'),"));
127+
}
128+
}
129+
103130
@Ignore
104131
@Test
105132
public void testTabletTopicWithPath() throws Exception {

‎iotdb-core/datanode/src/main/i18n/en/org/apache/iotdb/db/i18n/DataNodePipeMessages.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ public final class DataNodePipeMessages {
131131
"Failed to decrease reference count for event {} in PipeRealtimePriorityBlockingQueue";
132132
public static final String FAILED_TO_GET_PENDINGQUEUE_NO_SUCH_SUBTASK =
133133
"Failed to get PendingQueue. No such subtask: ";
134+
public static final String FAILED_TO_GET_PIPE_INFO_FROM_CONFIG_NODE_STATUS =
135+
"Failed to get pipe info from config node, status is %s.";
134136
public static final String FAILED_TO_GET_PIPE_METAS_WILL_BE =
135137
"Failed to get pipe metas, will be synced by configNode later...";
136138
public static final String FAILED_TO_GET_PIPE_PLUGIN_JAR_FROM =
@@ -224,6 +226,10 @@ public final class DataNodePipeMessages {
224226
"Pipe skipping temporary TsFile which shouldn't be transferred: {}";
225227
public static final String PULLED_PIPE_META_FROM_CONFIG_NODE_RECOVERING =
226228
"Pulled pipe meta from config node: {}, recovering ...";
229+
public static final String FAILED_TO_SHOW_CREATE_PIPE_NOT_EXIST =
230+
"Failed to show create pipe %s, the pipe does not exist.";
231+
public static final String FAILED_TO_SHOW_CREATE_TOPIC_NOT_EXIST =
232+
"Failed to show create topic %s, the topic does not exist.";
227233
public static final String RECEIVED_PIPE_HEARTBEAT_REQUEST_FROM_CONFIG_NODE =
228234
"Received pipe heartbeat request {} from config node.";
229235
public static final String REGION_NO_TSFILEINSERTIONEVENTS_TO_REPLACE_FOR_SOURCE =

‎iotdb-core/datanode/src/main/i18n/en/org/apache/iotdb/db/i18n/DataNodeQueryMessages.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ public final class DataNodeQueryMessages {
301301
"select into: the i of ${i} should be an integer.";
302302
public static final String FAILED_TO_GET_DATABASE_MAP =
303303
"Failed to get database Map";
304+
public static final String UNKNOWN_DATABASE = "Unknown database %s";
304305
public static final String LOAD_ANALYSIS_STAGE_ALL_TSFILES_HAVE_BEEN_ANALYZED =
305306
"Load - Analysis Stage: all tsfiles have been analyzed.";
306307
public static final String ASYNC_LOAD_HAS_FAILED_AND_IS_NOW_TRYING =

‎iotdb-core/datanode/src/main/i18n/en/org/apache/iotdb/db/i18n/DataNodeSchemaMessages.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,8 @@ public final class DataNodeSchemaMessages {
396396

397397
public static final String SYSTEM_VIEW_NOT_SUPPORT_SHOW_CREATE =
398398
"The system view does not support show create.";
399+
public static final String SYSTEM_DATABASE_NOT_SUPPORT_SHOW_CREATE =
400+
"The system database does not support show create.";
399401

400402
// ======================== Traverser ========================
401403

‎iotdb-core/datanode/src/main/i18n/zh/org/apache/iotdb/db/i18n/DataNodePipeMessages.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,10 @@ public final class DataNodePipeMessages {
217217
"Pipe 跳过不应传输的临时 TsFile:{}";
218218
public static final String PULLED_PIPE_META_FROM_CONFIG_NODE_RECOVERING =
219219
"已从 config node 拉取 pipe 元数据:{},正在恢复 ...";
220+
public static final String FAILED_TO_SHOW_CREATE_PIPE_NOT_EXIST =
221+
"show create pipe %s 失败,该 pipe 不存在。";
222+
public static final String FAILED_TO_SHOW_CREATE_TOPIC_NOT_EXIST =
223+
"show create topic %s 失败,该 topic 不存在。";
220224
public static final String RECEIVED_PIPE_HEARTBEAT_REQUEST_FROM_CONFIG_NODE =
221225
"收到来自 config node 的 pipe 心跳请求 {}。";
222226
public static final String REGION_NO_TSFILEINSERTIONEVENTS_TO_REPLACE_FOR_SOURCE =

‎iotdb-core/datanode/src/main/i18n/zh/org/apache/iotdb/db/i18n/DataNodeQueryMessages.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ public final class DataNodeQueryMessages {
299299
"SELECT INTO:${i} 中的 i 应为整数。";
300300
public static final String FAILED_TO_GET_DATABASE_MAP =
301301
"获取数据库映射失败";
302+
public static final String UNKNOWN_DATABASE = "未知数据库 %s";
302303
public static final String LOAD_ANALYSIS_STAGE_ALL_TSFILES_HAVE_BEEN_ANALYZED =
303304
"加载 - 分析阶段:所有 TsFile 已分析完毕。";
304305
public static final String ASYNC_LOAD_HAS_FAILED_AND_IS_NOW_TRYING =

‎iotdb-core/datanode/src/main/i18n/zh/org/apache/iotdb/db/i18n/DataNodeSchemaMessages.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,8 @@ public final class DataNodeSchemaMessages {
395395

396396
public static final String SYSTEM_VIEW_NOT_SUPPORT_SHOW_CREATE =
397397
"系统视图不支持 show create。";
398+
public static final String SYSTEM_DATABASE_NOT_SUPPORT_SHOW_CREATE =
399+
"系统数据库不支持 show create。";
398400

399401
// ======================== 附加 SchemaRegion 相关消息 ========================
400402

‎iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/common/header/DatasetHeaderFactory.java‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,18 @@ public static DatasetHeader getShowCreateTableColumnHeader() {
263263
return new DatasetHeader(ColumnHeaderConstant.showCreateTableColumnHeaders, true);
264264
}
265265

266+
public static DatasetHeader getShowCreatePipeColumnHeader() {
267+
return new DatasetHeader(ColumnHeaderConstant.showCreatePipeColumnHeaders, true);
268+
}
269+
270+
public static DatasetHeader getShowCreateTopicColumnHeader() {
271+
return new DatasetHeader(ColumnHeaderConstant.showCreateTopicColumnHeaders, true);
272+
}
273+
274+
public static DatasetHeader getShowCreateDatabaseColumnHeader() {
275+
return new DatasetHeader(ColumnHeaderConstant.showCreateDatabaseColumnHeaders, true);
276+
}
277+
266278
public static DatasetHeader getShowTablesHeader() {
267279
return new DatasetHeader(ColumnHeaderConstant.showTablesColumnHeaders, true);
268280
}

0 commit comments

Comments
 (0)