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

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

commit 456b960d470df6effb1083d82350ee4259e2061c
Author: JackieTien97 <[email protected]>
AuthorDate: Tue Jun 4 18:43:35 2024 +0800

    add sqlDialect parameter for IT framework
---
 .../iotdb/it/env/cluster/env/AbstractEnv.java      | 110 +++++++++++++--------
 .../iotdb/it/env/remote/env/RemoteServerEnv.java   |  94 +++++++++++-------
 .../java/org/apache/iotdb/itbase/env/BaseEnv.java  |  59 +++++++++--
 3 files changed, 177 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..0544438fca4 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,20 @@ 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(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);
   }
 
-  Connection getConnection(Constant.Version version, String username, String 
password)
+  Connection getConnection(
+      Constant.Version version, String username, String password, String 
sqlDialect)
       throws SQLException;
 
-  Connection getConnection(String username, String password) throws 
SQLException;
+  Connection getConnection(String username, String password, String 
sqlDialect) throws SQLException;
 
   default Connection 
getWriteOnlyConnectionWithSpecifiedDataNode(DataNodeWrapper dataNode)
       throws SQLException {
@@ -140,13 +149,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(String sqlDialect) throws 
IoTDBConnectionException;
+
+  default ISession getSessionConnection(String userName, String password)
+      throws IoTDBConnectionException {
+    return getSessionConnection(userName, password, TREE_SQL_DIALECT);
+  }
 
-  ISession getSessionConnection() throws IoTDBConnectionException;
+  ISession getSessionConnection(String userName, String password, String 
sqlDialect)
+      throws IoTDBConnectionException;
 
-  ISession getSessionConnection(String userName, String password) 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 +287,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;
+  }
 }

Reply via email to