You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by qi...@apache.org on 2019/08/27 14:23:10 UTC

[incubator-iotdb] branch master updated: [IOTDB-179] Add create matadata interfaces to Session (#357)

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

qiaojialin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git


The following commit(s) were added to refs/heads/master by this push:
     new bfbccbe  [IOTDB-179] Add create matadata interfaces to Session (#357)
bfbccbe is described below

commit bfbccbe3c6a6efff0696a913afcf0057bf178658
Author: Zesong Sun <15...@smail.nju.edu.cn>
AuthorDate: Tue Aug 27 22:23:05 2019 +0800

    [IOTDB-179] Add create matadata interfaces to Session (#357)
    
    * Add create matadata interfaces to Session
---
 .../org/apache/iotdb/client/AbstractClient.java    |   1 -
 .../UserGuide/7-Session API/1-Session API.md       |  16 +--
 .../UserGuide/7-Session API/1-Session API.md       |  16 +--
 example/{session => jdbc}/pom.xml                  |   9 +-
 .../main/java/org/apache/iotdb/JDBCExample.java    |   0
 .../org/apache/iotdb}/PrepareStatementDemo.java    |   2 +-
 example/session/pom.xml                            |   5 -
 .../main/java/org/apache/iotdb/SessionExample.java |  31 ++----
 .../org/apache/iotdb/jdbc/IoTDBConnection.java     |  13 +--
 .../org/apache/iotdb/jdbc/IoTDBQueryResultSet.java |  10 +-
 .../java/org/apache/iotdb/jdbc/IoTDBStatement.java |   4 +-
 .../org/apache/iotdb/jdbc/IoTDBConnectionTest.java |   2 +-
 .../iotdb/jdbc/IoTDBPreparedStatementTest.java     |   2 +-
 .../org/apache/iotdb/jdbc/demo/MetadataDemo.java   |  36 -------
 .../iotdb/db/qp/executor/QueryProcessExecutor.java |   2 +-
 .../iotdb/db/qp/logical/sys/MetadataOperator.java  |   8 +-
 .../iotdb/db/qp/physical/sys/MetadataPlan.java     |  47 +++++---
 .../iotdb/db/qp/strategy/LogicalGenerator.java     |   2 +-
 .../org/apache/iotdb/db/service/TSServiceImpl.java | 119 ++++++++++++++-------
 service-rpc/src/main/thrift/rpc.thrift             |  48 ++++-----
 .../java/org/apache/iotdb/session/Session.java     |  44 +++++---
 21 files changed, 197 insertions(+), 220 deletions(-)

diff --git a/client/src/main/java/org/apache/iotdb/client/AbstractClient.java b/client/src/main/java/org/apache/iotdb/client/AbstractClient.java
index 3dedc0c..ece480c 100644
--- a/client/src/main/java/org/apache/iotdb/client/AbstractClient.java
+++ b/client/src/main/java/org/apache/iotdb/client/AbstractClient.java
@@ -224,7 +224,6 @@ public abstract class AbstractClient {
       }
     }
 
-    println(StringUtils.repeat('-', DIVIDING_LINE_LENGTH));
     printCount(isShow, res, cnt);
   }
 
diff --git a/docs/Documentation-CHN/UserGuide/7-Session API/1-Session API.md b/docs/Documentation-CHN/UserGuide/7-Session API/1-Session API.md
index b72d436..9b21474 100644
--- a/docs/Documentation-CHN/UserGuide/7-Session API/1-Session API.md	
+++ b/docs/Documentation-CHN/UserGuide/7-Session API/1-Session API.md	
@@ -62,19 +62,13 @@ import org.apache.iotdb.tsfile.write.schema.Schema;
 public class SessionExample {
 
   public static void main(String[] args) throws ClassNotFoundException, IoTDBSessionException {
-    Class.forName("org.apache.iotdb.jdbc.IoTDBDriver");
-    try (Connection connection = DriverManager.getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root");
-        Statement statement = connection.createStatement()) {
-      statement.execute("SET STORAGE GROUP TO root.sg1");
-      statement.execute("CREATE TIMESERIES root.sg1.d1.s1 WITH DATATYPE=INT64, ENCODING=RLE");
-      statement.execute("CREATE TIMESERIES root.sg1.d1.s2 WITH DATATYPE=INT64, ENCODING=RLE");
-      statement.execute("CREATE TIMESERIES root.sg1.d1.s3 WITH DATATYPE=INT64, ENCODING=RLE");
-    } catch (Exception e) {
-      System.out.println(e.getMessage());
-    }
-
     Session session = new Session("127.0.0.1", 6667, "root", "root");
     session.open();
+    
+    session.setStorageGroup("root.sg1");
+    session.createTimeseriesResp("root.sg1.d1.s1", TSDataType.INT64, TSEncoding.RLE);
+    session.createTimeseriesResp("root.sg1.d1.s2", TSDataType.INT64, TSEncoding.RLE);
+    session.createTimeseriesResp("root.sg1.d1.s3", TSDataType.INT64, TSEncoding.RLE);
 
     Schema schema = new Schema();
     schema.registerMeasurement(new MeasurementSchema("s1", TSDataType.INT64, TSEncoding.RLE));
diff --git a/docs/Documentation/UserGuide/7-Session API/1-Session API.md b/docs/Documentation/UserGuide/7-Session API/1-Session API.md
index fa0ae6c..b2cd10c 100644
--- a/docs/Documentation/UserGuide/7-Session API/1-Session API.md	
+++ b/docs/Documentation/UserGuide/7-Session API/1-Session API.md	
@@ -71,19 +71,13 @@ import org.apache.iotdb.tsfile.write.schema.Schema;
 public class SessionExample {
 
   public static void main(String[] args) throws ClassNotFoundException, IoTDBSessionException {
-    Class.forName("org.apache.iotdb.jdbc.IoTDBDriver");
-    try (Connection connection = DriverManager.getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root");
-        Statement statement = connection.createStatement()) {
-      statement.execute("SET STORAGE GROUP TO root.sg1");
-      statement.execute("CREATE TIMESERIES root.sg1.d1.s1 WITH DATATYPE=INT64, ENCODING=RLE");
-      statement.execute("CREATE TIMESERIES root.sg1.d1.s2 WITH DATATYPE=INT64, ENCODING=RLE");
-      statement.execute("CREATE TIMESERIES root.sg1.d1.s3 WITH DATATYPE=INT64, ENCODING=RLE");
-    } catch (Exception e) {
-      System.out.println(e.getMessage());
-    }
-
     Session session = new Session("127.0.0.1", 6667, "root", "root");
     session.open();
+    
+    session.setStorageGroup("root.sg1");
+    session.createTimeseriesResp("root.sg1.d1.s1", TSDataType.INT64, TSEncoding.RLE);
+    session.createTimeseriesResp("root.sg1.d1.s2", TSDataType.INT64, TSEncoding.RLE);
+    session.createTimeseriesResp("root.sg1.d1.s3", TSDataType.INT64, TSEncoding.RLE);
 
     Schema schema = new Schema();
     schema.registerMeasurement(new MeasurementSchema("s1", TSDataType.INT64, TSEncoding.RLE));
diff --git a/example/session/pom.xml b/example/jdbc/pom.xml
similarity index 86%
copy from example/session/pom.xml
copy to example/jdbc/pom.xml
index 7386c4b..065731f 100644
--- a/example/session/pom.xml
+++ b/example/jdbc/pom.xml
@@ -26,8 +26,8 @@
         <version>0.9.0-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
-    <artifactId>client-example</artifactId>
-    <name>client-example</name>
+    <artifactId>jdbc-example</artifactId>
+    <name>jdbc-example</name>
     <properties>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
         <maven.compiler.source>1.7</maven.compiler.source>
@@ -36,11 +36,6 @@
     <dependencies>
         <dependency>
             <groupId>org.apache.iotdb</groupId>
-            <artifactId>iotdb-session</artifactId>
-            <version>0.9.0-SNAPSHOT</version>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.iotdb</groupId>
             <artifactId>iotdb-jdbc</artifactId>
             <version>0.9.0-SNAPSHOT</version>
         </dependency>
diff --git a/example/session/src/main/java/org/apache/iotdb/JDBCExample.java b/example/jdbc/src/main/java/org/apache/iotdb/JDBCExample.java
similarity index 100%
rename from example/session/src/main/java/org/apache/iotdb/JDBCExample.java
rename to example/jdbc/src/main/java/org/apache/iotdb/JDBCExample.java
diff --git a/jdbc/src/test/java/org/apache/iotdb/jdbc/demo/PrepareStatementDemo.java b/example/jdbc/src/main/java/org/apache/iotdb/PrepareStatementDemo.java
similarity index 98%
rename from jdbc/src/test/java/org/apache/iotdb/jdbc/demo/PrepareStatementDemo.java
rename to example/jdbc/src/main/java/org/apache/iotdb/PrepareStatementDemo.java
index 3f0e3a0..804bc15 100644
--- a/jdbc/src/test/java/org/apache/iotdb/jdbc/demo/PrepareStatementDemo.java
+++ b/example/jdbc/src/main/java/org/apache/iotdb/PrepareStatementDemo.java
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.iotdb.jdbc.demo;
+package org.apache.iotdb;
 
 import java.sql.Connection;
 import java.sql.DriverManager;
diff --git a/example/session/pom.xml b/example/session/pom.xml
index 7386c4b..8b1b215 100644
--- a/example/session/pom.xml
+++ b/example/session/pom.xml
@@ -39,10 +39,5 @@
             <artifactId>iotdb-session</artifactId>
             <version>0.9.0-SNAPSHOT</version>
         </dependency>
-        <dependency>
-            <groupId>org.apache.iotdb</groupId>
-            <artifactId>iotdb-jdbc</artifactId>
-            <version>0.9.0-SNAPSHOT</version>
-        </dependency>
     </dependencies>
 </project>
diff --git a/example/session/src/main/java/org/apache/iotdb/SessionExample.java b/example/session/src/main/java/org/apache/iotdb/SessionExample.java
index 930d612..0becd79 100644
--- a/example/session/src/main/java/org/apache/iotdb/SessionExample.java
+++ b/example/session/src/main/java/org/apache/iotdb/SessionExample.java
@@ -18,9 +18,6 @@
  */
 package org.apache.iotdb;
 
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.Statement;
 import org.apache.iotdb.session.IoTDBSessionException;
 import org.apache.iotdb.session.Session;
 import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
@@ -29,33 +26,17 @@ import org.apache.iotdb.tsfile.write.record.RowBatch;
 import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
 import org.apache.iotdb.tsfile.write.schema.Schema;
 
-/**
- * you need to set storage group and create timeseries first from Client or JDBC
- *
- * for this example:
- *
- * SET STORAGE GROUP TO root.sg1
- * CREATE TIMESERIES root.sg1.d1.s1 WITH DATATYPE=FLOAT, ENCODING=RLE
- * CREATE TIMESERIES root.sg1.d1.s2 WITH DATATYPE=FLOAT, ENCODING=RLE
- * CREATE TIMESERIES root.sg1.d1.s3 WITH DATATYPE=FLOAT, ENCODING=RLE
- */
 public class SessionExample {
 
-  public static void main(String[] args) throws ClassNotFoundException, IoTDBSessionException {
-    Class.forName("org.apache.iotdb.jdbc.IoTDBDriver");
-    try (Connection connection = DriverManager.getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root");
-        Statement statement = connection.createStatement()) {
-      statement.execute("SET STORAGE GROUP TO root.sg1");
-      statement.execute("CREATE TIMESERIES root.sg1.d1.s1 WITH DATATYPE=INT64, ENCODING=RLE");
-      statement.execute("CREATE TIMESERIES root.sg1.d1.s2 WITH DATATYPE=INT64, ENCODING=RLE");
-      statement.execute("CREATE TIMESERIES root.sg1.d1.s3 WITH DATATYPE=INT64, ENCODING=RLE");
-    } catch (Exception e) {
-      System.out.println(e.getMessage());
-    }
-
+  public static void main(String[] args) throws IoTDBSessionException {
     Session session = new Session("127.0.0.1", 6667, "root", "root");
     session.open();
 
+    session.setStorageGroup("root.sg1");
+    session.createTimeseries("root.sg1.d1.s1", TSDataType.INT64, TSEncoding.RLE);
+    session.createTimeseries("root.sg1.d1.s2", TSDataType.INT64, TSEncoding.RLE);
+    session.createTimeseries("root.sg1.d1.s3", TSDataType.INT64, TSEncoding.RLE);
+
     Schema schema = new Schema();
     schema.registerMeasurement(new MeasurementSchema("s1", TSDataType.INT64, TSEncoding.RLE));
     schema.registerMeasurement(new MeasurementSchema("s2", TSDataType.INT64, TSEncoding.RLE));
diff --git a/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBConnection.java b/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBConnection.java
index 83a96ab..85270e1 100644
--- a/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBConnection.java
+++ b/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBConnection.java
@@ -40,16 +40,7 @@ import java.util.Properties;
 import java.util.concurrent.Executor;
 import org.apache.iotdb.rpc.IoTDBRPCException;
 import org.apache.iotdb.rpc.RpcUtils;
-import org.apache.iotdb.service.rpc.thrift.ServerProperties;
-import org.apache.iotdb.service.rpc.thrift.TSCloseSessionReq;
-import org.apache.iotdb.service.rpc.thrift.TSGetTimeZoneResp;
-import org.apache.iotdb.service.rpc.thrift.TSIService;
-import org.apache.iotdb.service.rpc.thrift.TSOpenSessionReq;
-import org.apache.iotdb.service.rpc.thrift.TSOpenSessionResp;
-import org.apache.iotdb.service.rpc.thrift.TSProtocolVersion;
-import org.apache.iotdb.service.rpc.thrift.TSSetTimeZoneReq;
-import org.apache.iotdb.service.rpc.thrift.TSSetTimeZoneResp;
-import org.apache.iotdb.service.rpc.thrift.TS_SessionHandle;
+import org.apache.iotdb.service.rpc.thrift.*;
 import org.apache.thrift.TException;
 import org.apache.thrift.protocol.TBinaryProtocol;
 import org.apache.thrift.protocol.TCompactProtocol;
@@ -492,7 +483,7 @@ public class IoTDBConnection implements Connection {
 
   public void setTimeZone(String zoneId) throws TException, IoTDBSQLException {
     TSSetTimeZoneReq req = new TSSetTimeZoneReq(zoneId);
-    TSSetTimeZoneResp resp = client.setTimeZone(req);
+    TSRPCResp resp = client.setTimeZone(req);
     try {
       RpcUtils.verifySuccess(resp.getStatus());
     } catch (IoTDBRPCException e) {
diff --git a/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBQueryResultSet.java b/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBQueryResultSet.java
index a865a90..012c766 100644
--- a/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBQueryResultSet.java
+++ b/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBQueryResultSet.java
@@ -48,13 +48,7 @@ import java.util.List;
 import java.util.Map;
 import org.apache.iotdb.rpc.IoTDBRPCException;
 import org.apache.iotdb.rpc.RpcUtils;
-import org.apache.iotdb.service.rpc.thrift.TSCloseOperationReq;
-import org.apache.iotdb.service.rpc.thrift.TSCloseOperationResp;
-import org.apache.iotdb.service.rpc.thrift.TSFetchResultsReq;
-import org.apache.iotdb.service.rpc.thrift.TSFetchResultsResp;
-import org.apache.iotdb.service.rpc.thrift.TSIService;
-import org.apache.iotdb.service.rpc.thrift.TSOperationHandle;
-import org.apache.iotdb.service.rpc.thrift.TSQueryDataSet;
+import org.apache.iotdb.service.rpc.thrift.*;
 import org.apache.iotdb.tsfile.read.common.Field;
 import org.apache.iotdb.tsfile.read.common.RowRecord;
 import org.apache.thrift.TException;
@@ -215,7 +209,7 @@ public class IoTDBQueryResultSet implements ResultSet {
     try {
       if (operationHandle != null) {
         TSCloseOperationReq closeReq = new TSCloseOperationReq(operationHandle, queryId);
-        TSCloseOperationResp closeResp = client.closeOperation(closeReq);
+        TSRPCResp closeResp = client.closeOperation(closeReq);
         RpcUtils.verifySuccess(closeResp.getStatus());
       }
     } catch (IoTDBRPCException e) {
diff --git a/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBStatement.java b/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBStatement.java
index 680a0a3..b728831 100644
--- a/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBStatement.java
+++ b/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBStatement.java
@@ -124,7 +124,7 @@ public class IoTDBStatement implements Statement {
     try {
       if (operationHandle != null) {
         TSCancelOperationReq closeReq = new TSCancelOperationReq(operationHandle);
-        TSCancelOperationResp closeResp = client.cancelOperation(closeReq);
+        TSRPCResp closeResp = client.cancelOperation(closeReq);
         RpcUtils.verifySuccess(closeResp.getStatus());
       }
     } catch (Exception e) {
@@ -151,7 +151,7 @@ public class IoTDBStatement implements Statement {
       if (operationHandle != null) {
         TSCloseOperationReq closeReq = new TSCloseOperationReq(operationHandle, -1);
         closeReq.setStmtId(stmtId);
-        TSCloseOperationResp closeResp = client.closeOperation(closeReq);
+        TSRPCResp closeResp = client.closeOperation(closeReq);
         RpcUtils.verifySuccess(closeResp.getStatus());
       }
     } catch (Exception e) {
diff --git a/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBConnectionTest.java b/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBConnectionTest.java
index 36bc42b..5012e5e 100644
--- a/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBConnectionTest.java
+++ b/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBConnectionTest.java
@@ -56,7 +56,7 @@ public class IoTDBConnectionTest {
   public void testSetTimeZone() throws TException, IoTDBSQLException {
     String timeZone = "Asia/Shanghai";
     when(client.setTimeZone(any(TSSetTimeZoneReq.class)))
-        .thenReturn(new TSSetTimeZoneResp(Status_SUCCESS));
+        .thenReturn(new TSRPCResp(Status_SUCCESS));
     connection.client = client;
     connection.setTimeZone(timeZone);
     assertEquals(connection.getTimeZone(), timeZone);
diff --git a/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBPreparedStatementTest.java b/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBPreparedStatementTest.java
index f690de2..f8c2a94 100644
--- a/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBPreparedStatementTest.java
+++ b/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBPreparedStatementTest.java
@@ -41,7 +41,7 @@ public class IoTDBPreparedStatementTest {
   @Mock
   TSExecuteStatementResp execStatementResp;
   @Mock
-  TSGetOperationStatusResp getOperationStatusResp;
+  TSRPCResp getOperationStatusResp;
   private ZoneId zoneId = ZoneId.systemDefault();
   @Mock
   private IoTDBConnection connection;
diff --git a/jdbc/src/test/java/org/apache/iotdb/jdbc/demo/MetadataDemo.java b/jdbc/src/test/java/org/apache/iotdb/jdbc/demo/MetadataDemo.java
deleted file mode 100644
index 41c22d3..0000000
--- a/jdbc/src/test/java/org/apache/iotdb/jdbc/demo/MetadataDemo.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/**
- * 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.jdbc.demo;
-
-import java.sql.SQLException;
-
-public class MetadataDemo {
-
-  public static void main(String[] args) throws ClassNotFoundException, SQLException {
-    // Class.forName(TsfileJDBCConfig.JDBC_DRIVER_NAME);
-    // Connection connection = null;
-    // try {
-    // connection = DriverManager.getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root");
-    // DatabaseMetaData databaseMetaData = connection.getMetaData();
-    // } finally {
-    // connection.close();
-    // }
-  }
-
-}
\ No newline at end of file
diff --git a/server/src/main/java/org/apache/iotdb/db/qp/executor/QueryProcessExecutor.java b/server/src/main/java/org/apache/iotdb/db/qp/executor/QueryProcessExecutor.java
index 962cfec..a736915 100644
--- a/server/src/main/java/org/apache/iotdb/db/qp/executor/QueryProcessExecutor.java
+++ b/server/src/main/java/org/apache/iotdb/db/qp/executor/QueryProcessExecutor.java
@@ -377,7 +377,7 @@ public class QueryProcessExecutor extends AbstractQueryProcessExecutor {
             storageEngine.deleteAllDataFilesInOneStorageGroup(deleteStorageGroup);
           }
           break;
-        case SET_FILE_LEVEL:
+        case SET_STORAGE_GROUP:
           mManager.setStorageLevelToMTree(path.getFullPath());
           break;
         default:
diff --git a/server/src/main/java/org/apache/iotdb/db/qp/logical/sys/MetadataOperator.java b/server/src/main/java/org/apache/iotdb/db/qp/logical/sys/MetadataOperator.java
index 4f2c6bd..2a80f6b 100644
--- a/server/src/main/java/org/apache/iotdb/db/qp/logical/sys/MetadataOperator.java
+++ b/server/src/main/java/org/apache/iotdb/db/qp/logical/sys/MetadataOperator.java
@@ -46,7 +46,7 @@ public class MetadataOperator extends RootOperator {
     super(tokenIntType);
     namespaceType = type;
     switch (type) {
-      case SET_FILE_LEVEL:
+      case SET_STORAGE_GROUP:
         operatorType = OperatorType.SET_STORAGE_GROUP;
         break;
       case ADD_PATH:
@@ -113,7 +113,7 @@ public class MetadataOperator extends RootOperator {
   }
 
   public enum NamespaceType {
-    ADD_PATH, DELETE_PATH, SET_FILE_LEVEL;
+    ADD_PATH, DELETE_PATH, SET_STORAGE_GROUP;
 
     /**
      * deserialize short number.
@@ -128,7 +128,7 @@ public class MetadataOperator extends RootOperator {
         case 1:
           return DELETE_PATH;
         case 2:
-          return SET_FILE_LEVEL;
+          return SET_STORAGE_GROUP;
         default:
           return null;
       }
@@ -145,7 +145,7 @@ public class MetadataOperator extends RootOperator {
           return 0;
         case DELETE_PATH:
           return 1;
-        case SET_FILE_LEVEL:
+        case SET_STORAGE_GROUP:
           return 2;
         default:
           return -1;
diff --git a/server/src/main/java/org/apache/iotdb/db/qp/physical/sys/MetadataPlan.java b/server/src/main/java/org/apache/iotdb/db/qp/physical/sys/MetadataPlan.java
index 263ea53..cae6f63 100644
--- a/server/src/main/java/org/apache/iotdb/db/qp/physical/sys/MetadataPlan.java
+++ b/server/src/main/java/org/apache/iotdb/db/qp/physical/sys/MetadataPlan.java
@@ -55,19 +55,24 @@ public class MetadataPlan extends PhysicalPlan {
     this.encoding = encoding;
     this.props = props;
     this.deletePathList = deletePathList;
-    switch (namespaceType) {
-      case SET_FILE_LEVEL:
-        setOperatorType(Operator.OperatorType.SET_STORAGE_GROUP);
-        break;
-      case ADD_PATH:
-        setOperatorType(Operator.OperatorType.CREATE_TIMESERIES);
-        break;
-      case DELETE_PATH:
-        setOperatorType(Operator.OperatorType.DELETE_TIMESERIES);
-        break;
-      default:
-        break;
-    }
+    setOperatorType(namespaceType);
+  }
+
+  public MetadataPlan(MetadataOperator.NamespaceType namespaceType, Path path, TSDataType dataType,
+                      TSEncoding encoding) {
+    super(false, Operator.OperatorType.METADATA);
+    this.namespaceType = namespaceType;
+    this.path = path;
+    this.dataType = dataType;
+    this.encoding = encoding;
+    setOperatorType(namespaceType);
+  }
+
+  public MetadataPlan(MetadataOperator.NamespaceType namespaceType, Path path) {
+    super(false, Operator.OperatorType.METADATA);
+    this.namespaceType = namespaceType;
+    this.path = path;
+    setOperatorType(namespaceType);
   }
 
   public Path getPath() {
@@ -171,4 +176,20 @@ public class MetadataPlan extends PhysicalPlan {
         .hash(getNamespaceType(), getPath(), getDataType(), getCompressor(), getEncoding(),
             getProps(), getDeletePathList());
   }
+
+  private void setOperatorType(MetadataOperator.NamespaceType namespaceType) {
+    switch (namespaceType) {
+      case SET_STORAGE_GROUP:
+        setOperatorType(Operator.OperatorType.SET_STORAGE_GROUP);
+        break;
+      case ADD_PATH:
+        setOperatorType(Operator.OperatorType.CREATE_TIMESERIES);
+        break;
+      case DELETE_PATH:
+        setOperatorType(Operator.OperatorType.DELETE_TIMESERIES);
+        break;
+      default:
+        break;
+    }
+  }
 }
diff --git a/server/src/main/java/org/apache/iotdb/db/qp/strategy/LogicalGenerator.java b/server/src/main/java/org/apache/iotdb/db/qp/strategy/LogicalGenerator.java
index f83591d..fb288f7 100644
--- a/server/src/main/java/org/apache/iotdb/db/qp/strategy/LogicalGenerator.java
+++ b/server/src/main/java/org/apache/iotdb/db/qp/strategy/LogicalGenerator.java
@@ -425,7 +425,7 @@ public class LogicalGenerator {
   private void analyzeMetadataSetFileLevel(AstNode astNode) {
     MetadataOperator metadataOperator = new MetadataOperator(
         SQLConstant.TOK_METADATA_SET_FILE_LEVEL,
-        MetadataOperator.NamespaceType.SET_FILE_LEVEL);
+        MetadataOperator.NamespaceType.SET_STORAGE_GROUP);
     Path path = parsePath(astNode.getChild(0).getChild(0));
     metadataOperator.setPath(path);
     initializedOperator = metadataOperator;
diff --git a/server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java b/server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java
index 6d54f26..10cb8ea 100644
--- a/server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java
+++ b/server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java
@@ -38,10 +38,12 @@ import org.apache.iotdb.db.metadata.MManager;
 import org.apache.iotdb.db.metadata.Metadata;
 import org.apache.iotdb.db.qp.QueryProcessor;
 import org.apache.iotdb.db.qp.executor.QueryProcessExecutor;
+import org.apache.iotdb.db.qp.logical.sys.MetadataOperator;
 import org.apache.iotdb.db.qp.physical.PhysicalPlan;
 import org.apache.iotdb.db.qp.physical.crud.BatchInsertPlan;
 import org.apache.iotdb.db.qp.physical.crud.InsertPlan;
 import org.apache.iotdb.db.qp.physical.sys.AuthorPlan;
+import org.apache.iotdb.db.qp.physical.sys.MetadataPlan;
 import org.apache.iotdb.db.query.context.QueryContext;
 import org.apache.iotdb.db.query.control.QueryResourceManager;
 import org.apache.iotdb.db.utils.QueryDataSetUtils;
@@ -50,6 +52,7 @@ import org.apache.iotdb.service.rpc.thrift.*;
 import org.apache.iotdb.tsfile.common.constant.StatisticConstant;
 import org.apache.iotdb.tsfile.exception.filter.QueryFilterOptimizationException;
 import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
 import org.apache.iotdb.tsfile.read.common.Path;
 import org.apache.iotdb.tsfile.read.query.dataset.QueryDataSet;
 import org.apache.thrift.TException;
@@ -141,7 +144,7 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext {
   }
 
   @Override
-  public TSCloseSessionResp closeSession(TSCloseSessionReq req) {
+  public TSRPCResp closeSession(TSCloseSessionReq req) {
     logger.info("{}: receive close session", IoTDBConstant.GLOBAL_DB_NAME);
     TS_Status tsStatus;
     if (username.get() == null) {
@@ -156,16 +159,16 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext {
         zoneIds.remove();
       }
     }
-    return new TSCloseSessionResp(tsStatus);
+    return new TSRPCResp(tsStatus);
   }
 
   @Override
-  public TSCancelOperationResp cancelOperation(TSCancelOperationReq req) {
-    return new TSCancelOperationResp(getStatus(TSStatusType.SUCCESS_STATUS));
+  public TSRPCResp cancelOperation(TSCancelOperationReq req) {
+    return new TSRPCResp(getStatus(TSStatusType.SUCCESS_STATUS));
   }
 
   @Override
-  public TSCloseOperationResp closeOperation(TSCloseOperationReq req) {
+  public TSRPCResp closeOperation(TSCloseOperationReq req) {
     logger.info("{}: receive close operation", IoTDBConstant.GLOBAL_DB_NAME);
     try {
 
@@ -180,7 +183,7 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext {
     } catch (Exception e) {
       logger.error("Error in closeOperation : ", e);
     }
-    return new TSCloseOperationResp(getStatus(TSStatusType.SUCCESS_STATUS));
+    return new TSRPCResp(getStatus(TSStatusType.SUCCESS_STATUS));
   }
 
   private void releaseQueryResource(TSCloseOperationReq req) throws StorageEngineException {
@@ -782,29 +785,13 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext {
   }
 
   private TSExecuteStatementResp executeUpdateStatement(PhysicalPlan plan) {
-    List<Path> paths = plan.getPaths();
-    try {
-      if (!checkAuthorization(paths, plan)) {
-        return getTSExecuteStatementResp(getStatus(TSStatusType.NO_PERMISSION_ERROR, plan.getOperatorType().toString()));
-      }
-    } catch (AuthException e) {
-      logger.error("meet error while checking authorization.", e);
-      return getTSExecuteStatementResp(getStatus(TSStatusType.UNINITIALIZED_AUTH_ERROR, e.getMessage()));
-    }
-    // TODO
-    // In current version, we only return OK/ERROR
-    // Do we need to add extra information of executive condition
-    boolean execRet;
-    try {
-      execRet = executeNonQuery(plan);
-    } catch (ProcessorException e) {
-      logger.debug("meet error while processing non-query. ", e);
-      return getTSExecuteStatementResp(getStatus(TSStatusType.EXECUTE_STATEMENT_ERROR, e.getMessage()));
+    TS_Status status = checkAuthority(plan);
+    if (status != null) {
+      return new TSExecuteStatementResp(status);
     }
 
-    TSStatusType statusType = execRet ? TSStatusType.SUCCESS_STATUS : TSStatusType.EXECUTE_STATEMENT_ERROR;
-    String msg = execRet ? "Execute successfully" : "Execute statement error.";
-    TSExecuteStatementResp resp = getTSExecuteStatementResp(getStatus(statusType, msg));
+    status = executePlan(plan);
+    TSExecuteStatementResp resp = getTSExecuteStatementResp(status);
     TSHandleIdentifier operationId = new TSHandleIdentifier(
         ByteBuffer.wrap(username.get().getBytes()),
         ByteBuffer.wrap("PASS".getBytes()));
@@ -911,7 +898,7 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext {
   }
 
   @Override
-  public TSSetTimeZoneResp setTimeZone(TSSetTimeZoneReq req) {
+  public TSRPCResp setTimeZone(TSSetTimeZoneReq req) {
     TS_Status tsStatus;
     try {
       String timeZoneID = req.getTimeZone();
@@ -921,7 +908,7 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext {
       logger.error("meet error while setting time zone.", e);
       tsStatus = getStatus(TSStatusType.SET_TIME_ZONE_ERROR);
     }
-    return new TSSetTimeZoneResp(tsStatus);
+    return new TSRPCResp(tsStatus);
   }
 
   @Override
@@ -987,19 +974,10 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext {
       batchInsertPlan.setDataTypes(req.types);
 
       boolean isAllSuccessful = true;
-
-      List<Path> paths = batchInsertPlan.getPaths();
-      try {
-        if (!checkAuthorization(paths, batchInsertPlan)) {
-          return getTSBatchExecuteStatementResp(getStatus(TSStatusType.NO_PERMISSION_ERROR,
-              "No permissions for this operation " + batchInsertPlan.getOperatorType()), null);
-        }
-      } catch (AuthException e) {
-        logger.error("meet error while checking authorization.", e);
-        return getTSBatchExecuteStatementResp(getStatus(TSStatusType.UNINITIALIZED_AUTH_ERROR,
-            "Uninitialized authorizer " + e.getMessage()), null);
+      TS_Status status = checkAuthority(batchInsertPlan);
+      if (status != null) {
+        return new TSExecuteBatchStatementResp(status);
       }
-
       Integer[] results = processor.getExecutor().insertBatch(batchInsertPlan);
 
       for (Integer result : results) {
@@ -1025,8 +1003,67 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext {
   }
 
   @Override
+  public TSRPCResp setStorageGroup(TSSetStorageGroupReq req) throws TException {
+    if (!checkLogin()) {
+      logger.info(INFO_NOT_LOGIN, IoTDBConstant.GLOBAL_DB_NAME);
+      return new TSRPCResp(getStatus(TSStatusType.NOT_LOGIN_ERROR));
+    }
+
+    MetadataPlan plan = new MetadataPlan(MetadataOperator.NamespaceType.SET_STORAGE_GROUP, new Path(req.getStorageGroupId()));
+    TS_Status status = checkAuthority(plan);
+    if (status != null) {
+      return new TSRPCResp(status);
+    }
+    return new TSRPCResp(executePlan(plan));
+  }
+
+  @Override
+  public TSRPCResp createTimeseries(TSCreateTimeseriesReq req) throws TException {
+    if (!checkLogin()) {
+      logger.info(INFO_NOT_LOGIN, IoTDBConstant.GLOBAL_DB_NAME);
+      return new TSRPCResp(getStatus(TSStatusType.NOT_LOGIN_ERROR));
+    }
+    MetadataPlan plan = new MetadataPlan(MetadataOperator.NamespaceType.ADD_PATH, new Path(req.getPath()),
+            TSDataType.values()[req.getDataType()], TSEncoding.values()[req.getEncoding()]);
+    TS_Status status = checkAuthority(plan);
+    if (status != null) {
+      return new TSRPCResp(status);
+    }
+    return new TSRPCResp(executePlan(plan));
+  }
+
+  @Override
   public long requestStatementId() {
     return globalStmtId.incrementAndGet();
   }
+
+  private TS_Status checkAuthority(PhysicalPlan plan) {
+    List<Path> paths = plan.getPaths();
+    try {
+      if (!checkAuthorization(paths, plan)) {
+        return getStatus(TSStatusType.NO_PERMISSION_ERROR, plan.getOperatorType().toString());
+      }
+    } catch (AuthException e) {
+      logger.error("meet error while checking authorization.", e);
+      return getStatus(TSStatusType.UNINITIALIZED_AUTH_ERROR, e.getMessage());
+    }
+    return null;
+  }
+
+  private TS_Status executePlan(PhysicalPlan plan) {
+    // TODO
+    // In current version, we only return OK/ERROR
+    // Do we need to add extra information of executive condition
+    boolean execRet;
+    try {
+      execRet = executeNonQuery(plan);
+    } catch (ProcessorException e) {
+      logger.debug("meet error while processing non-query. ", e);
+      return getStatus(TSStatusType.EXECUTE_STATEMENT_ERROR, e.getMessage());
+    }
+
+    return execRet ? getStatus(TSStatusType.SUCCESS_STATUS, "Execute successfully")
+            : getStatus(TSStatusType.EXECUTE_STATEMENT_ERROR);
+  }
 }
 
diff --git a/service-rpc/src/main/thrift/rpc.thrift b/service-rpc/src/main/thrift/rpc.thrift
index 13aae09..6eee9c1 100644
--- a/service-rpc/src/main/thrift/rpc.thrift
+++ b/service-rpc/src/main/thrift/rpc.thrift
@@ -100,10 +100,6 @@ struct TSOpenSessionReq {
   4: optional map<string, string> configuration
 }
 
-struct TSCloseSessionResp {
-  1: required TS_Status status
-}
-
 // CloseSession()
 // Closes the specified session and frees any resources currently allocated to that session. 
 // Any open operations in that session will be canceled.
@@ -145,10 +141,6 @@ struct TSGetOperationStatusReq {
   1: required TSOperationHandle operationHandle
 }
 
-struct TSGetOperationStatusResp {
-  1: required TS_Status status
-}
-
 // CancelOperation()
 //
 // Cancels processing on the specified operation handle and frees any resources which were allocated.
@@ -157,11 +149,6 @@ struct TSCancelOperationReq {
   1: required TSOperationHandle operationHandle
 }
 
-struct TSCancelOperationResp {
-  1: required TS_Status status
-}
-
-
 // CloseOperation()
 struct TSCloseOperationReq {
   1: required TSOperationHandle operationHandle
@@ -169,11 +156,6 @@ struct TSCloseOperationReq {
   3: optional i64 stmtId
 }
 
-struct TSCloseOperationResp {
-  1: required TS_Status status
-}
-
-
 struct TSDataValue{
   1: required bool is_empty
   2: optional bool bool_val
@@ -237,10 +219,6 @@ struct TSSetTimeZoneReq {
     1: required string timeZone
 }
 
-struct TSSetTimeZoneResp {
-    1: required TS_Status status
-}
-
 struct TSInsertionReq {
     1: optional string deviceId
     2: optional list<string> measurements
@@ -258,6 +236,20 @@ struct TSBatchInsertionReq {
     6: required i32 size
 }
 
+struct TSSetStorageGroupReq {
+  1: required string storageGroupId
+}
+
+struct TSRPCResp {
+  1: required TS_Status status
+}
+
+struct TSCreateTimeseriesReq {
+  1: required string path
+  2: required i32 dataType
+  3: required i32 encoding
+}
+
 struct ServerProperties {
 	1: required string version;
 	2: required list<string> supportedTimeAggregationOperations;
@@ -267,7 +259,7 @@ struct ServerProperties {
 service TSIService {
 	TSOpenSessionResp openSession(1:TSOpenSessionReq req);
 
-	TSCloseSessionResp closeSession(1:TSCloseSessionReq req);
+	TSRPCResp closeSession(1:TSCloseSessionReq req);
 
 	TSExecuteStatementResp executeStatement(1:TSExecuteStatementReq req);
 
@@ -281,13 +273,13 @@ service TSIService {
 
 	TSFetchMetadataResp fetchMetadata(1:TSFetchMetadataReq req)
 
-	TSCancelOperationResp cancelOperation(1:TSCancelOperationReq req);
+	TSRPCResp cancelOperation(1:TSCancelOperationReq req);
 
-	TSCloseOperationResp closeOperation(1:TSCloseOperationReq req);
+	TSRPCResp closeOperation(1:TSCloseOperationReq req);
 
 	TSGetTimeZoneResp getTimeZone();
 
-	TSSetTimeZoneResp setTimeZone(1:TSSetTimeZoneReq req);
+	TSRPCResp setTimeZone(1:TSSetTimeZoneReq req);
 	
 	ServerProperties getProperties();
 
@@ -295,5 +287,9 @@ service TSIService {
 
 	TSExecuteBatchStatementResp insertBatch(1:TSBatchInsertionReq req);
 
+	TSRPCResp setStorageGroup(1:TSSetStorageGroupReq req);
+
+	TSRPCResp createTimeseries(1:TSCreateTimeseriesReq req);
+
 	i64 requestStatementId();
 	}
diff --git a/session/src/main/java/org/apache/iotdb/session/Session.java b/session/src/main/java/org/apache/iotdb/session/Session.java
index e7d71ad..0b13c58 100644
--- a/session/src/main/java/org/apache/iotdb/session/Session.java
+++ b/session/src/main/java/org/apache/iotdb/session/Session.java
@@ -18,20 +18,11 @@
  */
 package org.apache.iotdb.session;
 
-import java.time.ZoneId;
 import org.apache.iotdb.rpc.IoTDBRPCException;
 import org.apache.iotdb.rpc.RpcUtils;
-import org.apache.iotdb.service.rpc.thrift.TSBatchInsertionReq;
-import org.apache.iotdb.service.rpc.thrift.TSCloseSessionReq;
-import org.apache.iotdb.service.rpc.thrift.TSExecuteBatchStatementResp;
-import org.apache.iotdb.service.rpc.thrift.TSGetTimeZoneResp;
-import org.apache.iotdb.service.rpc.thrift.TSIService;
-import org.apache.iotdb.service.rpc.thrift.TSOpenSessionReq;
-import org.apache.iotdb.service.rpc.thrift.TSOpenSessionResp;
-import org.apache.iotdb.service.rpc.thrift.TSProtocolVersion;
-import org.apache.iotdb.service.rpc.thrift.TSSetTimeZoneReq;
-import org.apache.iotdb.service.rpc.thrift.TSSetTimeZoneResp;
-import org.apache.iotdb.service.rpc.thrift.TS_SessionHandle;
+import org.apache.iotdb.service.rpc.thrift.*;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
 import org.apache.iotdb.tsfile.write.record.RowBatch;
 import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
 import org.apache.thrift.TException;
@@ -42,9 +33,10 @@ import org.apache.thrift.transport.TTransportException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.time.ZoneId;
+
 public class Session {
 
-  private static final Logger logger = LoggerFactory.getLogger(Session.class);
   private String host;
   private int port;
   private String username;
@@ -163,6 +155,30 @@ public class Session {
     }
   }
 
+  public TSRPCResp setStorageGroup(String storageGroupId) throws IoTDBSessionException {
+    TSSetStorageGroupReq request = new TSSetStorageGroupReq();
+    request.setStorageGroupId(storageGroupId);
+
+    try {
+      return client.setStorageGroup(request);
+    } catch (TException e) {
+      throw new IoTDBSessionException(e);
+    }
+  }
+
+  public TSRPCResp createTimeseries(String path, TSDataType dataType, TSEncoding encoding) throws IoTDBSessionException {
+    TSCreateTimeseriesReq request = new TSCreateTimeseriesReq();
+    request.setPath(path);
+    request.setDataType(dataType.ordinal());
+    request.setEncoding(encoding.ordinal());
+
+    try {
+      return client.createTimeseries(request);
+    } catch (TException e) {
+      throw new IoTDBSessionException(e);
+    }
+  }
+
   public String getTimeZone() throws TException, IoTDBRPCException {
     if (zoneId != null) {
       return zoneId.toString();
@@ -175,7 +191,7 @@ public class Session {
 
   public void setTimeZone(String zoneId) throws TException, IoTDBRPCException {
     TSSetTimeZoneReq req = new TSSetTimeZoneReq(zoneId);
-    TSSetTimeZoneResp resp = client.setTimeZone(req);
+    TSRPCResp resp = client.setTimeZone(req);
     RpcUtils.verifySuccess(resp.getStatus());
     this.zoneId = ZoneId.of(zoneId);
   }