This is an automated email from the ASF dual-hosted git repository.

jackietien pushed a commit to branch ty/TableModelGrammar
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/ty/TableModelGrammar by this 
push:
     new 780cbdfe28a Add IT for database management
780cbdfe28a is described below

commit 780cbdfe28a90d2e9d08718b45cfe02f77b6f17a
Author: Jackie Tien <[email protected]>
AuthorDate: Wed Jun 5 15:16:22 2024 +0800

    Add IT for database management
---
 .../iotdb/it/env/cluster/env/AbstractEnv.java      | 110 ++++++++------
 .../iotdb/it/env/remote/env/RemoteServerEnv.java   |  94 +++++++-----
 .../java/org/apache/iotdb/itbase/env/BaseEnv.java  |  78 +++++++++-
 .../relational/it/schema/IoTDBDatabaseIT.java      | 162 +++++++++++++++++++++
 .../iotdb/relational/it/schema/IoTDBTableIT.java   |  45 ++++++
 5 files changed, 403 insertions(+), 86 deletions(-)

diff --git 
a/integration-test/src/main/java/org/apache/iotdb/it/env/cluster/env/AbstractEnv.java
 
b/integration-test/src/main/java/org/apache/iotdb/it/env/cluster/env/AbstractEnv.java
index 981d39dccca..84425f298d7 100644
--- 
a/integration-test/src/main/java/org/apache/iotdb/it/env/cluster/env/AbstractEnv.java
+++ 
b/integration-test/src/main/java/org/apache/iotdb/it/env/cluster/env/AbstractEnv.java
@@ -377,16 +377,19 @@ public abstract class AbstractEnv implements BaseEnv {
   }
 
   @Override
-  public Connection getConnection(String username, String password) throws 
SQLException {
+  public Connection getConnection(String username, String password, String 
sqlDialect)
+      throws SQLException {
     return new ClusterTestConnection(
-        getWriteConnection(null, username, password), getReadConnections(null, 
username, password));
+        getWriteConnection(null, username, password, sqlDialect),
+        getReadConnections(null, username, password, sqlDialect));
   }
 
   @Override
   public Connection getWriteOnlyConnectionWithSpecifiedDataNode(
       DataNodeWrapper dataNode, String username, String password) throws 
SQLException {
     return new ClusterTestConnection(
-        getWriteConnectionWithSpecifiedDataNode(dataNode, null, username, 
password),
+        getWriteConnectionWithSpecifiedDataNode(
+            dataNode, null, username, password, TREE_SQL_DIALECT),
         Collections.emptyList());
   }
 
@@ -394,72 +397,92 @@ public abstract class AbstractEnv implements BaseEnv {
   public Connection getConnectionWithSpecifiedDataNode(
       DataNodeWrapper dataNode, String username, String password) throws 
SQLException {
     return new ClusterTestConnection(
-        getWriteConnectionWithSpecifiedDataNode(dataNode, null, username, 
password),
-        getReadConnections(null, username, password));
+        getWriteConnectionWithSpecifiedDataNode(
+            dataNode, null, username, password, TREE_SQL_DIALECT),
+        getReadConnections(null, username, password, TREE_SQL_DIALECT));
   }
 
   @Override
-  public Connection getConnection(Constant.Version version, String username, 
String password)
+  public Connection getConnection(
+      Constant.Version version, String username, String password, String 
sqlDialect)
       throws SQLException {
     if (System.getProperty("ReadAndVerifyWithMultiNode", 
"true").equalsIgnoreCase("true")) {
       return new ClusterTestConnection(
-          getWriteConnection(version, username, password),
-          getReadConnections(version, username, password));
+          getWriteConnection(version, username, password, sqlDialect),
+          getReadConnections(version, username, password, sqlDialect));
     } else {
-      return getWriteConnection(version, username, 
password).getUnderlyingConnecton();
+      return getWriteConnection(version, username, password, 
sqlDialect).getUnderlyingConnecton();
     }
   }
 
   @Override
-  public ISession getSessionConnection() throws IoTDBConnectionException {
+  public ISession getSessionConnection(String sqlDialect) throws 
IoTDBConnectionException {
     DataNodeWrapper dataNode =
         
this.dataNodeWrapperList.get(rand.nextInt(this.dataNodeWrapperList.size()));
-    Session session = new Session(dataNode.getIp(), dataNode.getPort());
+    Session session =
+        new Session.Builder()
+            .host(dataNode.getIp())
+            .port(dataNode.getPort())
+            .sqlDialect(sqlDialect)
+            .build();
     session.open();
     return session;
   }
 
   @Override
-  public ISession getSessionConnection(String userName, String password)
+  public ISession getSessionConnection(String userName, String password, 
String sqlDialect)
       throws IoTDBConnectionException {
     DataNodeWrapper dataNode =
         
this.dataNodeWrapperList.get(rand.nextInt(this.dataNodeWrapperList.size()));
-    Session session = new Session(dataNode.getIp(), dataNode.getPort(), 
userName, password);
+    Session session =
+        new Session.Builder()
+            .host(dataNode.getIp())
+            .port(dataNode.getPort())
+            .username(userName)
+            .password(password)
+            .sqlDialect(sqlDialect)
+            .build();
     session.open();
     return session;
   }
 
   @Override
-  public ISession getSessionConnection(List<String> nodeUrls) throws 
IoTDBConnectionException {
+  public ISession getSessionConnection(List<String> nodeUrls, String 
sqlDialect)
+      throws IoTDBConnectionException {
     Session session =
-        new Session(
-            nodeUrls,
-            SessionConfig.DEFAULT_USER,
-            SessionConfig.DEFAULT_PASSWORD,
-            SessionConfig.DEFAULT_FETCH_SIZE,
-            null,
-            SessionConfig.DEFAULT_INITIAL_BUFFER_CAPACITY,
-            SessionConfig.DEFAULT_MAX_FRAME_SIZE,
-            SessionConfig.DEFAULT_REDIRECTION_MODE,
-            SessionConfig.DEFAULT_VERSION);
+        new Session.Builder()
+            .nodeUrls(nodeUrls)
+            .username(SessionConfig.DEFAULT_USER)
+            .password(SessionConfig.DEFAULT_PASSWORD)
+            .fetchSize(SessionConfig.DEFAULT_FETCH_SIZE)
+            .zoneId(null)
+            
.thriftDefaultBufferSize(SessionConfig.DEFAULT_INITIAL_BUFFER_CAPACITY)
+            .thriftMaxFrameSize(SessionConfig.DEFAULT_MAX_FRAME_SIZE)
+            .enableRedirection(SessionConfig.DEFAULT_REDIRECTION_MODE)
+            .version(SessionConfig.DEFAULT_VERSION)
+            .sqlDialect(sqlDialect)
+            .build();
     session.open();
     return session;
   }
 
   @Override
-  public ISessionPool getSessionPool(int maxSize) {
+  public ISessionPool getSessionPool(int maxSize, String sqlDialect) {
     DataNodeWrapper dataNode =
         
this.dataNodeWrapperList.get(rand.nextInt(this.dataNodeWrapperList.size()));
-    return new SessionPool(
-        dataNode.getIp(),
-        dataNode.getPort(),
-        SessionConfig.DEFAULT_USER,
-        SessionConfig.DEFAULT_PASSWORD,
-        maxSize);
+    return new SessionPool.Builder()
+        .host(dataNode.getIp())
+        .port(dataNode.getPort())
+        .user(SessionConfig.DEFAULT_USER)
+        .password(SessionConfig.DEFAULT_PASSWORD)
+        .maxSize(maxSize)
+        .sqlDialect(sqlDialect)
+        .build();
   }
 
   protected NodeConnection getWriteConnection(
-      Constant.Version version, String username, String password) throws 
SQLException {
+      Constant.Version version, String username, String password, String 
sqlDialect)
+      throws SQLException {
     DataNodeWrapper dataNode;
 
     if (System.getProperty("RandomSelectWriteNode", 
"true").equalsIgnoreCase("true")) {
@@ -470,11 +493,15 @@ public abstract class AbstractEnv implements BaseEnv {
     }
 
     return getWriteConnectionFromDataNodeList(
-        this.dataNodeWrapperList, version, username, password);
+        this.dataNodeWrapperList, version, username, password, sqlDialect);
   }
 
   protected NodeConnection getWriteConnectionWithSpecifiedDataNode(
-      DataNodeWrapper dataNode, Constant.Version version, String username, 
String password)
+      DataNodeWrapper dataNode,
+      Constant.Version version,
+      String username,
+      String password,
+      String sqlDialect)
       throws SQLException {
     String endpoint = dataNode.getIp() + ":" + dataNode.getPort();
     Connection writeConnection =
@@ -482,8 +509,7 @@ public abstract class AbstractEnv implements BaseEnv {
             Config.IOTDB_URL_PREFIX
                 + endpoint
                 + getParam(version, NODE_NETWORK_TIMEOUT_MS, ZERO_TIME_ZONE),
-            System.getProperty("User", username),
-            System.getProperty("Password", password));
+            BaseEnv.constructProperties(username, password, sqlDialect));
     return new NodeConnection(
         endpoint,
         NodeConnection.NodeRole.DATA_NODE,
@@ -495,14 +521,16 @@ public abstract class AbstractEnv implements BaseEnv {
       List<DataNodeWrapper> dataNodeList,
       Constant.Version version,
       String username,
-      String password)
+      String password,
+      String sqlDialect)
       throws SQLException {
     List<DataNodeWrapper> dataNodeWrapperListCopy = new 
ArrayList<>(dataNodeList);
     Collections.shuffle(dataNodeWrapperListCopy);
     SQLException lastException = null;
     for (DataNodeWrapper dataNode : dataNodeWrapperListCopy) {
       try {
-        return getWriteConnectionWithSpecifiedDataNode(dataNode, version, 
username, password);
+        return getWriteConnectionWithSpecifiedDataNode(
+            dataNode, version, username, password, sqlDialect);
       } catch (SQLException e) {
         lastException = e;
       }
@@ -512,7 +540,8 @@ public abstract class AbstractEnv implements BaseEnv {
   }
 
   protected List<NodeConnection> getReadConnections(
-      Constant.Version version, String username, String password) throws 
SQLException {
+      Constant.Version version, String username, String password, String 
sqlDialect)
+      throws SQLException {
     List<String> endpoints = new ArrayList<>();
     ParallelRequestDelegate<NodeConnection> readConnRequestDelegate =
         new ParallelRequestDelegate<>(endpoints, NODE_START_TIMEOUT);
@@ -526,8 +555,7 @@ public abstract class AbstractEnv implements BaseEnv {
                     Config.IOTDB_URL_PREFIX
                         + endpoint
                         + getParam(version, NODE_NETWORK_TIMEOUT_MS, 
ZERO_TIME_ZONE),
-                    System.getProperty("User", username),
-                    System.getProperty("Password", password));
+                    BaseEnv.constructProperties(username, password, 
sqlDialect));
             return new NodeConnection(
                 endpoint,
                 NodeConnection.NodeRole.DATA_NODE,
diff --git 
a/integration-test/src/main/java/org/apache/iotdb/it/env/remote/env/RemoteServerEnv.java
 
b/integration-test/src/main/java/org/apache/iotdb/it/env/remote/env/RemoteServerEnv.java
index eae42bd7a23..665d6248ad0 100644
--- 
a/integration-test/src/main/java/org/apache/iotdb/it/env/remote/env/RemoteServerEnv.java
+++ 
b/integration-test/src/main/java/org/apache/iotdb/it/env/remote/env/RemoteServerEnv.java
@@ -118,13 +118,15 @@ public class RemoteServerEnv implements BaseEnv {
   }
 
   @Override
-  public Connection getConnection(String username, String password) throws 
SQLException {
+  public Connection getConnection(String username, String password, String 
sqlDialect)
+      throws SQLException {
     Connection connection;
     try {
       Class.forName(Config.JDBC_DRIVER_NAME);
       connection =
           DriverManager.getConnection(
-              Config.IOTDB_URL_PREFIX + ip_addr + ":" + port, this.user, 
this.password);
+              Config.IOTDB_URL_PREFIX + ip_addr + ":" + port,
+              BaseEnv.constructProperties(this.user, this.password, 
sqlDialect));
     } catch (ClassNotFoundException e) {
       e.printStackTrace();
       throw new AssertionError();
@@ -141,11 +143,12 @@ public class RemoteServerEnv implements BaseEnv {
   @Override
   public Connection getConnectionWithSpecifiedDataNode(
       DataNodeWrapper dataNode, String username, String password) throws 
SQLException {
-    return getConnection(username, password);
+    return getConnection(username, password, TREE_SQL_DIALECT);
   }
 
   @Override
-  public Connection getConnection(Constant.Version version, String username, 
String password)
+  public Connection getConnection(
+      Constant.Version version, String username, String password, String 
sqlDialect)
       throws SQLException {
     Connection connection;
     try {
@@ -160,8 +163,7 @@ public class RemoteServerEnv implements BaseEnv {
                   + VERSION
                   + "="
                   + version.toString(),
-              this.user,
-              this.password);
+              BaseEnv.constructProperties(this.user, this.password, 
sqlDialect));
     } catch (ClassNotFoundException e) {
       e.printStackTrace();
       throw new AssertionError();
@@ -194,51 +196,69 @@ public class RemoteServerEnv implements BaseEnv {
   }
 
   @Override
-  public ISessionPool getSessionPool(int maxSize) {
-    return new SessionPool(
-        SessionConfig.DEFAULT_HOST,
-        SessionConfig.DEFAULT_PORT,
-        SessionConfig.DEFAULT_USER,
-        SessionConfig.DEFAULT_PASSWORD,
-        maxSize,
-        SessionConfig.DEFAULT_FETCH_SIZE,
-        60_000,
-        false,
-        null,
-        SessionConfig.DEFAULT_REDIRECTION_MODE,
-        SessionConfig.DEFAULT_CONNECTION_TIMEOUT_MS,
-        SessionConfig.DEFAULT_VERSION,
-        SessionConfig.DEFAULT_INITIAL_BUFFER_CAPACITY,
-        SessionConfig.DEFAULT_MAX_FRAME_SIZE);
+  public ISessionPool getSessionPool(int maxSize, String sqlDialect) {
+    return new SessionPool.Builder()
+        .host(SessionConfig.DEFAULT_HOST)
+        .port(SessionConfig.DEFAULT_PORT)
+        .user(SessionConfig.DEFAULT_USER)
+        .password(SessionConfig.DEFAULT_PASSWORD)
+        .maxSize(maxSize)
+        .fetchSize(SessionConfig.DEFAULT_FETCH_SIZE)
+        .waitToGetSessionTimeoutInMs(60_000)
+        .enableCompression(false)
+        .zoneId(null)
+        .enableRedirection(SessionConfig.DEFAULT_REDIRECTION_MODE)
+        .connectionTimeoutInMs(SessionConfig.DEFAULT_CONNECTION_TIMEOUT_MS)
+        .version(SessionConfig.DEFAULT_VERSION)
+        .thriftDefaultBufferSize(SessionConfig.DEFAULT_INITIAL_BUFFER_CAPACITY)
+        .thriftMaxFrameSize(SessionConfig.DEFAULT_MAX_FRAME_SIZE)
+        .sqlDialect(sqlDialect)
+        .build();
   }
 
   @Override
-  public ISession getSessionConnection() throws IoTDBConnectionException {
-    Session session = new Session(ip_addr, Integer.parseInt(port));
+  public ISession getSessionConnection(String sqlDialect) throws 
IoTDBConnectionException {
+    Session session =
+        new Session.Builder()
+            .host(ip_addr)
+            .port(Integer.parseInt(port))
+            .sqlDialect(sqlDialect)
+            .build();
     session.open();
     return session;
   }
 
-  public ISession getSessionConnection(String userName, String password)
+  @Override
+  public ISession getSessionConnection(String userName, String password, 
String sqlDialect)
       throws IoTDBConnectionException {
-    Session session = new Session(ip_addr, Integer.parseInt(port), userName, 
password);
+    Session session =
+        new Session.Builder()
+            .host(ip_addr)
+            .port(Integer.parseInt(port))
+            .username(userName)
+            .password(password)
+            .sqlDialect(sqlDialect)
+            .build();
     session.open();
     return session;
   }
 
   @Override
-  public ISession getSessionConnection(List<String> nodeUrls) throws 
IoTDBConnectionException {
+  public ISession getSessionConnection(List<String> nodeUrls, String 
sqlDialect)
+      throws IoTDBConnectionException {
     Session session =
-        new Session(
-            Collections.singletonList(ip_addr + ":" + port),
-            SessionConfig.DEFAULT_USER,
-            SessionConfig.DEFAULT_PASSWORD,
-            SessionConfig.DEFAULT_FETCH_SIZE,
-            null,
-            SessionConfig.DEFAULT_INITIAL_BUFFER_CAPACITY,
-            SessionConfig.DEFAULT_MAX_FRAME_SIZE,
-            SessionConfig.DEFAULT_REDIRECTION_MODE,
-            SessionConfig.DEFAULT_VERSION);
+        new Session.Builder()
+            .nodeUrls(Collections.singletonList(ip_addr + ":" + port))
+            .username(SessionConfig.DEFAULT_USER)
+            .password(SessionConfig.DEFAULT_PASSWORD)
+            .fetchSize(SessionConfig.DEFAULT_FETCH_SIZE)
+            .zoneId(null)
+            
.thriftDefaultBufferSize(SessionConfig.DEFAULT_INITIAL_BUFFER_CAPACITY)
+            .thriftMaxFrameSize(SessionConfig.DEFAULT_MAX_FRAME_SIZE)
+            .enableRedirection(SessionConfig.DEFAULT_REDIRECTION_MODE)
+            .version(SessionConfig.DEFAULT_VERSION)
+            .sqlDialect(sqlDialect)
+            .build();
     session.open();
     return session;
   }
diff --git 
a/integration-test/src/main/java/org/apache/iotdb/itbase/env/BaseEnv.java 
b/integration-test/src/main/java/org/apache/iotdb/itbase/env/BaseEnv.java
index 965e2254e84..472df6c6f63 100644
--- a/integration-test/src/main/java/org/apache/iotdb/itbase/env/BaseEnv.java
+++ b/integration-test/src/main/java/org/apache/iotdb/itbase/env/BaseEnv.java
@@ -27,6 +27,7 @@ import org.apache.iotdb.isession.SessionConfig;
 import org.apache.iotdb.isession.pool.ISessionPool;
 import org.apache.iotdb.it.env.cluster.node.ConfigNodeWrapper;
 import org.apache.iotdb.it.env.cluster.node.DataNodeWrapper;
+import org.apache.iotdb.jdbc.Config;
 import org.apache.iotdb.jdbc.Constant;
 import org.apache.iotdb.rpc.IoTDBConnectionException;
 
@@ -40,9 +41,14 @@ import java.sql.Connection;
 import java.sql.SQLException;
 import java.util.List;
 import java.util.Optional;
+import java.util.Properties;
 
 public interface BaseEnv {
 
+  String TREE_SQL_DIALECT = "tree";
+
+  String TABLE_SQL_DIALECT = "table";
+
   /** Init a cluster with default number of ConfigNodes and DataNodes. */
   void initClusterEnvironment();
 
@@ -98,17 +104,39 @@ public interface BaseEnv {
   List<String> getMetricPrometheusReporterContents();
 
   default Connection getConnection() throws SQLException {
-    return getConnection(SessionConfig.DEFAULT_USER, 
SessionConfig.DEFAULT_PASSWORD);
+    return getConnection(
+        SessionConfig.DEFAULT_USER, SessionConfig.DEFAULT_PASSWORD, 
TREE_SQL_DIALECT);
+  }
+
+  default Connection getConnection(String sqlDialect) throws SQLException {
+    return getConnection(SessionConfig.DEFAULT_USER, 
SessionConfig.DEFAULT_PASSWORD, sqlDialect);
   }
 
   default Connection getConnection(Constant.Version version) throws 
SQLException {
-    return getConnection(version, SessionConfig.DEFAULT_USER, 
SessionConfig.DEFAULT_PASSWORD);
+    return getConnection(
+        version, SessionConfig.DEFAULT_USER, SessionConfig.DEFAULT_PASSWORD, 
TREE_SQL_DIALECT);
+  }
+
+  default Connection getConnection(Constant.Version version, String sqlDialect)
+      throws SQLException {
+    return getConnection(
+        version, SessionConfig.DEFAULT_USER, SessionConfig.DEFAULT_PASSWORD, 
sqlDialect);
   }
 
-  Connection getConnection(Constant.Version version, String username, String 
password)
+  default Connection getConnection(Constant.Version version, String username, 
String password)
+      throws SQLException {
+    return getConnection(version, username, password, TREE_SQL_DIALECT);
+  }
+
+  Connection getConnection(
+      Constant.Version version, String username, String password, String 
sqlDialect)
       throws SQLException;
 
-  Connection getConnection(String username, String password) throws 
SQLException;
+  default Connection getConnection(String username, String password) throws 
SQLException {
+    return getConnection(username, password, TREE_SQL_DIALECT);
+  }
+
+  Connection getConnection(String username, String password, String 
sqlDialect) throws SQLException;
 
   default Connection 
getWriteOnlyConnectionWithSpecifiedDataNode(DataNodeWrapper dataNode)
       throws SQLException {
@@ -140,13 +168,32 @@ public interface BaseEnv {
   IConfigNodeRPCService.Iface getLeaderConfigNodeConnection()
       throws ClientManagerException, IOException, InterruptedException;
 
-  ISessionPool getSessionPool(int maxSize);
+  default ISessionPool getSessionPool(int maxSize) {
+    return getSessionPool(maxSize, TREE_SQL_DIALECT);
+  }
+
+  ISessionPool getSessionPool(int maxSize, String sqlDialect);
+
+  default ISession getSessionConnection() throws IoTDBConnectionException {
+    return getSessionConnection(TREE_SQL_DIALECT);
+  }
 
-  ISession getSessionConnection() throws IoTDBConnectionException;
+  ISession getSessionConnection(String sqlDialect) throws 
IoTDBConnectionException;
 
-  ISession getSessionConnection(String userName, String password) throws 
IoTDBConnectionException;
+  default ISession getSessionConnection(String userName, String password)
+      throws IoTDBConnectionException {
+    return getSessionConnection(userName, password, TREE_SQL_DIALECT);
+  }
+
+  ISession getSessionConnection(String userName, String password, String 
sqlDialect)
+      throws IoTDBConnectionException;
+
+  default ISession getSessionConnection(List<String> nodeUrls) throws 
IoTDBConnectionException {
+    return getSessionConnection(nodeUrls, TREE_SQL_DIALECT);
+  }
 
-  ISession getSessionConnection(List<String> nodeUrls) throws 
IoTDBConnectionException;
+  ISession getSessionConnection(List<String> nodeUrls, String sqlDialect)
+      throws IoTDBConnectionException;
 
   /**
    * Get the index of the first dataNode with a SchemaRegion leader.
@@ -259,4 +306,19 @@ public interface BaseEnv {
   void registerConfigNodeKillPoints(List<String> killPoints);
 
   void registerDataNodeKillPoints(List<String> killPoints);
+
+  static Properties constructProperties(String username, String password, 
String sqlDialect) {
+    Properties info = new Properties();
+
+    if (username != null) {
+      info.put("user", username);
+    }
+    if (password != null) {
+      info.put("password", password);
+    }
+    if (sqlDialect != null) {
+      info.put(Config.SQL_DIALECT, sqlDialect);
+    }
+    return info;
+  }
 }
diff --git 
a/integration-test/src/test/java/org/apache/iotdb/relational/it/schema/IoTDBDatabaseIT.java
 
b/integration-test/src/test/java/org/apache/iotdb/relational/it/schema/IoTDBDatabaseIT.java
new file mode 100644
index 00000000000..cb02608e424
--- /dev/null
+++ 
b/integration-test/src/test/java/org/apache/iotdb/relational/it/schema/IoTDBDatabaseIT.java
@@ -0,0 +1,162 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.relational.it.schema;
+
+import org.apache.iotdb.it.env.EnvFactory;
+import org.apache.iotdb.it.framework.IoTDBTestRunner;
+import org.apache.iotdb.itbase.category.ClusterIT;
+import org.apache.iotdb.itbase.category.LocalStandaloneIT;
+import org.apache.iotdb.itbase.env.BaseEnv;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static 
org.apache.iotdb.db.queryengine.common.header.ColumnHeaderConstant.showDBColumnHeaders;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+@RunWith(IoTDBTestRunner.class)
+@Category({LocalStandaloneIT.class, ClusterIT.class})
+public class IoTDBDatabaseIT {
+
+  @BeforeClass
+  public static void setUp() throws Exception {
+    EnvFactory.getEnv().initClusterEnvironment();
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanClusterEnvironment();
+  }
+
+  @Test
+  public void testManageDatabase() {
+    try (Connection connection = 
EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT);
+        Statement statement = connection.createStatement()) {
+
+      // create
+      statement.execute("create database test");
+
+      String[] databaseNames = new String[] {"test"};
+      int[] schemaReplicaFactors = new int[] {1};
+      int[] dataReplicaFactors = new int[] {1};
+      int[] timePartitionInterval = new int[] {604800000};
+
+      // show
+      try (ResultSet resultSet = statement.executeQuery("SHOW DATABASES")) {
+        int cnt = 0;
+        ResultSetMetaData metaData = resultSet.getMetaData();
+        assertEquals(showDBColumnHeaders.size(), metaData.getColumnCount());
+        for (int i = 0; i < showDBColumnHeaders.size(); i++) {
+          assertEquals(showDBColumnHeaders.get(i).getColumnName(), 
metaData.getColumnName(i + 1));
+        }
+        while (resultSet.next()) {
+          assertEquals(databaseNames[cnt], resultSet.getString(1));
+          assertEquals(schemaReplicaFactors[cnt], resultSet.getInt(2));
+          assertEquals(dataReplicaFactors[cnt], resultSet.getInt(3));
+          assertEquals(timePartitionInterval[cnt], resultSet.getLong(4));
+          cnt++;
+        }
+        assertEquals(databaseNames.length, cnt);
+      }
+
+      // use
+      statement.execute("use test");
+
+      // use nonexistent database
+      try {
+        statement.execute("use test1");
+        fail("use test1 shouldn't succeed because test1 doesn't exist");
+      } catch (SQLException e) {
+        assertEquals("500: Database test1 doesn't exists.", e.getMessage());
+      }
+
+      // drop
+      statement.execute("drop database test");
+      try (ResultSet resultSet = statement.executeQuery("SHOW DATABASES")) {
+        assertFalse(resultSet.next());
+      }
+
+      // drop nonexistent database
+      try {
+        statement.execute("drop database test");
+        fail("drop database test shouldn't succeed because test1 doesn't 
exist");
+      } catch (SQLException e) {
+        // TODO error msg should be changed to 500: Database test1 doesn't 
exists
+        assertEquals("508: Path [root.test] does not exist", e.getMessage());
+      }
+
+      // create with strange name
+      try {
+        statement.execute("create database 1test");
+        fail("create database 1test shouldn't succeed because test1 doesn't 
exist");
+      } catch (SQLException e) {
+        assertTrue(
+            e.getMessage(),
+            e.getMessage()
+                .endsWith(
+                    "identifiers must not start with a digit; surround the 
identifier with double quotes"));
+      }
+
+      statement.execute("create database \"1test\"");
+      statement.execute("use \"1test\"");
+      statement.execute("drop database \"1test\"");
+
+      //      try {
+      //        statement.execute("create database 1");
+      //        fail("create database 1test shouldn't succeed because test1 
doesn't exist");
+      //      } catch (SQLException e) {
+      //        // TODO add error msg assert
+      //      }
+      //
+      //      // TODO fix it, should succeed
+      //      statement.execute("create database \"1\"");
+      //      statement.execute("use \"1\"");
+      //      statement.execute("drop database \"1\"");
+      //
+      //      try {
+      //        statement.execute("create database a.b");
+      //        fail("create database 1test shouldn't succeed because test1 
doesn't exist");
+      //      } catch (SQLException e) {
+      //        // TODO add error msg assert
+      //      }
+      //
+      //      // TODO fix it, should succeed
+      //      statement.execute("create database \"a.b\"");
+      //      statement.execute("use \"a.b\"");
+      //      statement.execute("drop database \"a.b\"");
+
+    } catch (SQLException e) {
+      e.printStackTrace();
+      fail(e.getMessage());
+    }
+  }
+}
diff --git 
a/integration-test/src/test/java/org/apache/iotdb/relational/it/schema/IoTDBTableIT.java
 
b/integration-test/src/test/java/org/apache/iotdb/relational/it/schema/IoTDBTableIT.java
new file mode 100644
index 00000000000..a01741d2cda
--- /dev/null
+++ 
b/integration-test/src/test/java/org/apache/iotdb/relational/it/schema/IoTDBTableIT.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.relational.it.schema;
+
+import org.apache.iotdb.it.env.EnvFactory;
+import org.apache.iotdb.it.framework.IoTDBTestRunner;
+import org.apache.iotdb.itbase.category.ClusterIT;
+import org.apache.iotdb.itbase.category.LocalStandaloneIT;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+
+@RunWith(IoTDBTestRunner.class)
+@Category({LocalStandaloneIT.class, ClusterIT.class})
+public class IoTDBTableIT {
+
+  @BeforeClass
+  public static void setUp() throws Exception {
+    EnvFactory.getEnv().initClusterEnvironment();
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanClusterEnvironment();
+  }
+}

Reply via email to