You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by GitBox <gi...@apache.org> on 2022/10/14 17:56:22 UTC

[GitHub] [iotdb] ycycse opened a new pull request, #7613: [IOTDB-3936]Add an interface in IClientRPCService to directly return bytebuffer instead of TSQueryDataSet

ycycse opened a new pull request, #7613:
URL: https://github.com/apache/iotdb/pull/7613

   ## 概述
   在查询的过程中客户端会调用服务端的executeStatement()方法并获得对应的返回值,该方法中会将查询得到的TsBlock转为TSQueryDataSet类型。然而这个过程涉及服务端上TsBlock的反序列化和TSQueryDataSet的序列化,会占用服务端的一定资源并增加了响应时间。
   
   针对该问题,我们可以添加一个新的接口,将查询到的序列化TsBlock以ByteBuffer的形式直接返回,反序列化以及数据处理在客户端进行。该接口节省了服务端TsBlock反序列化和TSQueryDataset序列化的资源消耗,提供更加高效的查询。
   
   为了支持该接口,需要对服务端和客户端进行修改,这里的客户端修改只涉及session,不涉及jdbc
   ### Server端 
   server端的修改可以分为以下几个部分
   1. 增加对应的接口方法,包括executeStatementV2,executeRawDataQueryV2,executeLastDataQueryV2,executeQueryStatementV2,executeUpdateStatementV2作为供客户端调用的新接口。
   2. 对ISourceHandle的实现方法进行修改,添加方法getSerializedTsBlock()获得bytebuffer类型返回值。需要提到的是,SourceHandle实现类返回bytebuffer可以省略掉反序列化过程,因为查询结果就是bytebuffer,是优化的主要目标;但是LocalSourceHandle存储的形式是TsBlock,需要对其序列化。后续性能测试中证明了添加了一个TsBlock序列化减少了一个QueryDataset反序列化的LocalSourceHadle系列调用保持了原有的性能。
   3. 在QueryExecution增加方法getByteBufferBatchResult用于对ISourceHandle的实现类进行一个调用
   4. 由于一次调用不能取出所有数据,且ByteBuffer本身不适合融合,因此在ClientRPCServiceImpl中实现了一个方法convertQueryResultByFetchSize用于多次调用getByteBufferBatchResult知道获得足够的数据并将结果以List<ByteBuffer>的形式融合并返回
   ### Session端 
   session端主要是对返回的List<ByteBuffer>进行适配,使得客户端能够通过SessionDataset对数据进行遍历,涉及了SessionDataset和IoTDBRpcDataSet的修改。
   session端适配List<ByteBuffer>的主要思路是,每次取出一份ByteBuffer将其反序列化为TsBlock,当该TsBlock中包含的行被读完后,再取出新的ByteBuffer进行反序列化,也就是边用边反序列化
   <!--
   In each section, please describe design decisions made, including:
    - Choice of algorithms
    - Behavioral aspects. What configuration values are acceptable? How are corner cases and error 
       conditions handled, such as when there are insufficient resources?
    - Class organization and design (how the logic is split between classes, inheritance, composition, 
       design patterns)
    - Method organization and design (how the logic is split between methods, parameters and return types)
    - Naming (class, method, API, configuration, HTTP endpoint, names of emitted metrics)
   -->
   
   
   <!-- It's good to describe an alternative design (or mention an alternative name) for every design 
   (or naming) decision point and compare the alternatives with the designs that you've implemented 
   (or the names you've chosen) to highlight the advantages of the chosen designs and names. -->
   
   <!-- If there was a discussion of the design of the feature implemented in this PR elsewhere 
   (e. g. a "Proposal" issue, any other issue, or a thread in the development mailing list), 
   link to that discussion from this PR description and explain what have changed in your final design 
   compared to your original proposal or the consensus version in the end of the discussion. 
   If something hasn't changed since the original discussion, you can omit a detailed discussion of 
   those aspects of the design here, perhaps apart from brief mentioning for the sake of readability 
   of this PR description. -->
   
   <!-- Some of the aspects mentioned above may be omitted for simple and small changes. -->
   
   <hr>
   
   This PR has:
   - [x] added unit tests or modified existing tests to cover new code paths, ensuring the threshold 
     for code coverage.
   - [ ] been tested in a test IoTDB cluster.
   
   <!-- Check the items by putting "x" in the brackets for the done things. Not all of these items 
   apply to every PR. Remove the items which are not done or not relevant to the PR. None of the items 
   from the checklist above are strictly necessary, but it would be very helpful if you at least 
   self-review the PR. -->
   
   <hr>
   
   ##### Key changed/added classes (or packages if there are too many classes) in this PR
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] HTHou commented on a diff in pull request #7613: [IOTDB-3936]Add an interface in IClientRPCService to directly return bytebuffer instead of TSQueryDataSet

Posted by GitBox <gi...@apache.org>.
HTHou commented on code in PR #7613:
URL: https://github.com/apache/iotdb/pull/7613#discussion_r996654089


##########
session/src/test/java/org/apache/iotdb/session/SessionDatasetTest.java:
##########
@@ -0,0 +1,221 @@
+package org.apache.iotdb.session;

Review Comment:
    Don't forget Apache License header.
   ```suggestion
   /*
    * 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.session;
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] ycycse commented on a diff in pull request #7613: [IOTDB-3936]Add an interface in IClientRPCService to directly return bytebuffer instead of TSQueryDataSet

Posted by GitBox <gi...@apache.org>.
ycycse commented on code in PR #7613:
URL: https://github.com/apache/iotdb/pull/7613#discussion_r996681884


##########
session/src/test/java/org/apache/iotdb/session/SessionDatasetTest.java:
##########
@@ -0,0 +1,221 @@
+package org.apache.iotdb.session;

Review Comment:
   Thanks! I will fix it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] JackieTien97 commented on a diff in pull request #7613: [IOTDB-3936]Add an interface in IClientRPCService to directly return bytebuffer instead of TSQueryDataSet

Posted by GitBox <gi...@apache.org>.
JackieTien97 commented on code in PR #7613:
URL: https://github.com/apache/iotdb/pull/7613#discussion_r1004372591


##########
jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBJDBCResultSetTest.java:
##########
@@ -125,15 +128,17 @@ public void before() throws Exception {
 
     execResp.queryDataSet = FakedFirstFetchResult();

Review Comment:
   ```suggestion
   ```



##########
jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBJDBCResultSet.java:
##########
@@ -20,18 +20,48 @@
 package org.apache.iotdb.jdbc;
 
 import org.apache.iotdb.rpc.IoTDBConnectionException;
+import org.apache.iotdb.rpc.IoTDBRpcDataSet;
 import org.apache.iotdb.rpc.StatementExecutionException;
 import org.apache.iotdb.service.rpc.thrift.IClientRPCService;
-import org.apache.iotdb.service.rpc.thrift.TSQueryDataSet;
 import org.apache.iotdb.service.rpc.thrift.TSTracingInfo;
 
+import org.apache.thrift.TException;
+
+import java.io.InputStream;
+import java.io.Reader;
+import java.math.BigDecimal;
+import java.math.MathContext;
+import java.net.URL;
+import java.nio.ByteBuffer;
+import java.sql.Array;
+import java.sql.Blob;
+import java.sql.Clob;
+import java.sql.Date;
+import java.sql.NClob;
+import java.sql.Ref;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.RowId;
 import java.sql.SQLException;
+import java.sql.SQLWarning;
+import java.sql.SQLXML;
 import java.sql.Statement;
+import java.sql.Time;
+import java.sql.Timestamp;
 import java.util.BitSet;
+import java.util.Calendar;
 import java.util.List;
 import java.util.Map;
 
 public class IoTDBJDBCResultSet extends AbstractIoTDBJDBCResultSet {
+
+  protected Statement statement;
+  protected SQLWarning warningChain = null;
+  protected List<String> columnTypeList;
+  protected IoTDBRpcDataSet ioTDBRpcDataSet;
+  protected IoTDBTracingInfo ioTDBRpcTracingInfo;
+  private boolean isRpcFetchResult = true;
+  private BitSet aliasColumnMap;

Review Comment:
   ```suggestion
   ```



##########
jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBJDBCResultSet.java:
##########
@@ -87,85 +126,1178 @@ public IoTDBJDBCResultSet(
       String sql,
       long queryId,
       long sessionId,
-      TSQueryDataSet dataset,
+      List<ByteBuffer> dataSet,
       TSTracingInfo tracingInfo,
       long timeout,
       boolean isRpcFetchResult)
       throws SQLException {
-    super(
-        statement,
-        columnNameList,
-        columnTypeList,
-        columnNameIndex,
-        ignoreTimeStamp,
-        client,
-        sql,
-        queryId,
-        sessionId,
-        timeout,
-        isRpcFetchResult);
-    ioTDBRpcDataSet.setTsQueryDataSet(dataset);
+    this.ioTDBRpcDataSet =
+        new IoTDBRpcDataSet(
+            sql,
+            columnNameList,
+            columnTypeList,
+            columnNameIndex,
+            ignoreTimeStamp,
+            queryId,
+            ((IoTDBStatement) statement).getStmtId(),
+            client,
+            sessionId,
+            dataSet,
+            statement.getFetchSize(),
+            timeout);
+    this.statement = statement;
+    this.columnTypeList = columnTypeList;
+    this.isRpcFetchResult = isRpcFetchResult;
     if (tracingInfo != null) {
       ioTDBRpcTracingInfo = new IoTDBTracingInfo();
       ioTDBRpcTracingInfo.setTsTracingInfo(tracingInfo);
     }
   }
 
   @Override
-  public long getLong(String columnName) throws SQLException {
+  public boolean isWrapperFor(Class<?> iface) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public <T> T unwrap(Class<T> iface) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public boolean absolute(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void afterLast() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void beforeFirst() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void cancelRowUpdates() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void clearWarnings() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void close() throws SQLException {
     try {
-      return ioTDBRpcDataSet.getLong(columnName);
+      ioTDBRpcDataSet.close();
+    } catch (StatementExecutionException e) {
+      throw new SQLException("Error occurs for close operation in server side because ", e);
+    } catch (TException e) {
+      throw new SQLException("Error occurs when connecting to server for close operation ", e);
+    }
+  }
+
+  @Override
+  public void deleteRow() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public int findColumn(String columnName) {
+    return ioTDBRpcDataSet.findColumn(columnName);
+  }
+
+  @Override
+  public boolean first() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Array getArray(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Array getArray(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public InputStream getAsciiStream(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public InputStream getAsciiStream(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public BigDecimal getBigDecimal(int columnIndex) throws SQLException {
+    try {
+      return getBigDecimal(ioTDBRpcDataSet.findColumnNameByIndex(columnIndex));
+    } catch (StatementExecutionException e) {
+      throw new SQLException(e.getMessage());
+    }
+  }
+
+  @Override
+  public BigDecimal getBigDecimal(String columnName) throws SQLException {
+    String value = getValueByName(columnName);
+    if (value != null) {
+      return new BigDecimal(value);
+    } else {
+      return null;
+    }
+  }
+
+  @Override
+  public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException {
+    MathContext mc = new MathContext(scale);
+    return getBigDecimal(columnIndex).round(mc);
+  }
+
+  @Override
+  public BigDecimal getBigDecimal(String columnName, int scale) throws SQLException {
+    return getBigDecimal(findColumn(columnName), scale);
+  }
+
+  @Override
+  public InputStream getBinaryStream(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public InputStream getBinaryStream(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Blob getBlob(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Blob getBlob(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public boolean getBoolean(int columnIndex) throws SQLException {
+    try {
+      return getBoolean(ioTDBRpcDataSet.findColumnNameByIndex(columnIndex));

Review Comment:
   ```suggestion
         return ioTDBRpcDataSet.getBoolean(columnIndex);
   ```
   same as all the others types' get method.



##########
jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBJDBCResultSet.java:
##########
@@ -20,18 +20,48 @@
 package org.apache.iotdb.jdbc;
 
 import org.apache.iotdb.rpc.IoTDBConnectionException;
+import org.apache.iotdb.rpc.IoTDBRpcDataSet;
 import org.apache.iotdb.rpc.StatementExecutionException;
 import org.apache.iotdb.service.rpc.thrift.IClientRPCService;
-import org.apache.iotdb.service.rpc.thrift.TSQueryDataSet;
 import org.apache.iotdb.service.rpc.thrift.TSTracingInfo;
 
+import org.apache.thrift.TException;
+
+import java.io.InputStream;
+import java.io.Reader;
+import java.math.BigDecimal;
+import java.math.MathContext;
+import java.net.URL;
+import java.nio.ByteBuffer;
+import java.sql.Array;
+import java.sql.Blob;
+import java.sql.Clob;
+import java.sql.Date;
+import java.sql.NClob;
+import java.sql.Ref;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.RowId;
 import java.sql.SQLException;
+import java.sql.SQLWarning;
+import java.sql.SQLXML;
 import java.sql.Statement;
+import java.sql.Time;
+import java.sql.Timestamp;
 import java.util.BitSet;
+import java.util.Calendar;
 import java.util.List;
 import java.util.Map;
 
 public class IoTDBJDBCResultSet extends AbstractIoTDBJDBCResultSet {

Review Comment:
   ```suggestion
   public class IoTDBJDBCResultSet implements ResultSet {
   ```



##########
jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBJDBCResultSet.java:
##########
@@ -87,85 +126,1178 @@ public IoTDBJDBCResultSet(
       String sql,
       long queryId,
       long sessionId,
-      TSQueryDataSet dataset,
+      List<ByteBuffer> dataSet,
       TSTracingInfo tracingInfo,
       long timeout,
       boolean isRpcFetchResult)
       throws SQLException {
-    super(
-        statement,
-        columnNameList,
-        columnTypeList,
-        columnNameIndex,
-        ignoreTimeStamp,
-        client,
-        sql,
-        queryId,
-        sessionId,
-        timeout,
-        isRpcFetchResult);
-    ioTDBRpcDataSet.setTsQueryDataSet(dataset);
+    this.ioTDBRpcDataSet =
+        new IoTDBRpcDataSet(
+            sql,
+            columnNameList,
+            columnTypeList,
+            columnNameIndex,
+            ignoreTimeStamp,
+            queryId,
+            ((IoTDBStatement) statement).getStmtId(),
+            client,
+            sessionId,
+            dataSet,
+            statement.getFetchSize(),
+            timeout);
+    this.statement = statement;
+    this.columnTypeList = columnTypeList;
+    this.isRpcFetchResult = isRpcFetchResult;
     if (tracingInfo != null) {
       ioTDBRpcTracingInfo = new IoTDBTracingInfo();
       ioTDBRpcTracingInfo.setTsTracingInfo(tracingInfo);
     }
   }
 
   @Override
-  public long getLong(String columnName) throws SQLException {
+  public boolean isWrapperFor(Class<?> iface) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public <T> T unwrap(Class<T> iface) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public boolean absolute(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void afterLast() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void beforeFirst() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void cancelRowUpdates() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void clearWarnings() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void close() throws SQLException {
     try {
-      return ioTDBRpcDataSet.getLong(columnName);
+      ioTDBRpcDataSet.close();
+    } catch (StatementExecutionException e) {
+      throw new SQLException("Error occurs for close operation in server side because ", e);
+    } catch (TException e) {
+      throw new SQLException("Error occurs when connecting to server for close operation ", e);
+    }
+  }
+
+  @Override
+  public void deleteRow() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public int findColumn(String columnName) {
+    return ioTDBRpcDataSet.findColumn(columnName);
+  }
+
+  @Override
+  public boolean first() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Array getArray(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Array getArray(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public InputStream getAsciiStream(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public InputStream getAsciiStream(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public BigDecimal getBigDecimal(int columnIndex) throws SQLException {
+    try {
+      return getBigDecimal(ioTDBRpcDataSet.findColumnNameByIndex(columnIndex));
+    } catch (StatementExecutionException e) {
+      throw new SQLException(e.getMessage());
+    }
+  }
+
+  @Override
+  public BigDecimal getBigDecimal(String columnName) throws SQLException {
+    String value = getValueByName(columnName);
+    if (value != null) {
+      return new BigDecimal(value);
+    } else {
+      return null;
+    }
+  }
+
+  @Override
+  public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException {
+    MathContext mc = new MathContext(scale);
+    return getBigDecimal(columnIndex).round(mc);
+  }
+
+  @Override
+  public BigDecimal getBigDecimal(String columnName, int scale) throws SQLException {
+    return getBigDecimal(findColumn(columnName), scale);
+  }
+
+  @Override
+  public InputStream getBinaryStream(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public InputStream getBinaryStream(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Blob getBlob(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Blob getBlob(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public boolean getBoolean(int columnIndex) throws SQLException {
+    try {
+      return getBoolean(ioTDBRpcDataSet.findColumnNameByIndex(columnIndex));
     } catch (StatementExecutionException e) {
       throw new SQLException(e.getMessage());
     }
   }
 
   @Override
-  protected boolean fetchResults() throws SQLException {
+  public boolean getBoolean(String columnName) throws SQLException {
     try {
-      return ioTDBRpcDataSet.fetchResults();
-    } catch (StatementExecutionException | IoTDBConnectionException e) {
+      return ioTDBRpcDataSet.getBoolean(columnName);
+    } catch (StatementExecutionException e) {
       throw new SQLException(e.getMessage());
     }
   }
 
   @Override
-  protected boolean hasCachedResults() {
-    return ioTDBRpcDataSet.hasCachedResults();
+  public byte getByte(int columnIndex) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
   }
 
   @Override
-  protected void constructOneRow() {
-    ioTDBRpcDataSet.constructOneRow();
+  public byte getByte(String columnName) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
   }
 
   @Override
-  protected void checkRecord() throws SQLException {
+  public byte[] getBytes(int columnIndex) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public byte[] getBytes(String columnName) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Reader getCharacterStream(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Reader getCharacterStream(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Clob getClob(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Clob getClob(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public int getConcurrency() {
+    return ResultSet.CONCUR_READ_ONLY;
+  }
+
+  @Override
+  public String getCursorName() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Date getDate(int columnIndex) throws SQLException {
+    return new Date(getLong(columnIndex));
+  }
+
+  @Override
+  public Date getDate(String columnName) throws SQLException {
+    return getDate(findColumn(columnName));
+  }
+
+  @Override
+  public Date getDate(int arg0, Calendar arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Date getDate(String arg0, Calendar arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public double getDouble(int columnIndex) throws SQLException {
     try {
-      ioTDBRpcDataSet.checkRecord();
+      return getDouble(ioTDBRpcDataSet.findColumnNameByIndex(columnIndex));
     } catch (StatementExecutionException e) {
       throw new SQLException(e.getMessage());
     }
   }
 
   @Override
-  protected String getValueByName(String columnName) throws SQLException {
+  public double getDouble(String columnName) throws SQLException {
     try {
-      return ioTDBRpcDataSet.getValueByName(columnName);
+      return ioTDBRpcDataSet.getDouble(columnName);
     } catch (StatementExecutionException e) {
       throw new SQLException(e.getMessage());
     }
   }
 
   @Override
-  protected Object getObjectByName(String columnName) throws SQLException {
+  public int getFetchDirection() {
+    return ResultSet.FETCH_FORWARD;
+  }
+
+  @Override
+  public void setFetchDirection(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public int getFetchSize() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void setFetchSize(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public float getFloat(int columnIndex) throws SQLException {
     try {
-      return ioTDBRpcDataSet.getObjectByName(columnName);
+      return getFloat(ioTDBRpcDataSet.findColumnNameByIndex(columnIndex));
+    } catch (StatementExecutionException e) {
+      throw new SQLException(e.getMessage());
+    }
+  }
+
+  @Override
+  public float getFloat(String columnName) throws SQLException {
+    try {
+      return ioTDBRpcDataSet.getFloat(columnName);
+    } catch (StatementExecutionException e) {
+      throw new SQLException(e.getMessage());
+    }
+  }
+
+  @Override
+  public int getHoldability() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public int getInt(int columnIndex) throws SQLException {
+    try {
+      return getInt(ioTDBRpcDataSet.findColumnNameByIndex(columnIndex));
+    } catch (StatementExecutionException e) {
+      throw new SQLException(e.getMessage());
+    }
+  }
+
+  @Override
+  public int getInt(String columnName) throws SQLException {
+    try {
+      return ioTDBRpcDataSet.getInt(columnName);
+    } catch (StatementExecutionException e) {
+      throw new SQLException(e.getMessage());
+    }
+  }
+
+  @Override
+  public long getLong(int columnIndex) throws SQLException {
+    try {
+      return getLong(ioTDBRpcDataSet.findColumnNameByIndex(columnIndex));
+    } catch (StatementExecutionException e) {
+      throw new SQLException(e.getMessage());
+    }
+  }
+
+  @Override
+  public long getLong(String columnName) throws SQLException {
+    try {
+      return ioTDBRpcDataSet.getLong(columnName);
+    } catch (StatementExecutionException e) {
+      throw new SQLException(e.getMessage());
+    }
+  }
+
+  @Override
+  public ResultSetMetaData getMetaData() {
+    String operationType = "";
+    boolean nonAlign = false;
+    try {
+      if (statement.getResultSet() instanceof IoTDBJDBCResultSet) {
+        operationType = ((IoTDBJDBCResultSet) statement.getResultSet()).getOperationType();
+        this.sgColumns = ((IoTDBJDBCResultSet) statement.getResultSet()).getSgColumns();

Review Comment:
   must be this if branch, no need to do this if-else-if judgement.



##########
jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBJDBCResultSet.java:
##########
@@ -87,85 +126,1178 @@ public IoTDBJDBCResultSet(
       String sql,
       long queryId,
       long sessionId,
-      TSQueryDataSet dataset,
+      List<ByteBuffer> dataSet,
       TSTracingInfo tracingInfo,
       long timeout,
       boolean isRpcFetchResult)
       throws SQLException {
-    super(
-        statement,
-        columnNameList,
-        columnTypeList,
-        columnNameIndex,
-        ignoreTimeStamp,
-        client,
-        sql,
-        queryId,
-        sessionId,
-        timeout,
-        isRpcFetchResult);
-    ioTDBRpcDataSet.setTsQueryDataSet(dataset);
+    this.ioTDBRpcDataSet =
+        new IoTDBRpcDataSet(
+            sql,
+            columnNameList,
+            columnTypeList,
+            columnNameIndex,
+            ignoreTimeStamp,
+            queryId,
+            ((IoTDBStatement) statement).getStmtId(),
+            client,
+            sessionId,
+            dataSet,
+            statement.getFetchSize(),
+            timeout);
+    this.statement = statement;
+    this.columnTypeList = columnTypeList;
+    this.isRpcFetchResult = isRpcFetchResult;
     if (tracingInfo != null) {
       ioTDBRpcTracingInfo = new IoTDBTracingInfo();
       ioTDBRpcTracingInfo.setTsTracingInfo(tracingInfo);
     }
   }
 
   @Override
-  public long getLong(String columnName) throws SQLException {
+  public boolean isWrapperFor(Class<?> iface) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public <T> T unwrap(Class<T> iface) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public boolean absolute(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void afterLast() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void beforeFirst() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void cancelRowUpdates() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void clearWarnings() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void close() throws SQLException {
     try {
-      return ioTDBRpcDataSet.getLong(columnName);
+      ioTDBRpcDataSet.close();
+    } catch (StatementExecutionException e) {
+      throw new SQLException("Error occurs for close operation in server side because ", e);
+    } catch (TException e) {
+      throw new SQLException("Error occurs when connecting to server for close operation ", e);
+    }
+  }
+
+  @Override
+  public void deleteRow() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public int findColumn(String columnName) {
+    return ioTDBRpcDataSet.findColumn(columnName);
+  }
+
+  @Override
+  public boolean first() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Array getArray(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Array getArray(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public InputStream getAsciiStream(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public InputStream getAsciiStream(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public BigDecimal getBigDecimal(int columnIndex) throws SQLException {
+    try {
+      return getBigDecimal(ioTDBRpcDataSet.findColumnNameByIndex(columnIndex));
+    } catch (StatementExecutionException e) {
+      throw new SQLException(e.getMessage());
+    }
+  }
+
+  @Override
+  public BigDecimal getBigDecimal(String columnName) throws SQLException {
+    String value = getValueByName(columnName);
+    if (value != null) {
+      return new BigDecimal(value);
+    } else {
+      return null;
+    }
+  }
+
+  @Override
+  public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException {
+    MathContext mc = new MathContext(scale);
+    return getBigDecimal(columnIndex).round(mc);
+  }
+
+  @Override
+  public BigDecimal getBigDecimal(String columnName, int scale) throws SQLException {
+    return getBigDecimal(findColumn(columnName), scale);
+  }
+
+  @Override
+  public InputStream getBinaryStream(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public InputStream getBinaryStream(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Blob getBlob(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Blob getBlob(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public boolean getBoolean(int columnIndex) throws SQLException {
+    try {
+      return getBoolean(ioTDBRpcDataSet.findColumnNameByIndex(columnIndex));
     } catch (StatementExecutionException e) {
       throw new SQLException(e.getMessage());
     }
   }
 
   @Override
-  protected boolean fetchResults() throws SQLException {
+  public boolean getBoolean(String columnName) throws SQLException {
     try {
-      return ioTDBRpcDataSet.fetchResults();
-    } catch (StatementExecutionException | IoTDBConnectionException e) {
+      return ioTDBRpcDataSet.getBoolean(columnName);
+    } catch (StatementExecutionException e) {
       throw new SQLException(e.getMessage());
     }
   }
 
   @Override
-  protected boolean hasCachedResults() {
-    return ioTDBRpcDataSet.hasCachedResults();
+  public byte getByte(int columnIndex) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
   }
 
   @Override
-  protected void constructOneRow() {
-    ioTDBRpcDataSet.constructOneRow();
+  public byte getByte(String columnName) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
   }
 
   @Override
-  protected void checkRecord() throws SQLException {
+  public byte[] getBytes(int columnIndex) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public byte[] getBytes(String columnName) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Reader getCharacterStream(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Reader getCharacterStream(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Clob getClob(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Clob getClob(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public int getConcurrency() {
+    return ResultSet.CONCUR_READ_ONLY;
+  }
+
+  @Override
+  public String getCursorName() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Date getDate(int columnIndex) throws SQLException {
+    return new Date(getLong(columnIndex));
+  }
+
+  @Override
+  public Date getDate(String columnName) throws SQLException {
+    return getDate(findColumn(columnName));
+  }
+
+  @Override
+  public Date getDate(int arg0, Calendar arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Date getDate(String arg0, Calendar arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public double getDouble(int columnIndex) throws SQLException {
     try {
-      ioTDBRpcDataSet.checkRecord();
+      return getDouble(ioTDBRpcDataSet.findColumnNameByIndex(columnIndex));
     } catch (StatementExecutionException e) {
       throw new SQLException(e.getMessage());
     }
   }
 
   @Override
-  protected String getValueByName(String columnName) throws SQLException {
+  public double getDouble(String columnName) throws SQLException {
     try {
-      return ioTDBRpcDataSet.getValueByName(columnName);
+      return ioTDBRpcDataSet.getDouble(columnName);
     } catch (StatementExecutionException e) {
       throw new SQLException(e.getMessage());
     }
   }
 
   @Override
-  protected Object getObjectByName(String columnName) throws SQLException {
+  public int getFetchDirection() {
+    return ResultSet.FETCH_FORWARD;
+  }
+
+  @Override
+  public void setFetchDirection(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public int getFetchSize() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void setFetchSize(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public float getFloat(int columnIndex) throws SQLException {
     try {
-      return ioTDBRpcDataSet.getObjectByName(columnName);
+      return getFloat(ioTDBRpcDataSet.findColumnNameByIndex(columnIndex));
+    } catch (StatementExecutionException e) {
+      throw new SQLException(e.getMessage());
+    }
+  }
+
+  @Override
+  public float getFloat(String columnName) throws SQLException {
+    try {
+      return ioTDBRpcDataSet.getFloat(columnName);
+    } catch (StatementExecutionException e) {
+      throw new SQLException(e.getMessage());
+    }
+  }
+
+  @Override
+  public int getHoldability() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public int getInt(int columnIndex) throws SQLException {
+    try {
+      return getInt(ioTDBRpcDataSet.findColumnNameByIndex(columnIndex));
+    } catch (StatementExecutionException e) {
+      throw new SQLException(e.getMessage());
+    }
+  }
+
+  @Override
+  public int getInt(String columnName) throws SQLException {
+    try {
+      return ioTDBRpcDataSet.getInt(columnName);
+    } catch (StatementExecutionException e) {
+      throw new SQLException(e.getMessage());
+    }
+  }
+
+  @Override
+  public long getLong(int columnIndex) throws SQLException {
+    try {
+      return getLong(ioTDBRpcDataSet.findColumnNameByIndex(columnIndex));
+    } catch (StatementExecutionException e) {
+      throw new SQLException(e.getMessage());
+    }
+  }
+
+  @Override
+  public long getLong(String columnName) throws SQLException {
+    try {
+      return ioTDBRpcDataSet.getLong(columnName);
+    } catch (StatementExecutionException e) {
+      throw new SQLException(e.getMessage());
+    }
+  }
+
+  @Override
+  public ResultSetMetaData getMetaData() {
+    String operationType = "";
+    boolean nonAlign = false;
+    try {
+      if (statement.getResultSet() instanceof IoTDBJDBCResultSet) {
+        operationType = ((IoTDBJDBCResultSet) statement.getResultSet()).getOperationType();
+        this.sgColumns = ((IoTDBJDBCResultSet) statement.getResultSet()).getSgColumns();
+      } else if (statement.getResultSet() instanceof IoTDBNonAlignJDBCResultSet) {
+        operationType = ((IoTDBNonAlignJDBCResultSet) statement.getResultSet()).getOperationType();
+        this.sgColumns = ((IoTDBNonAlignJDBCResultSet) statement.getResultSet()).getSgColumns();
+        nonAlign = true;
+      }
+    } catch (SQLException throwables) {
+      throwables.printStackTrace();
+    }
+    return new IoTDBResultMetadata(
+        nonAlign,
+        sgColumns,
+        operationType,
+        ioTDBRpcDataSet.columnNameList,
+        ioTDBRpcDataSet.columnTypeList,
+        ioTDBRpcDataSet.ignoreTimeStamp);
+  }
+
+  @Override
+  public Reader getNCharacterStream(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Reader getNCharacterStream(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public NClob getNClob(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public NClob getNClob(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public String getNString(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public String getNString(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Object getObject(int columnIndex) throws SQLException {
+    try {
+      return getObject(ioTDBRpcDataSet.findColumnNameByIndex(columnIndex));
     } catch (StatementExecutionException e) {
       throw new SQLException(e.getMessage());
     }
   }
 
+  @Override
+  public Object getObject(String columnName) throws SQLException {
+    return getObjectByName(columnName);
+  }
+
+  @Override
+  public Object getObject(int arg0, Map<String, Class<?>> arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Object getObject(String arg0, Map<String, Class<?>> arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public <T> T getObject(int arg0, Class<T> arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public <T> T getObject(String arg0, Class<T> arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Ref getRef(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Ref getRef(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public int getRow() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public RowId getRowId(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public RowId getRowId(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public SQLXML getSQLXML(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public SQLXML getSQLXML(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public short getShort(int columnIndex) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public short getShort(String columnName) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Statement getStatement() {
+    return this.statement;
+  }
+
+  @Override
+  public String getString(int columnIndex) throws SQLException {
+    try {
+      return getString(ioTDBRpcDataSet.findColumnNameByIndex(columnIndex));
+    } catch (StatementExecutionException e) {
+      throw new SQLException(e.getMessage());
+    }
+  }
+
+  @Override
+  public String getString(String columnName) throws SQLException {
+    return getValueByName(columnName);
+  }
+
+  @Override
+  public Time getTime(int columnIndex) throws SQLException {
+    return new Time(getLong(columnIndex));
+  }
+
+  @Override
+  public Time getTime(String columnName) throws SQLException {
+    return getTime(findColumn(columnName));
+  }
+
+  @Override
+  public Time getTime(int arg0, Calendar arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Time getTime(String arg0, Calendar arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Timestamp getTimestamp(int columnIndex) throws SQLException {
+    return new Timestamp(getLong(columnIndex));
+  }
+
+  @Override
+  public Timestamp getTimestamp(String columnName) throws SQLException {
+    return getTimestamp(findColumn(columnName));
+  }
+
+  @Override
+  public Timestamp getTimestamp(int arg0, Calendar arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Timestamp getTimestamp(String arg0, Calendar arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public int getType() {
+    return ResultSet.TYPE_FORWARD_ONLY;
+  }
+
+  @Override
+  public URL getURL(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public URL getURL(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public InputStream getUnicodeStream(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public InputStream getUnicodeStream(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public SQLWarning getWarnings() {
+    return warningChain;
+  }
+
+  @Override
+  public void insertRow() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public boolean isAfterLast() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public boolean isBeforeFirst() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public boolean isClosed() {
+    return ioTDBRpcDataSet.isClosed;
+  }
+
+  @Override
+  public boolean isFirst() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public boolean isLast() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public boolean last() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void moveToCurrentRow() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void moveToInsertRow() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public boolean next() throws SQLException {
+    if (hasCachedBlock()) {
+      constructOneRow();
+      return true;
+    }
+    if (hasCachedByteBuffer()) {
+      constructOneBlock();
+      constructOneRow();
+      return true;
+    }
+    if (ioTDBRpcDataSet.emptyResultSet) {
+      return false;
+    }
+    if (isRpcFetchResult && fetchResults() && hasCachedByteBuffer()) {
+      logger.info("before IoTDBJDBCDataSet fetchResult");
+      constructOneBlock();
+      constructOneRow();
+      logger.info(
+          "after IoTDBJDBCDataSet fetchResult"
+              + ioTDBRpcDataSet.queryResultSize
+              + " tsblock size"
+              + ioTDBRpcDataSet.tsBlockSize);
+      return true;
+    }
+    return false;
+  }
+
+  /** @return true means has results */
+  public boolean fetchResults() throws SQLException {

Review Comment:
   ```suggestion
     private boolean fetchResults() throws SQLException {
   ```



##########
server/src/main/java/org/apache/iotdb/db/mpp/plan/execution/QueryExecution.java:
##########
@@ -341,8 +347,8 @@ private void releaseResource() {
    * DataStreamManager use the virtual ResultOperator's ID (This part will be designed and
    * implemented with DataStreamManager)
    */
-  @Override
-  public Optional<TsBlock> getBatchResult() throws IoTDBException {
+  private Optional<Object> getResult(ISourceHandleSupplier<Object> dataSupplier)

Review Comment:
   ```suggestion
     private <T> Optional<T> getResult(ISourceHandleSupplier<T> dataSupplier)
   ```



##########
jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBJDBCResultSet.java:
##########
@@ -87,85 +126,1178 @@ public IoTDBJDBCResultSet(
       String sql,
       long queryId,
       long sessionId,
-      TSQueryDataSet dataset,
+      List<ByteBuffer> dataSet,
       TSTracingInfo tracingInfo,
       long timeout,
       boolean isRpcFetchResult)
       throws SQLException {
-    super(
-        statement,
-        columnNameList,
-        columnTypeList,
-        columnNameIndex,
-        ignoreTimeStamp,
-        client,
-        sql,
-        queryId,
-        sessionId,
-        timeout,
-        isRpcFetchResult);
-    ioTDBRpcDataSet.setTsQueryDataSet(dataset);
+    this.ioTDBRpcDataSet =
+        new IoTDBRpcDataSet(
+            sql,
+            columnNameList,
+            columnTypeList,
+            columnNameIndex,
+            ignoreTimeStamp,
+            queryId,
+            ((IoTDBStatement) statement).getStmtId(),
+            client,
+            sessionId,
+            dataSet,
+            statement.getFetchSize(),
+            timeout);
+    this.statement = statement;
+    this.columnTypeList = columnTypeList;
+    this.isRpcFetchResult = isRpcFetchResult;
     if (tracingInfo != null) {
       ioTDBRpcTracingInfo = new IoTDBTracingInfo();
       ioTDBRpcTracingInfo.setTsTracingInfo(tracingInfo);
     }
   }
 
   @Override
-  public long getLong(String columnName) throws SQLException {
+  public boolean isWrapperFor(Class<?> iface) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public <T> T unwrap(Class<T> iface) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public boolean absolute(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void afterLast() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void beforeFirst() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void cancelRowUpdates() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void clearWarnings() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void close() throws SQLException {
     try {
-      return ioTDBRpcDataSet.getLong(columnName);
+      ioTDBRpcDataSet.close();
+    } catch (StatementExecutionException e) {
+      throw new SQLException("Error occurs for close operation in server side because ", e);
+    } catch (TException e) {
+      throw new SQLException("Error occurs when connecting to server for close operation ", e);
+    }
+  }
+
+  @Override
+  public void deleteRow() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public int findColumn(String columnName) {
+    return ioTDBRpcDataSet.findColumn(columnName);
+  }
+
+  @Override
+  public boolean first() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Array getArray(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Array getArray(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public InputStream getAsciiStream(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public InputStream getAsciiStream(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public BigDecimal getBigDecimal(int columnIndex) throws SQLException {
+    try {
+      return getBigDecimal(ioTDBRpcDataSet.findColumnNameByIndex(columnIndex));
+    } catch (StatementExecutionException e) {
+      throw new SQLException(e.getMessage());
+    }
+  }
+
+  @Override
+  public BigDecimal getBigDecimal(String columnName) throws SQLException {
+    String value = getValueByName(columnName);
+    if (value != null) {
+      return new BigDecimal(value);
+    } else {
+      return null;
+    }
+  }
+
+  @Override
+  public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException {
+    MathContext mc = new MathContext(scale);
+    return getBigDecimal(columnIndex).round(mc);
+  }
+
+  @Override
+  public BigDecimal getBigDecimal(String columnName, int scale) throws SQLException {
+    return getBigDecimal(findColumn(columnName), scale);
+  }
+
+  @Override
+  public InputStream getBinaryStream(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public InputStream getBinaryStream(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Blob getBlob(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Blob getBlob(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public boolean getBoolean(int columnIndex) throws SQLException {
+    try {
+      return getBoolean(ioTDBRpcDataSet.findColumnNameByIndex(columnIndex));
     } catch (StatementExecutionException e) {
       throw new SQLException(e.getMessage());
     }
   }
 
   @Override
-  protected boolean fetchResults() throws SQLException {
+  public boolean getBoolean(String columnName) throws SQLException {
     try {
-      return ioTDBRpcDataSet.fetchResults();
-    } catch (StatementExecutionException | IoTDBConnectionException e) {
+      return ioTDBRpcDataSet.getBoolean(columnName);
+    } catch (StatementExecutionException e) {
       throw new SQLException(e.getMessage());
     }
   }
 
   @Override
-  protected boolean hasCachedResults() {
-    return ioTDBRpcDataSet.hasCachedResults();
+  public byte getByte(int columnIndex) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
   }
 
   @Override
-  protected void constructOneRow() {
-    ioTDBRpcDataSet.constructOneRow();
+  public byte getByte(String columnName) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
   }
 
   @Override
-  protected void checkRecord() throws SQLException {
+  public byte[] getBytes(int columnIndex) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public byte[] getBytes(String columnName) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Reader getCharacterStream(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Reader getCharacterStream(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Clob getClob(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Clob getClob(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public int getConcurrency() {
+    return ResultSet.CONCUR_READ_ONLY;
+  }
+
+  @Override
+  public String getCursorName() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Date getDate(int columnIndex) throws SQLException {
+    return new Date(getLong(columnIndex));
+  }
+
+  @Override
+  public Date getDate(String columnName) throws SQLException {
+    return getDate(findColumn(columnName));
+  }
+
+  @Override
+  public Date getDate(int arg0, Calendar arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Date getDate(String arg0, Calendar arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public double getDouble(int columnIndex) throws SQLException {
     try {
-      ioTDBRpcDataSet.checkRecord();
+      return getDouble(ioTDBRpcDataSet.findColumnNameByIndex(columnIndex));
     } catch (StatementExecutionException e) {
       throw new SQLException(e.getMessage());
     }
   }
 
   @Override
-  protected String getValueByName(String columnName) throws SQLException {
+  public double getDouble(String columnName) throws SQLException {
     try {
-      return ioTDBRpcDataSet.getValueByName(columnName);
+      return ioTDBRpcDataSet.getDouble(columnName);
     } catch (StatementExecutionException e) {
       throw new SQLException(e.getMessage());
     }
   }
 
   @Override
-  protected Object getObjectByName(String columnName) throws SQLException {
+  public int getFetchDirection() {
+    return ResultSet.FETCH_FORWARD;
+  }
+
+  @Override
+  public void setFetchDirection(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public int getFetchSize() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void setFetchSize(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public float getFloat(int columnIndex) throws SQLException {
     try {
-      return ioTDBRpcDataSet.getObjectByName(columnName);
+      return getFloat(ioTDBRpcDataSet.findColumnNameByIndex(columnIndex));
+    } catch (StatementExecutionException e) {
+      throw new SQLException(e.getMessage());
+    }
+  }
+
+  @Override
+  public float getFloat(String columnName) throws SQLException {
+    try {
+      return ioTDBRpcDataSet.getFloat(columnName);
+    } catch (StatementExecutionException e) {
+      throw new SQLException(e.getMessage());
+    }
+  }
+
+  @Override
+  public int getHoldability() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public int getInt(int columnIndex) throws SQLException {
+    try {
+      return getInt(ioTDBRpcDataSet.findColumnNameByIndex(columnIndex));
+    } catch (StatementExecutionException e) {
+      throw new SQLException(e.getMessage());
+    }
+  }
+
+  @Override
+  public int getInt(String columnName) throws SQLException {
+    try {
+      return ioTDBRpcDataSet.getInt(columnName);
+    } catch (StatementExecutionException e) {
+      throw new SQLException(e.getMessage());
+    }
+  }
+
+  @Override
+  public long getLong(int columnIndex) throws SQLException {
+    try {
+      return getLong(ioTDBRpcDataSet.findColumnNameByIndex(columnIndex));
+    } catch (StatementExecutionException e) {
+      throw new SQLException(e.getMessage());
+    }
+  }
+
+  @Override
+  public long getLong(String columnName) throws SQLException {
+    try {
+      return ioTDBRpcDataSet.getLong(columnName);
+    } catch (StatementExecutionException e) {
+      throw new SQLException(e.getMessage());
+    }
+  }
+
+  @Override
+  public ResultSetMetaData getMetaData() {
+    String operationType = "";
+    boolean nonAlign = false;
+    try {
+      if (statement.getResultSet() instanceof IoTDBJDBCResultSet) {
+        operationType = ((IoTDBJDBCResultSet) statement.getResultSet()).getOperationType();
+        this.sgColumns = ((IoTDBJDBCResultSet) statement.getResultSet()).getSgColumns();
+      } else if (statement.getResultSet() instanceof IoTDBNonAlignJDBCResultSet) {
+        operationType = ((IoTDBNonAlignJDBCResultSet) statement.getResultSet()).getOperationType();
+        this.sgColumns = ((IoTDBNonAlignJDBCResultSet) statement.getResultSet()).getSgColumns();
+        nonAlign = true;
+      }
+    } catch (SQLException throwables) {
+      throwables.printStackTrace();
+    }
+    return new IoTDBResultMetadata(
+        nonAlign,
+        sgColumns,
+        operationType,
+        ioTDBRpcDataSet.columnNameList,
+        ioTDBRpcDataSet.columnTypeList,
+        ioTDBRpcDataSet.ignoreTimeStamp);
+  }
+
+  @Override
+  public Reader getNCharacterStream(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Reader getNCharacterStream(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public NClob getNClob(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public NClob getNClob(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public String getNString(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public String getNString(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Object getObject(int columnIndex) throws SQLException {
+    try {
+      return getObject(ioTDBRpcDataSet.findColumnNameByIndex(columnIndex));
     } catch (StatementExecutionException e) {
       throw new SQLException(e.getMessage());
     }
   }
 
+  @Override
+  public Object getObject(String columnName) throws SQLException {
+    return getObjectByName(columnName);
+  }
+
+  @Override
+  public Object getObject(int arg0, Map<String, Class<?>> arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Object getObject(String arg0, Map<String, Class<?>> arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public <T> T getObject(int arg0, Class<T> arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public <T> T getObject(String arg0, Class<T> arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Ref getRef(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Ref getRef(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public int getRow() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public RowId getRowId(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public RowId getRowId(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public SQLXML getSQLXML(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public SQLXML getSQLXML(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public short getShort(int columnIndex) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public short getShort(String columnName) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Statement getStatement() {
+    return this.statement;
+  }
+
+  @Override
+  public String getString(int columnIndex) throws SQLException {
+    try {
+      return getString(ioTDBRpcDataSet.findColumnNameByIndex(columnIndex));
+    } catch (StatementExecutionException e) {
+      throw new SQLException(e.getMessage());
+    }
+  }
+
+  @Override
+  public String getString(String columnName) throws SQLException {
+    return getValueByName(columnName);
+  }
+
+  @Override
+  public Time getTime(int columnIndex) throws SQLException {
+    return new Time(getLong(columnIndex));
+  }
+
+  @Override
+  public Time getTime(String columnName) throws SQLException {
+    return getTime(findColumn(columnName));
+  }
+
+  @Override
+  public Time getTime(int arg0, Calendar arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Time getTime(String arg0, Calendar arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Timestamp getTimestamp(int columnIndex) throws SQLException {
+    return new Timestamp(getLong(columnIndex));
+  }
+
+  @Override
+  public Timestamp getTimestamp(String columnName) throws SQLException {
+    return getTimestamp(findColumn(columnName));
+  }
+
+  @Override
+  public Timestamp getTimestamp(int arg0, Calendar arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Timestamp getTimestamp(String arg0, Calendar arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public int getType() {
+    return ResultSet.TYPE_FORWARD_ONLY;
+  }
+
+  @Override
+  public URL getURL(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public URL getURL(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public InputStream getUnicodeStream(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public InputStream getUnicodeStream(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public SQLWarning getWarnings() {
+    return warningChain;
+  }
+
+  @Override
+  public void insertRow() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public boolean isAfterLast() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public boolean isBeforeFirst() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public boolean isClosed() {
+    return ioTDBRpcDataSet.isClosed;
+  }
+
+  @Override
+  public boolean isFirst() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public boolean isLast() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public boolean last() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void moveToCurrentRow() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void moveToInsertRow() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public boolean next() throws SQLException {
+    if (hasCachedBlock()) {
+      constructOneRow();
+      return true;
+    }
+    if (hasCachedByteBuffer()) {
+      constructOneBlock();
+      constructOneRow();
+      return true;
+    }
+    if (ioTDBRpcDataSet.emptyResultSet) {
+      return false;
+    }
+    if (isRpcFetchResult && fetchResults() && hasCachedByteBuffer()) {
+      logger.info("before IoTDBJDBCDataSet fetchResult");
+      constructOneBlock();
+      constructOneRow();
+      logger.info(
+          "after IoTDBJDBCDataSet fetchResult"
+              + ioTDBRpcDataSet.queryResultSize
+              + " tsblock size"
+              + ioTDBRpcDataSet.tsBlockSize);
+      return true;
+    }
+    return false;
+  }
+
+  /** @return true means has results */
+  public boolean fetchResults() throws SQLException {
+    try {
+      logger.info(
+          "IoTDBJDBCDataSet fetchResult:"
+              + ioTDBRpcDataSet.sql
+              + ioTDBRpcDataSet.sessionId
+              + ioTDBRpcDataSet.queryId);
+      logger.info("IoTDBJDBCDataSet fetchResult: fetchSize:" + ioTDBRpcDataSet.fetchSize);
+      return ioTDBRpcDataSet.fetchResults();
+    } catch (StatementExecutionException | IoTDBConnectionException e) {
+      throw new SQLException(e.getMessage());
+    }
+  }
+
+  boolean hasCachedResults() {
+    return hasCachedBlock() || hasCachedByteBuffer();
+  }
+
+  protected boolean hasCachedByteBuffer() {
+    return ioTDBRpcDataSet.hasCachedByteBuffer();
+  }
+
+  protected boolean hasCachedBlock() {
+    return ioTDBRpcDataSet.hasCachedBlock();
+  }
+
+  protected void constructOneRow() {
+    ioTDBRpcDataSet.constructOneRow();
+  }
+
+  protected void constructOneBlock() {
+    ioTDBRpcDataSet.constructOneTsBlock();
+  }
+
+  @Override
+  public boolean previous() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void refreshRow() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public boolean relative(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public boolean rowDeleted() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public boolean rowInserted() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public boolean rowUpdated() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateArray(int arg0, Array arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateArray(String arg0, Array arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateAsciiStream(int arg0, InputStream arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateAsciiStream(String arg0, InputStream arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateAsciiStream(int arg0, InputStream arg1, int arg2) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateAsciiStream(String arg0, InputStream arg1, int arg2) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateAsciiStream(int arg0, InputStream arg1, long arg2) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateAsciiStream(String arg0, InputStream arg1, long arg2) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateBigDecimal(int arg0, BigDecimal arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateBigDecimal(String arg0, BigDecimal arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateBinaryStream(int arg0, InputStream arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateBinaryStream(String arg0, InputStream arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateBinaryStream(int arg0, InputStream arg1, int arg2) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateBinaryStream(String arg0, InputStream arg1, int arg2) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateBinaryStream(int arg0, InputStream arg1, long arg2) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateBinaryStream(String arg0, InputStream arg1, long arg2) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateBlob(int arg0, Blob arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateBlob(String arg0, Blob arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateBlob(int arg0, InputStream arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateBlob(String arg0, InputStream arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateBlob(int arg0, InputStream arg1, long arg2) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateBlob(String arg0, InputStream arg1, long arg2) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateBoolean(int arg0, boolean arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateBoolean(String arg0, boolean arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateByte(int arg0, byte arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateByte(String arg0, byte arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateBytes(int arg0, byte[] arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateBytes(String arg0, byte[] arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateCharacterStream(int arg0, Reader arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateCharacterStream(String arg0, Reader arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateCharacterStream(int arg0, Reader arg1, int arg2) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateCharacterStream(String arg0, Reader arg1, int arg2) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateCharacterStream(int arg0, Reader arg1, long arg2) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateCharacterStream(String arg0, Reader arg1, long arg2) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateClob(int arg0, Clob arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateClob(String arg0, Clob arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateClob(int arg0, Reader arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateClob(String arg0, Reader arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateClob(int arg0, Reader arg1, long arg2) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateClob(String arg0, Reader arg1, long arg2) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateDate(int arg0, Date arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateDate(String arg0, Date arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateDouble(int arg0, double arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateDouble(String arg0, double arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateFloat(int arg0, float arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateFloat(String arg0, float arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateInt(int arg0, int arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateInt(String arg0, int arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateLong(int arg0, long arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateLong(String arg0, long arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateNCharacterStream(int arg0, Reader arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateNCharacterStream(String arg0, Reader arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateNCharacterStream(int arg0, Reader arg1, long arg2) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateNCharacterStream(String arg0, Reader arg1, long arg2) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateNClob(int arg0, NClob arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateNClob(String arg0, NClob arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateNClob(int arg0, Reader arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateNClob(String arg0, Reader arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateNClob(int arg0, Reader arg1, long arg2) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateNClob(String arg0, Reader arg1, long arg2) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateNString(int arg0, String arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateNString(String arg0, String arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateNull(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateNull(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateObject(int arg0, Object arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateObject(String arg0, Object arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateObject(int arg0, Object arg1, int arg2) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateObject(String arg0, Object arg1, int arg2) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateRef(int arg0, Ref arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateRef(String arg0, Ref arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateRow() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateRowId(int arg0, RowId arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateRowId(String arg0, RowId arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateSQLXML(int arg0, SQLXML arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateSQLXML(String arg0, SQLXML arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateShort(int arg0, short arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateShort(String arg0, short arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateString(int arg0, String arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateString(String arg0, String arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateTime(int arg0, Time arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateTime(String arg0, Time arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateTimestamp(int arg0, Timestamp arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void updateTimestamp(String arg0, Timestamp arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public boolean wasNull() {
+    return ioTDBRpcDataSet.lastReadWasNull;
+  }
+
+  protected void checkRecord() throws SQLException {
+    try {
+      ioTDBRpcDataSet.checkRecord();
+    } catch (StatementExecutionException e) {
+      throw new SQLException(e.getMessage());
+    }
+  };

Review Comment:
   ```suggestion
   ```



##########
server/src/main/java/org/apache/iotdb/db/service/thrift/impl/ClientRPCServiceImpl.java:
##########
@@ -148,6 +149,11 @@ public class ClientRPCServiceImpl implements IClientRPCServiceWithHandler {
 
   private final ISchemaFetcher SCHEMA_FETCHER;
 
+  @FunctionalInterface
+  public interface SelectResult<T, R, U> {
+    public void apply(T t, R r, U u) throws IoTDBException, IOException;
+  }

Review Comment:
   ```suggestion
     @FunctionalInterface
     private static final SelectResult OLD_SELECT_RESULT = (resp, queryExecution, fetchSize) -> resp.setQueryDataSet(QueryDataSetUtils.convertTsBlockByFetchSize(queryExecution, fetchSize));
   
     private static final SelectResult SELECT_RESULT = (resp, queryExecution, fetchSize) -> resp.setQueryResult(QueryDataSetUtils.convertQueryResultByFetchSize(queryExecution, fetchSize));
   
     @FunctionalInterface
     public interface SelectResult {
       void apply(TSExecuteStatementResp resp, IQueryExecution queryExecution, int fetchSize) throws IoTDBException, IOException;
     }
   ```



##########
server/src/main/java/org/apache/iotdb/db/mpp/plan/execution/QueryExecution.java:
##########
@@ -369,7 +372,8 @@ public Optional<TsBlock> getBatchResult() throws IoTDBException {
         ListenableFuture<?> blocked = resultHandle.isBlocked();
         blocked.get();
         if (!resultHandle.isFinished()) {
-          TsBlock res = resultHandle.receive();
+          // use the getSerializedTsBlock instead of receive to get ByteBuffer result
+          Object res = dataSupplier.get();

Review Comment:
   ```suggestion
             T res = dataSupplier.get();
   ```



##########
server/src/main/java/org/apache/iotdb/db/service/thrift/impl/ClientRPCServiceImpl.java:
##########
@@ -148,6 +149,11 @@ public class ClientRPCServiceImpl implements IClientRPCServiceWithHandler {
 
   private final ISchemaFetcher SCHEMA_FETCHER;
 
+  @FunctionalInterface
+  public interface SelectResult<T, R, U> {
+    public void apply(T t, R r, U u) throws IoTDBException, IOException;
+  }

Review Comment:
   reuse `OLD_SELECT_RESULT ` and `SELECT_RESULT ` in the following methods instead of creating new one  each time that method is called.



##########
server/src/main/java/org/apache/iotdb/db/mpp/plan/execution/QueryExecution.java:
##########
@@ -397,6 +401,18 @@ public Optional<TsBlock> getBatchResult() throws IoTDBException {
     }
   }
 
+  @Override
+  public Optional<TsBlock> getBatchResult() throws IoTDBException {
+    Optional<Object> res = getResult(() -> resultHandle.receive());
+    return res.map(o -> (TsBlock) o);
+  }
+
+  @Override
+  public Optional<ByteBuffer> getByteBufferBatchResult() throws IoTDBException {
+    Optional<Object> res = getResult(() -> resultHandle.getSerializedTsBlock());
+    return res.map(o -> (ByteBuffer) o);
+  }

Review Comment:
   ```suggestion
     @Override
     public Optional<TsBlock> getBatchResult() throws IoTDBException {
       return getResult(this::getDeserializedTsBlock);
     }
   
     private TsBlock getDeserializedTsBlock() {
       return resultHandle.receive();
     }
   
     @Override
     public Optional<ByteBuffer> getByteBufferBatchResult() throws IoTDBException {
       return getResult(this::getSerializedTsBlock);
     }
     
     private ByteBuffer getSerializedTsBlock() throws IoTDBException {
       return resultHandle.getSerializedTsBlock();
     }
   ```



##########
jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBJDBCResultSet.java:
##########
@@ -87,85 +126,1178 @@ public IoTDBJDBCResultSet(
       String sql,
       long queryId,
       long sessionId,
-      TSQueryDataSet dataset,
+      List<ByteBuffer> dataSet,
       TSTracingInfo tracingInfo,
       long timeout,
       boolean isRpcFetchResult)
       throws SQLException {
-    super(
-        statement,
-        columnNameList,
-        columnTypeList,
-        columnNameIndex,
-        ignoreTimeStamp,
-        client,
-        sql,
-        queryId,
-        sessionId,
-        timeout,
-        isRpcFetchResult);
-    ioTDBRpcDataSet.setTsQueryDataSet(dataset);
+    this.ioTDBRpcDataSet =
+        new IoTDBRpcDataSet(
+            sql,
+            columnNameList,
+            columnTypeList,
+            columnNameIndex,
+            ignoreTimeStamp,
+            queryId,
+            ((IoTDBStatement) statement).getStmtId(),
+            client,
+            sessionId,
+            dataSet,
+            statement.getFetchSize(),
+            timeout);
+    this.statement = statement;
+    this.columnTypeList = columnTypeList;
+    this.isRpcFetchResult = isRpcFetchResult;
     if (tracingInfo != null) {
       ioTDBRpcTracingInfo = new IoTDBTracingInfo();
       ioTDBRpcTracingInfo.setTsTracingInfo(tracingInfo);
     }
   }
 
   @Override
-  public long getLong(String columnName) throws SQLException {
+  public boolean isWrapperFor(Class<?> iface) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public <T> T unwrap(Class<T> iface) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public boolean absolute(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void afterLast() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void beforeFirst() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void cancelRowUpdates() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void clearWarnings() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void close() throws SQLException {
     try {
-      return ioTDBRpcDataSet.getLong(columnName);
+      ioTDBRpcDataSet.close();
+    } catch (StatementExecutionException e) {
+      throw new SQLException("Error occurs for close operation in server side because ", e);
+    } catch (TException e) {
+      throw new SQLException("Error occurs when connecting to server for close operation ", e);
+    }
+  }
+
+  @Override
+  public void deleteRow() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public int findColumn(String columnName) {
+    return ioTDBRpcDataSet.findColumn(columnName);
+  }
+
+  @Override
+  public boolean first() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Array getArray(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Array getArray(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public InputStream getAsciiStream(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public InputStream getAsciiStream(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public BigDecimal getBigDecimal(int columnIndex) throws SQLException {
+    try {
+      return getBigDecimal(ioTDBRpcDataSet.findColumnNameByIndex(columnIndex));
+    } catch (StatementExecutionException e) {
+      throw new SQLException(e.getMessage());
+    }
+  }
+
+  @Override
+  public BigDecimal getBigDecimal(String columnName) throws SQLException {
+    String value = getValueByName(columnName);
+    if (value != null) {
+      return new BigDecimal(value);
+    } else {
+      return null;
+    }
+  }
+
+  @Override
+  public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException {
+    MathContext mc = new MathContext(scale);
+    return getBigDecimal(columnIndex).round(mc);
+  }
+
+  @Override
+  public BigDecimal getBigDecimal(String columnName, int scale) throws SQLException {
+    return getBigDecimal(findColumn(columnName), scale);
+  }
+
+  @Override
+  public InputStream getBinaryStream(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public InputStream getBinaryStream(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Blob getBlob(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Blob getBlob(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public boolean getBoolean(int columnIndex) throws SQLException {
+    try {
+      return getBoolean(ioTDBRpcDataSet.findColumnNameByIndex(columnIndex));
     } catch (StatementExecutionException e) {
       throw new SQLException(e.getMessage());
     }
   }
 
   @Override
-  protected boolean fetchResults() throws SQLException {
+  public boolean getBoolean(String columnName) throws SQLException {
     try {
-      return ioTDBRpcDataSet.fetchResults();
-    } catch (StatementExecutionException | IoTDBConnectionException e) {
+      return ioTDBRpcDataSet.getBoolean(columnName);
+    } catch (StatementExecutionException e) {
       throw new SQLException(e.getMessage());
     }
   }
 
   @Override
-  protected boolean hasCachedResults() {
-    return ioTDBRpcDataSet.hasCachedResults();
+  public byte getByte(int columnIndex) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
   }
 
   @Override
-  protected void constructOneRow() {
-    ioTDBRpcDataSet.constructOneRow();
+  public byte getByte(String columnName) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
   }
 
   @Override
-  protected void checkRecord() throws SQLException {
+  public byte[] getBytes(int columnIndex) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public byte[] getBytes(String columnName) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Reader getCharacterStream(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Reader getCharacterStream(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Clob getClob(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Clob getClob(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public int getConcurrency() {
+    return ResultSet.CONCUR_READ_ONLY;
+  }
+
+  @Override
+  public String getCursorName() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Date getDate(int columnIndex) throws SQLException {
+    return new Date(getLong(columnIndex));
+  }
+
+  @Override
+  public Date getDate(String columnName) throws SQLException {
+    return getDate(findColumn(columnName));
+  }
+
+  @Override
+  public Date getDate(int arg0, Calendar arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Date getDate(String arg0, Calendar arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public double getDouble(int columnIndex) throws SQLException {
     try {
-      ioTDBRpcDataSet.checkRecord();
+      return getDouble(ioTDBRpcDataSet.findColumnNameByIndex(columnIndex));
     } catch (StatementExecutionException e) {
       throw new SQLException(e.getMessage());
     }
   }
 
   @Override
-  protected String getValueByName(String columnName) throws SQLException {
+  public double getDouble(String columnName) throws SQLException {
     try {
-      return ioTDBRpcDataSet.getValueByName(columnName);
+      return ioTDBRpcDataSet.getDouble(columnName);
     } catch (StatementExecutionException e) {
       throw new SQLException(e.getMessage());
     }
   }
 
   @Override
-  protected Object getObjectByName(String columnName) throws SQLException {
+  public int getFetchDirection() {
+    return ResultSet.FETCH_FORWARD;
+  }
+
+  @Override
+  public void setFetchDirection(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public int getFetchSize() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void setFetchSize(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public float getFloat(int columnIndex) throws SQLException {
     try {
-      return ioTDBRpcDataSet.getObjectByName(columnName);
+      return getFloat(ioTDBRpcDataSet.findColumnNameByIndex(columnIndex));
+    } catch (StatementExecutionException e) {
+      throw new SQLException(e.getMessage());
+    }
+  }
+
+  @Override
+  public float getFloat(String columnName) throws SQLException {
+    try {
+      return ioTDBRpcDataSet.getFloat(columnName);
+    } catch (StatementExecutionException e) {
+      throw new SQLException(e.getMessage());
+    }
+  }
+
+  @Override
+  public int getHoldability() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public int getInt(int columnIndex) throws SQLException {
+    try {
+      return getInt(ioTDBRpcDataSet.findColumnNameByIndex(columnIndex));
+    } catch (StatementExecutionException e) {
+      throw new SQLException(e.getMessage());
+    }
+  }
+
+  @Override
+  public int getInt(String columnName) throws SQLException {
+    try {
+      return ioTDBRpcDataSet.getInt(columnName);
+    } catch (StatementExecutionException e) {
+      throw new SQLException(e.getMessage());
+    }
+  }
+
+  @Override
+  public long getLong(int columnIndex) throws SQLException {
+    try {
+      return getLong(ioTDBRpcDataSet.findColumnNameByIndex(columnIndex));
+    } catch (StatementExecutionException e) {
+      throw new SQLException(e.getMessage());
+    }
+  }
+
+  @Override
+  public long getLong(String columnName) throws SQLException {
+    try {
+      return ioTDBRpcDataSet.getLong(columnName);
+    } catch (StatementExecutionException e) {
+      throw new SQLException(e.getMessage());
+    }
+  }
+
+  @Override
+  public ResultSetMetaData getMetaData() {
+    String operationType = "";
+    boolean nonAlign = false;
+    try {
+      if (statement.getResultSet() instanceof IoTDBJDBCResultSet) {
+        operationType = ((IoTDBJDBCResultSet) statement.getResultSet()).getOperationType();
+        this.sgColumns = ((IoTDBJDBCResultSet) statement.getResultSet()).getSgColumns();
+      } else if (statement.getResultSet() instanceof IoTDBNonAlignJDBCResultSet) {
+        operationType = ((IoTDBNonAlignJDBCResultSet) statement.getResultSet()).getOperationType();
+        this.sgColumns = ((IoTDBNonAlignJDBCResultSet) statement.getResultSet()).getSgColumns();
+        nonAlign = true;
+      }
+    } catch (SQLException throwables) {
+      throwables.printStackTrace();
+    }
+    return new IoTDBResultMetadata(
+        nonAlign,
+        sgColumns,
+        operationType,
+        ioTDBRpcDataSet.columnNameList,
+        ioTDBRpcDataSet.columnTypeList,
+        ioTDBRpcDataSet.ignoreTimeStamp);
+  }
+
+  @Override
+  public Reader getNCharacterStream(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Reader getNCharacterStream(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public NClob getNClob(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public NClob getNClob(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public String getNString(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public String getNString(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Object getObject(int columnIndex) throws SQLException {
+    try {
+      return getObject(ioTDBRpcDataSet.findColumnNameByIndex(columnIndex));
     } catch (StatementExecutionException e) {
       throw new SQLException(e.getMessage());
     }
   }
 
+  @Override
+  public Object getObject(String columnName) throws SQLException {
+    return getObjectByName(columnName);
+  }
+
+  @Override
+  public Object getObject(int arg0, Map<String, Class<?>> arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Object getObject(String arg0, Map<String, Class<?>> arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public <T> T getObject(int arg0, Class<T> arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public <T> T getObject(String arg0, Class<T> arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Ref getRef(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Ref getRef(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public int getRow() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public RowId getRowId(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public RowId getRowId(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public SQLXML getSQLXML(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public SQLXML getSQLXML(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public short getShort(int columnIndex) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public short getShort(String columnName) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Statement getStatement() {
+    return this.statement;
+  }
+
+  @Override
+  public String getString(int columnIndex) throws SQLException {
+    try {
+      return getString(ioTDBRpcDataSet.findColumnNameByIndex(columnIndex));
+    } catch (StatementExecutionException e) {
+      throw new SQLException(e.getMessage());
+    }
+  }
+
+  @Override
+  public String getString(String columnName) throws SQLException {
+    return getValueByName(columnName);
+  }
+
+  @Override
+  public Time getTime(int columnIndex) throws SQLException {
+    return new Time(getLong(columnIndex));
+  }
+
+  @Override
+  public Time getTime(String columnName) throws SQLException {
+    return getTime(findColumn(columnName));
+  }
+
+  @Override
+  public Time getTime(int arg0, Calendar arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Time getTime(String arg0, Calendar arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Timestamp getTimestamp(int columnIndex) throws SQLException {
+    return new Timestamp(getLong(columnIndex));
+  }
+
+  @Override
+  public Timestamp getTimestamp(String columnName) throws SQLException {
+    return getTimestamp(findColumn(columnName));
+  }
+
+  @Override
+  public Timestamp getTimestamp(int arg0, Calendar arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Timestamp getTimestamp(String arg0, Calendar arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public int getType() {
+    return ResultSet.TYPE_FORWARD_ONLY;
+  }
+
+  @Override
+  public URL getURL(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public URL getURL(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public InputStream getUnicodeStream(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public InputStream getUnicodeStream(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public SQLWarning getWarnings() {
+    return warningChain;
+  }
+
+  @Override
+  public void insertRow() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public boolean isAfterLast() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public boolean isBeforeFirst() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public boolean isClosed() {
+    return ioTDBRpcDataSet.isClosed;
+  }
+
+  @Override
+  public boolean isFirst() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public boolean isLast() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public boolean last() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void moveToCurrentRow() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void moveToInsertRow() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public boolean next() throws SQLException {

Review Comment:
   why not just call ioTDBRpcDataSet.next() ?



##########
jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBJDBCResultSet.java:
##########
@@ -87,85 +126,1178 @@ public IoTDBJDBCResultSet(
       String sql,
       long queryId,
       long sessionId,
-      TSQueryDataSet dataset,
+      List<ByteBuffer> dataSet,
       TSTracingInfo tracingInfo,
       long timeout,
       boolean isRpcFetchResult)
       throws SQLException {
-    super(
-        statement,
-        columnNameList,
-        columnTypeList,
-        columnNameIndex,
-        ignoreTimeStamp,
-        client,
-        sql,
-        queryId,
-        sessionId,
-        timeout,
-        isRpcFetchResult);
-    ioTDBRpcDataSet.setTsQueryDataSet(dataset);
+    this.ioTDBRpcDataSet =
+        new IoTDBRpcDataSet(
+            sql,
+            columnNameList,
+            columnTypeList,
+            columnNameIndex,
+            ignoreTimeStamp,
+            queryId,
+            ((IoTDBStatement) statement).getStmtId(),
+            client,
+            sessionId,
+            dataSet,
+            statement.getFetchSize(),
+            timeout);
+    this.statement = statement;
+    this.columnTypeList = columnTypeList;
+    this.isRpcFetchResult = isRpcFetchResult;
     if (tracingInfo != null) {
       ioTDBRpcTracingInfo = new IoTDBTracingInfo();
       ioTDBRpcTracingInfo.setTsTracingInfo(tracingInfo);
     }
   }
 
   @Override
-  public long getLong(String columnName) throws SQLException {
+  public boolean isWrapperFor(Class<?> iface) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public <T> T unwrap(Class<T> iface) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public boolean absolute(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void afterLast() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void beforeFirst() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void cancelRowUpdates() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void clearWarnings() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void close() throws SQLException {
     try {
-      return ioTDBRpcDataSet.getLong(columnName);
+      ioTDBRpcDataSet.close();
+    } catch (StatementExecutionException e) {
+      throw new SQLException("Error occurs for close operation in server side because ", e);
+    } catch (TException e) {
+      throw new SQLException("Error occurs when connecting to server for close operation ", e);
+    }
+  }
+
+  @Override
+  public void deleteRow() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public int findColumn(String columnName) {
+    return ioTDBRpcDataSet.findColumn(columnName);
+  }
+
+  @Override
+  public boolean first() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Array getArray(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Array getArray(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public InputStream getAsciiStream(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public InputStream getAsciiStream(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public BigDecimal getBigDecimal(int columnIndex) throws SQLException {
+    try {
+      return getBigDecimal(ioTDBRpcDataSet.findColumnNameByIndex(columnIndex));
+    } catch (StatementExecutionException e) {
+      throw new SQLException(e.getMessage());
+    }
+  }
+
+  @Override
+  public BigDecimal getBigDecimal(String columnName) throws SQLException {
+    String value = getValueByName(columnName);
+    if (value != null) {
+      return new BigDecimal(value);
+    } else {
+      return null;
+    }
+  }
+
+  @Override
+  public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException {
+    MathContext mc = new MathContext(scale);
+    return getBigDecimal(columnIndex).round(mc);
+  }
+
+  @Override
+  public BigDecimal getBigDecimal(String columnName, int scale) throws SQLException {
+    return getBigDecimal(findColumn(columnName), scale);
+  }
+
+  @Override
+  public InputStream getBinaryStream(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public InputStream getBinaryStream(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Blob getBlob(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Blob getBlob(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public boolean getBoolean(int columnIndex) throws SQLException {
+    try {
+      return getBoolean(ioTDBRpcDataSet.findColumnNameByIndex(columnIndex));
     } catch (StatementExecutionException e) {
       throw new SQLException(e.getMessage());
     }
   }
 
   @Override
-  protected boolean fetchResults() throws SQLException {
+  public boolean getBoolean(String columnName) throws SQLException {
     try {
-      return ioTDBRpcDataSet.fetchResults();
-    } catch (StatementExecutionException | IoTDBConnectionException e) {
+      return ioTDBRpcDataSet.getBoolean(columnName);
+    } catch (StatementExecutionException e) {
       throw new SQLException(e.getMessage());
     }
   }
 
   @Override
-  protected boolean hasCachedResults() {
-    return ioTDBRpcDataSet.hasCachedResults();
+  public byte getByte(int columnIndex) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
   }
 
   @Override
-  protected void constructOneRow() {
-    ioTDBRpcDataSet.constructOneRow();
+  public byte getByte(String columnName) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
   }
 
   @Override
-  protected void checkRecord() throws SQLException {
+  public byte[] getBytes(int columnIndex) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public byte[] getBytes(String columnName) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Reader getCharacterStream(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Reader getCharacterStream(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Clob getClob(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Clob getClob(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public int getConcurrency() {
+    return ResultSet.CONCUR_READ_ONLY;
+  }
+
+  @Override
+  public String getCursorName() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Date getDate(int columnIndex) throws SQLException {
+    return new Date(getLong(columnIndex));
+  }
+
+  @Override
+  public Date getDate(String columnName) throws SQLException {
+    return getDate(findColumn(columnName));
+  }
+
+  @Override
+  public Date getDate(int arg0, Calendar arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Date getDate(String arg0, Calendar arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public double getDouble(int columnIndex) throws SQLException {
     try {
-      ioTDBRpcDataSet.checkRecord();
+      return getDouble(ioTDBRpcDataSet.findColumnNameByIndex(columnIndex));
     } catch (StatementExecutionException e) {
       throw new SQLException(e.getMessage());
     }
   }
 
   @Override
-  protected String getValueByName(String columnName) throws SQLException {
+  public double getDouble(String columnName) throws SQLException {
     try {
-      return ioTDBRpcDataSet.getValueByName(columnName);
+      return ioTDBRpcDataSet.getDouble(columnName);
     } catch (StatementExecutionException e) {
       throw new SQLException(e.getMessage());
     }
   }
 
   @Override
-  protected Object getObjectByName(String columnName) throws SQLException {
+  public int getFetchDirection() {
+    return ResultSet.FETCH_FORWARD;
+  }
+
+  @Override
+  public void setFetchDirection(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public int getFetchSize() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void setFetchSize(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public float getFloat(int columnIndex) throws SQLException {
     try {
-      return ioTDBRpcDataSet.getObjectByName(columnName);
+      return getFloat(ioTDBRpcDataSet.findColumnNameByIndex(columnIndex));
+    } catch (StatementExecutionException e) {
+      throw new SQLException(e.getMessage());
+    }
+  }
+
+  @Override
+  public float getFloat(String columnName) throws SQLException {
+    try {
+      return ioTDBRpcDataSet.getFloat(columnName);
+    } catch (StatementExecutionException e) {
+      throw new SQLException(e.getMessage());
+    }
+  }
+
+  @Override
+  public int getHoldability() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public int getInt(int columnIndex) throws SQLException {
+    try {
+      return getInt(ioTDBRpcDataSet.findColumnNameByIndex(columnIndex));
+    } catch (StatementExecutionException e) {
+      throw new SQLException(e.getMessage());
+    }
+  }
+
+  @Override
+  public int getInt(String columnName) throws SQLException {
+    try {
+      return ioTDBRpcDataSet.getInt(columnName);
+    } catch (StatementExecutionException e) {
+      throw new SQLException(e.getMessage());
+    }
+  }
+
+  @Override
+  public long getLong(int columnIndex) throws SQLException {
+    try {
+      return getLong(ioTDBRpcDataSet.findColumnNameByIndex(columnIndex));
+    } catch (StatementExecutionException e) {
+      throw new SQLException(e.getMessage());
+    }
+  }
+
+  @Override
+  public long getLong(String columnName) throws SQLException {
+    try {
+      return ioTDBRpcDataSet.getLong(columnName);
+    } catch (StatementExecutionException e) {
+      throw new SQLException(e.getMessage());
+    }
+  }
+
+  @Override
+  public ResultSetMetaData getMetaData() {
+    String operationType = "";
+    boolean nonAlign = false;
+    try {
+      if (statement.getResultSet() instanceof IoTDBJDBCResultSet) {
+        operationType = ((IoTDBJDBCResultSet) statement.getResultSet()).getOperationType();
+        this.sgColumns = ((IoTDBJDBCResultSet) statement.getResultSet()).getSgColumns();
+      } else if (statement.getResultSet() instanceof IoTDBNonAlignJDBCResultSet) {
+        operationType = ((IoTDBNonAlignJDBCResultSet) statement.getResultSet()).getOperationType();
+        this.sgColumns = ((IoTDBNonAlignJDBCResultSet) statement.getResultSet()).getSgColumns();
+        nonAlign = true;
+      }
+    } catch (SQLException throwables) {
+      throwables.printStackTrace();
+    }
+    return new IoTDBResultMetadata(
+        nonAlign,
+        sgColumns,
+        operationType,
+        ioTDBRpcDataSet.columnNameList,
+        ioTDBRpcDataSet.columnTypeList,
+        ioTDBRpcDataSet.ignoreTimeStamp);
+  }
+
+  @Override
+  public Reader getNCharacterStream(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Reader getNCharacterStream(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public NClob getNClob(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public NClob getNClob(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public String getNString(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public String getNString(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Object getObject(int columnIndex) throws SQLException {
+    try {
+      return getObject(ioTDBRpcDataSet.findColumnNameByIndex(columnIndex));
     } catch (StatementExecutionException e) {
       throw new SQLException(e.getMessage());
     }
   }
 
+  @Override
+  public Object getObject(String columnName) throws SQLException {
+    return getObjectByName(columnName);
+  }
+
+  @Override
+  public Object getObject(int arg0, Map<String, Class<?>> arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Object getObject(String arg0, Map<String, Class<?>> arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public <T> T getObject(int arg0, Class<T> arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public <T> T getObject(String arg0, Class<T> arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Ref getRef(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Ref getRef(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public int getRow() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public RowId getRowId(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public RowId getRowId(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public SQLXML getSQLXML(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public SQLXML getSQLXML(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public short getShort(int columnIndex) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public short getShort(String columnName) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Statement getStatement() {
+    return this.statement;
+  }
+
+  @Override
+  public String getString(int columnIndex) throws SQLException {
+    try {
+      return getString(ioTDBRpcDataSet.findColumnNameByIndex(columnIndex));
+    } catch (StatementExecutionException e) {
+      throw new SQLException(e.getMessage());
+    }
+  }
+
+  @Override
+  public String getString(String columnName) throws SQLException {
+    return getValueByName(columnName);
+  }
+
+  @Override
+  public Time getTime(int columnIndex) throws SQLException {
+    return new Time(getLong(columnIndex));
+  }
+
+  @Override
+  public Time getTime(String columnName) throws SQLException {
+    return getTime(findColumn(columnName));
+  }
+
+  @Override
+  public Time getTime(int arg0, Calendar arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Time getTime(String arg0, Calendar arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Timestamp getTimestamp(int columnIndex) throws SQLException {
+    return new Timestamp(getLong(columnIndex));
+  }
+
+  @Override
+  public Timestamp getTimestamp(String columnName) throws SQLException {
+    return getTimestamp(findColumn(columnName));
+  }
+
+  @Override
+  public Timestamp getTimestamp(int arg0, Calendar arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public Timestamp getTimestamp(String arg0, Calendar arg1) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public int getType() {
+    return ResultSet.TYPE_FORWARD_ONLY;
+  }
+
+  @Override
+  public URL getURL(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public URL getURL(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public InputStream getUnicodeStream(int arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public InputStream getUnicodeStream(String arg0) throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public SQLWarning getWarnings() {
+    return warningChain;
+  }
+
+  @Override
+  public void insertRow() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public boolean isAfterLast() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public boolean isBeforeFirst() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public boolean isClosed() {
+    return ioTDBRpcDataSet.isClosed;
+  }
+
+  @Override
+  public boolean isFirst() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public boolean isLast() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public boolean last() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void moveToCurrentRow() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public void moveToInsertRow() throws SQLException {
+    throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+  }
+
+  @Override
+  public boolean next() throws SQLException {
+    if (hasCachedBlock()) {
+      constructOneRow();
+      return true;
+    }
+    if (hasCachedByteBuffer()) {
+      constructOneBlock();
+      constructOneRow();
+      return true;
+    }
+    if (ioTDBRpcDataSet.emptyResultSet) {
+      return false;
+    }
+    if (isRpcFetchResult && fetchResults() && hasCachedByteBuffer()) {
+      logger.info("before IoTDBJDBCDataSet fetchResult");
+      constructOneBlock();
+      constructOneRow();
+      logger.info(
+          "after IoTDBJDBCDataSet fetchResult"
+              + ioTDBRpcDataSet.queryResultSize
+              + " tsblock size"
+              + ioTDBRpcDataSet.tsBlockSize);
+      return true;
+    }
+    return false;

Review Comment:
   ```suggestion
       return ioTDBRpcDataSet.next();
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] JackieTien97 commented on a diff in pull request #7613: [IOTDB-3936]Add an interface in IClientRPCService to directly return bytebuffer instead of TSQueryDataSet

Posted by GitBox <gi...@apache.org>.
JackieTien97 commented on code in PR #7613:
URL: https://github.com/apache/iotdb/pull/7613#discussion_r998997856


##########
server/src/main/java/org/apache/iotdb/db/mpp/execution/exchange/ISourceHandle.java:
##########
@@ -40,6 +42,9 @@ public interface ISourceHandle {
    */
   TsBlock receive();
 
+  /** get the serialized tsblock as the form of bytebuffer. */

Review Comment:
   Add more java doc to indicate that this method share the same iterator with `receive()`, after this method being called, `receive()`'s cursor will also forward.



##########
server/src/main/java/org/apache/iotdb/db/mpp/execution/exchange/LocalSourceHandle.java:
##########
@@ -103,6 +107,36 @@ public TsBlock receive() {
     }
   }
 
+  @Override
+  public ByteBuffer getSerializedTsBlock() {
+    try (SetThreadName sourceHandleName = new SetThreadName(threadName)) {
+      checkState();
+
+      if (!queue.isBlocked().isDone()) {
+        throw new IllegalStateException("Source handle is blocked.");
+      }
+      TsBlock tsBlock;
+      synchronized (queue) {
+        tsBlock = queue.remove();
+      }
+      if (tsBlock != null) {
+        currSequenceId++;
+        logger.info(
+            "[GetTsBlockFromQueue] TsBlock:{} size:{}",
+            currSequenceId,
+            tsBlock.getRetainedSizeInBytes());
+      }
+      checkAndInvokeOnFinished();
+      if (tsBlock != null) {
+        return new TsBlockSerde().serialize(tsBlock);
+      } else {
+        return null;
+      }
+    } catch (IOException e) {
+      throw new RuntimeException(e);
+    }

Review Comment:
   Too much duplicated code with `receive()`, try to extract same code.



##########
server/src/main/java/org/apache/iotdb/db/mpp/plan/execution/QueryExecution.java:
##########
@@ -392,6 +393,60 @@ public Optional<TsBlock> getBatchResult() throws IoTDBException {
     }
   }
 
+  @Override
+  public Optional<ByteBuffer> getByteBufferBatchResult() throws IoTDBException {

Review Comment:
   extract the common code



##########
server/src/main/java/org/apache/iotdb/db/mpp/plan/execution/memory/MemorySourceHandle.java:
##########
@@ -60,6 +64,20 @@ public synchronized TsBlock receive() {
     return result;
   }
 
+  @Override
+  public ByteBuffer getSerializedTsBlock() {
+    hasNext = false;
+    if (result.isEmpty()) {
+      return null;
+    } else {
+      try {
+        return new TsBlockSerde().serialize(result);
+      } catch (IOException e) {
+        throw new RuntimeException(e);

Review Comment:
   try not to throw RuntimeException



##########
server/src/main/java/org/apache/iotdb/db/service/thrift/impl/TSServiceImpl.java:
##########
@@ -315,6 +315,38 @@ public TSServiceImpl() {
     serviceProvider = IoTDB.serviceProvider;
   }
 
+  @Override
+  public TSExecuteStatementResp executeQueryStatementV2(TSExecuteStatementReq req)
+      throws TException {
+    return null;
+  }
+
+  @Override
+  public TSExecuteStatementResp executeUpdateStatementV2(TSExecuteStatementReq req)
+      throws TException {
+    return null;
+  }
+
+  @Override
+  public TSExecuteStatementResp executeStatementV2(TSExecuteStatementReq req) throws TException {
+    return null;
+  }
+
+  @Override
+  public TSExecuteStatementResp executeRawDataQueryV2(TSRawDataQueryReq req) throws TException {
+    return null;
+  }
+
+  @Override
+  public TSExecuteStatementResp executeLastDataQueryV2(TSLastDataQueryReq req) throws TException {
+    return null;

Review Comment:
   ```suggestion
       throw  new UnsupportedOperationException();
   ```



##########
server/src/main/java/org/apache/iotdb/db/service/thrift/impl/ClientRPCServiceImpl.java:
##########
@@ -158,6 +159,270 @@ public ClientRPCServiceImpl() {
     }
   }
 
+  @Override
+  public TSExecuteStatementResp executeQueryStatementV2(TSExecuteStatementReq req)
+      throws TException {
+    return executeStatementV2(req);
+  }
+
+  @Override
+  public TSExecuteStatementResp executeUpdateStatementV2(TSExecuteStatementReq req)
+      throws TException {
+    return executeStatementV2(req);
+  }
+
+  // To fetch required amounts of data and combine them through List
+  private List<ByteBuffer> convertQueryResultByFetchSize(
+      IQueryExecution queryExecution, int fetchSize) {
+    int rowCount = 0;
+    List<ByteBuffer> res = new LinkedList<>();
+    while (rowCount < fetchSize) {
+      try {
+        Optional<ByteBuffer> optionalByteBuffer = queryExecution.getByteBufferBatchResult();
+        if (!optionalByteBuffer.isPresent()) {
+          break;
+        }
+
+        ByteBuffer byteBuffer = optionalByteBuffer.get();
+        byteBuffer.mark();
+        int valueColumnCount = byteBuffer.getInt();
+        if (valueColumnCount == 0) {
+          continue;
+        }

Review Comment:
   it's  ok that valueColumnColumn is zero, don't skip this. We may support some queries that only need time column.



##########
server/src/main/java/org/apache/iotdb/db/service/thrift/impl/ClientRPCServiceImpl.java:
##########
@@ -158,6 +159,270 @@ public ClientRPCServiceImpl() {
     }
   }
 
+  @Override
+  public TSExecuteStatementResp executeQueryStatementV2(TSExecuteStatementReq req)
+      throws TException {
+    return executeStatementV2(req);
+  }
+
+  @Override
+  public TSExecuteStatementResp executeUpdateStatementV2(TSExecuteStatementReq req)
+      throws TException {
+    return executeStatementV2(req);
+  }
+
+  // To fetch required amounts of data and combine them through List
+  private List<ByteBuffer> convertQueryResultByFetchSize(

Review Comment:
   move the method to `QueryDataSetUtils`



##########
session/src/main/java/org/apache/iotdb/session/SessionDataSet.java:
##########
@@ -134,32 +132,31 @@ private RowRecord constructRowRecordFromValueArray() throws StatementExecutionEx
               - START_INDEX;
 
       if (!ioTDBRpcDataSet.isNull(datasetColumnIndex)) {
-        byte[] valueBytes = ioTDBRpcDataSet.values[loc];
         TSDataType dataType = ioTDBRpcDataSet.columnTypeDeduplicatedList.get(loc);
         field = new Field(dataType);
         switch (dataType) {
           case BOOLEAN:
-            boolean booleanValue = BytesUtils.bytesToBool(valueBytes);
+            boolean booleanValue = ioTDBRpcDataSet.getBoolean(datasetColumnIndex);
             field.setBoolV(booleanValue);
             break;
           case INT32:
-            int intValue = BytesUtils.bytesToInt(valueBytes);
+            int intValue = iterator().getInt(datasetColumnIndex);

Review Comment:
   Why `INT32` is different from other types?



##########
session/src/test/java/org/apache/iotdb/session/SessionDatasetTest.java:
##########
@@ -0,0 +1,238 @@
+/*
+ * 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.session;
+
+import org.apache.iotdb.rpc.IoTDBConnectionException;
+import org.apache.iotdb.rpc.StatementExecutionException;
+import org.apache.iotdb.tsfile.exception.write.UnSupportedDataTypeException;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+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.Field;
+import org.apache.iotdb.tsfile.read.common.RowRecord;
+import org.apache.iotdb.tsfile.write.record.Tablet;
+import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+public class SessionDatasetTest {

Review Comment:
   no need to add this test.



##########
server/src/main/java/org/apache/iotdb/db/service/thrift/impl/TSServiceImpl.java:
##########
@@ -315,6 +315,38 @@ public TSServiceImpl() {
     serviceProvider = IoTDB.serviceProvider;
   }
 
+  @Override
+  public TSExecuteStatementResp executeQueryStatementV2(TSExecuteStatementReq req)
+      throws TException {
+    return null;
+  }
+
+  @Override
+  public TSExecuteStatementResp executeUpdateStatementV2(TSExecuteStatementReq req)
+      throws TException {
+    return null;

Review Comment:
   ```suggestion
       throw  new UnsupportedOperationException();
   ```



##########
server/src/main/java/org/apache/iotdb/db/mpp/plan/execution/config/ConfigExecution.java:
##########
@@ -172,6 +175,19 @@ public Optional<TsBlock> getBatchResult() {
     return Optional.empty();
   }
 
+  @Override
+  public Optional<ByteBuffer> getByteBufferBatchResult() {
+    if (!resultSetConsumed) {
+      resultSetConsumed = true;
+      try {
+        return Optional.of(new TsBlockSerde().serialize(resultSet));
+      } catch (IOException e) {
+        throw new RuntimeException(e);

Review Comment:
   try not to use RuntimeException to wrap



##########
server/src/main/java/org/apache/iotdb/db/service/thrift/impl/TSServiceImpl.java:
##########
@@ -315,6 +315,38 @@ public TSServiceImpl() {
     serviceProvider = IoTDB.serviceProvider;
   }
 
+  @Override
+  public TSExecuteStatementResp executeQueryStatementV2(TSExecuteStatementReq req)
+      throws TException {
+    return null;

Review Comment:
   ```suggestion
       throw  new UnsupportedOperationException();
   ```



##########
server/src/main/java/org/apache/iotdb/db/mpp/execution/exchange/LocalSourceHandle.java:
##########
@@ -103,6 +107,36 @@ public TsBlock receive() {
     }
   }
 
+  @Override
+  public ByteBuffer getSerializedTsBlock() {
+    try (SetThreadName sourceHandleName = new SetThreadName(threadName)) {
+      checkState();
+
+      if (!queue.isBlocked().isDone()) {
+        throw new IllegalStateException("Source handle is blocked.");
+      }
+      TsBlock tsBlock;
+      synchronized (queue) {
+        tsBlock = queue.remove();
+      }
+      if (tsBlock != null) {
+        currSequenceId++;
+        logger.info(
+            "[GetTsBlockFromQueue] TsBlock:{} size:{}",
+            currSequenceId,
+            tsBlock.getRetainedSizeInBytes());
+      }
+      checkAndInvokeOnFinished();
+      if (tsBlock != null) {
+        return new TsBlockSerde().serialize(tsBlock);
+      } else {
+        return null;
+      }
+    } catch (IOException e) {
+      throw new RuntimeException(e);

Review Comment:
   better not to wrap checked exception as unchecked exception. You can add `throw IOException` in the signature of this method and then add catch block in the caller.



##########
server/src/main/java/org/apache/iotdb/db/service/thrift/impl/TSServiceImpl.java:
##########
@@ -315,6 +315,38 @@ public TSServiceImpl() {
     serviceProvider = IoTDB.serviceProvider;
   }
 
+  @Override
+  public TSExecuteStatementResp executeQueryStatementV2(TSExecuteStatementReq req)
+      throws TException {
+    return null;
+  }
+
+  @Override
+  public TSExecuteStatementResp executeUpdateStatementV2(TSExecuteStatementReq req)
+      throws TException {
+    return null;
+  }
+
+  @Override
+  public TSExecuteStatementResp executeStatementV2(TSExecuteStatementReq req) throws TException {
+    return null;

Review Comment:
   ```suggestion
       throw  new UnsupportedOperationException();
   ```



##########
server/src/main/java/org/apache/iotdb/db/service/thrift/impl/TSServiceImpl.java:
##########
@@ -315,6 +315,38 @@ public TSServiceImpl() {
     serviceProvider = IoTDB.serviceProvider;
   }
 
+  @Override
+  public TSExecuteStatementResp executeQueryStatementV2(TSExecuteStatementReq req)
+      throws TException {
+    return null;
+  }
+
+  @Override
+  public TSExecuteStatementResp executeUpdateStatementV2(TSExecuteStatementReq req)
+      throws TException {
+    return null;
+  }
+
+  @Override
+  public TSExecuteStatementResp executeStatementV2(TSExecuteStatementReq req) throws TException {
+    return null;
+  }
+
+  @Override
+  public TSExecuteStatementResp executeRawDataQueryV2(TSRawDataQueryReq req) throws TException {
+    return null;

Review Comment:
   ```suggestion
       throw  new UnsupportedOperationException();
   ```



##########
server/src/main/java/org/apache/iotdb/db/mpp/execution/exchange/SourceHandle.java:
##########
@@ -146,6 +148,38 @@ public synchronized TsBlock receive() {
     }
   }
 
+  @Override
+  public ByteBuffer getSerializedTsBlock() {
+    try (SetThreadName sourceHandleName = new SetThreadName(threadName)) {
+
+      checkState();
+
+      if (!blocked.isDone()) {
+        throw new IllegalStateException("Source handle is blocked.");
+      }
+
+      ByteBuffer bfBlock = sequenceIdToBfBlock.remove(currSequenceId);
+      if (bfBlock == null) {
+        return null;
+      }
+      long retainedSize = sequenceIdToDataBlockSize.remove(currSequenceId);
+      logger.info("[GetTsBlockFromBuffer] sequenceId:{}, size:{}", currSequenceId, retainedSize);
+      currSequenceId += 1;
+      bufferRetainedSizeInBytes -= retainedSize;
+      localMemoryManager.getQueryPool().free(localFragmentInstanceId.getQueryId(), retainedSize);
+
+      if (sequenceIdToBfBlock.isEmpty() && !isFinished()) {
+        logger.info("[WaitForMoreTsBlock]");
+        blocked = SettableFuture.create();
+      }
+      if (isFinished()) {
+        sourceHandleListener.onFinished(this);
+      }
+      trySubmitGetDataBlocksTask();
+      return bfBlock;
+    }
+  }

Review Comment:
   Too much duplicated code with receive(), try to extract same code.



##########
server/src/main/java/org/apache/iotdb/db/service/thrift/impl/TSServiceImpl.java:
##########
@@ -315,6 +315,38 @@ public TSServiceImpl() {
     serviceProvider = IoTDB.serviceProvider;
   }
 
+  @Override
+  public TSExecuteStatementResp executeQueryStatementV2(TSExecuteStatementReq req)
+      throws TException {
+    return null;
+  }
+
+  @Override
+  public TSExecuteStatementResp executeUpdateStatementV2(TSExecuteStatementReq req)
+      throws TException {
+    return null;
+  }
+
+  @Override
+  public TSExecuteStatementResp executeStatementV2(TSExecuteStatementReq req) throws TException {
+    return null;
+  }
+
+  @Override
+  public TSExecuteStatementResp executeRawDataQueryV2(TSRawDataQueryReq req) throws TException {
+    return null;
+  }
+
+  @Override
+  public TSExecuteStatementResp executeLastDataQueryV2(TSLastDataQueryReq req) throws TException {
+    return null;
+  }
+
+  @Override
+  public TSFetchResultsResp fetchResultsV2(TSFetchResultsReq req) throws TException {
+    return null;

Review Comment:
   ```suggestion
       throw  new UnsupportedOperationException();
   ```



##########
server/src/main/java/org/apache/iotdb/db/service/thrift/impl/ClientRPCServiceImpl.java:
##########
@@ -158,6 +159,270 @@ public ClientRPCServiceImpl() {
     }
   }
 
+  @Override
+  public TSExecuteStatementResp executeQueryStatementV2(TSExecuteStatementReq req)
+      throws TException {
+    return executeStatementV2(req);
+  }
+
+  @Override
+  public TSExecuteStatementResp executeUpdateStatementV2(TSExecuteStatementReq req)
+      throws TException {
+    return executeStatementV2(req);
+  }
+
+  // To fetch required amounts of data and combine them through List
+  private List<ByteBuffer> convertQueryResultByFetchSize(
+      IQueryExecution queryExecution, int fetchSize) {
+    int rowCount = 0;
+    List<ByteBuffer> res = new LinkedList<>();
+    while (rowCount < fetchSize) {
+      try {
+        Optional<ByteBuffer> optionalByteBuffer = queryExecution.getByteBufferBatchResult();
+        if (!optionalByteBuffer.isPresent()) {
+          break;
+        }
+
+        ByteBuffer byteBuffer = optionalByteBuffer.get();
+        byteBuffer.mark();
+        int valueColumnCount = byteBuffer.getInt();
+        if (valueColumnCount == 0) {
+          continue;
+        }
+        for (int i = 0; i < valueColumnCount; i++) {
+          byteBuffer.get();
+        }
+        int positionCount = byteBuffer.getInt();
+        byteBuffer.reset();
+
+        res.add(byteBuffer);
+        rowCount += positionCount;
+
+      } catch (IoTDBException e) {
+        throw new RuntimeException(e);
+      }
+    }
+    return res;
+  }
+
+  @Override
+  public TSExecuteStatementResp executeStatementV2(TSExecuteStatementReq req) throws TException {

Review Comment:
   extract common codes.



##########
server/src/main/java/org/apache/iotdb/db/service/thrift/impl/ClientRPCServiceImpl.java:
##########
@@ -158,6 +159,270 @@ public ClientRPCServiceImpl() {
     }
   }
 
+  @Override
+  public TSExecuteStatementResp executeQueryStatementV2(TSExecuteStatementReq req)
+      throws TException {
+    return executeStatementV2(req);
+  }
+
+  @Override
+  public TSExecuteStatementResp executeUpdateStatementV2(TSExecuteStatementReq req)
+      throws TException {
+    return executeStatementV2(req);
+  }
+
+  // To fetch required amounts of data and combine them through List
+  private List<ByteBuffer> convertQueryResultByFetchSize(
+      IQueryExecution queryExecution, int fetchSize) {
+    int rowCount = 0;
+    List<ByteBuffer> res = new LinkedList<>();
+    while (rowCount < fetchSize) {
+      try {
+        Optional<ByteBuffer> optionalByteBuffer = queryExecution.getByteBufferBatchResult();
+        if (!optionalByteBuffer.isPresent()) {
+          break;
+        }
+
+        ByteBuffer byteBuffer = optionalByteBuffer.get();
+        byteBuffer.mark();
+        int valueColumnCount = byteBuffer.getInt();
+        if (valueColumnCount == 0) {
+          continue;
+        }
+        for (int i = 0; i < valueColumnCount; i++) {
+          byteBuffer.get();
+        }
+        int positionCount = byteBuffer.getInt();
+        byteBuffer.reset();
+
+        res.add(byteBuffer);
+        rowCount += positionCount;
+
+      } catch (IoTDBException e) {
+        throw new RuntimeException(e);
+      }
+    }
+    return res;
+  }
+
+  @Override
+  public TSExecuteStatementResp executeStatementV2(TSExecuteStatementReq req) throws TException {
+    String statement = req.getStatement();
+    if (!SESSION_MANAGER.checkLogin(req.getSessionId())) {
+      return RpcUtils.getTSExecuteStatementResp(getNotLoggedInStatus());
+    }
+
+    long startTime = System.currentTimeMillis();
+    try {
+      Statement s =
+          StatementGenerator.createStatement(
+              statement, SESSION_MANAGER.getZoneId(req.getSessionId()));
+
+      if (s == null) {
+        return RpcUtils.getTSExecuteStatementResp(
+            RpcUtils.getStatus(
+                TSStatusCode.SQL_PARSE_ERROR, "This operation type is not supported"));
+      }
+      // permission check
+      TSStatus status = AuthorityChecker.checkAuthority(s, req.sessionId);
+      if (status.getCode() != TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
+        return RpcUtils.getTSExecuteStatementResp(status);
+      }
+
+      QUERY_FREQUENCY_RECORDER.incrementAndGet();
+      AUDIT_LOGGER.debug("Session {} execute Query: {}", req.sessionId, statement);
+
+      long queryId = SESSION_MANAGER.requestQueryId(req.statementId, true);
+      // create and cache dataset
+      ExecutionResult result =
+          COORDINATOR.execute(
+              s,
+              queryId,
+              SESSION_MANAGER.getSessionInfo(req.sessionId),
+              statement,
+              PARTITION_FETCHER,
+              SCHEMA_FETCHER,
+              req.getTimeout());
+
+      if (result.status.code != TSStatusCode.SUCCESS_STATUS.getStatusCode()
+          && result.status.code != TSStatusCode.NEED_REDIRECTION.getStatusCode()) {
+        return RpcUtils.getTSExecuteStatementResp(result.status);
+      }
+
+      IQueryExecution queryExecution = COORDINATOR.getQueryExecution(queryId);
+
+      try (SetThreadName threadName = new SetThreadName(result.queryId.getId())) {
+        TSExecuteStatementResp resp;
+        if (queryExecution != null && queryExecution.isQuery()) {
+          resp = createResponse(queryExecution.getDatasetHeader(), queryId);
+          resp.setStatus(result.status);
+          resp.setQueryResult(convertQueryResultByFetchSize(queryExecution, req.getFetchSize()));
+        } else {
+          resp = RpcUtils.getTSExecuteStatementResp(result.status);
+        }
+        return resp;
+      }
+    } catch (Exception e) {
+      return RpcUtils.getTSExecuteStatementResp(
+          onQueryException(e, "\"" + statement + "\". " + OperationType.EXECUTE_STATEMENT));
+    } finally {
+      addOperationLatency(Operation.EXECUTE_QUERY, startTime);
+      long costTime = System.currentTimeMillis() - startTime;
+      if (costTime >= CONFIG.getSlowQueryThreshold()) {
+        SLOW_SQL_LOGGER.info("Cost: {} ms, sql is {}", costTime, statement);
+      }
+    }
+  }
+
+  @Override
+  public TSExecuteStatementResp executeRawDataQueryV2(TSRawDataQueryReq req) throws TException {

Review Comment:
   extract common codes.



##########
server/src/main/java/org/apache/iotdb/db/service/thrift/impl/ClientRPCServiceImpl.java:
##########
@@ -158,6 +159,270 @@ public ClientRPCServiceImpl() {
     }
   }
 
+  @Override
+  public TSExecuteStatementResp executeQueryStatementV2(TSExecuteStatementReq req)
+      throws TException {
+    return executeStatementV2(req);
+  }
+
+  @Override
+  public TSExecuteStatementResp executeUpdateStatementV2(TSExecuteStatementReq req)
+      throws TException {
+    return executeStatementV2(req);
+  }
+
+  // To fetch required amounts of data and combine them through List
+  private List<ByteBuffer> convertQueryResultByFetchSize(
+      IQueryExecution queryExecution, int fetchSize) {
+    int rowCount = 0;
+    List<ByteBuffer> res = new LinkedList<>();
+    while (rowCount < fetchSize) {
+      try {
+        Optional<ByteBuffer> optionalByteBuffer = queryExecution.getByteBufferBatchResult();
+        if (!optionalByteBuffer.isPresent()) {
+          break;
+        }
+
+        ByteBuffer byteBuffer = optionalByteBuffer.get();
+        byteBuffer.mark();
+        int valueColumnCount = byteBuffer.getInt();
+        if (valueColumnCount == 0) {
+          continue;
+        }
+        for (int i = 0; i < valueColumnCount; i++) {
+          byteBuffer.get();
+        }
+        int positionCount = byteBuffer.getInt();
+        byteBuffer.reset();
+
+        res.add(byteBuffer);
+        rowCount += positionCount;
+
+      } catch (IoTDBException e) {
+        throw new RuntimeException(e);

Review Comment:
   Don't use `RuntimeException`, just rethrow it.



##########
service-rpc/src/main/java/org/apache/iotdb/rpc/IoTDBRpcDataSet.java:
##########
@@ -69,11 +64,14 @@ public class IoTDBRpcDataSet {
   public long statementId;
   public boolean ignoreTimeStamp;
 
-  public int rowsIndex = 0; // used to record the row index in current TSQueryDataSet
-
-  public TSQueryDataSet tsQueryDataSet = null;
-  public byte[] time; // used to cache the current time value
-  public byte[] currentBitmap; // used to cache the current bitmap for every column
+  public TsBlockSerde serde;

Review Comment:
   ```suggestion
     public final static TsBlockSerde serde = new TsBlockSerde();
   ```



##########
server/src/main/java/org/apache/iotdb/db/service/thrift/impl/ClientRPCServiceImpl.java:
##########
@@ -158,6 +159,270 @@ public ClientRPCServiceImpl() {
     }
   }
 
+  @Override
+  public TSExecuteStatementResp executeQueryStatementV2(TSExecuteStatementReq req)
+      throws TException {
+    return executeStatementV2(req);
+  }
+
+  @Override
+  public TSExecuteStatementResp executeUpdateStatementV2(TSExecuteStatementReq req)
+      throws TException {
+    return executeStatementV2(req);
+  }
+
+  // To fetch required amounts of data and combine them through List
+  private List<ByteBuffer> convertQueryResultByFetchSize(
+      IQueryExecution queryExecution, int fetchSize) {
+    int rowCount = 0;
+    List<ByteBuffer> res = new LinkedList<>();
+    while (rowCount < fetchSize) {
+      try {
+        Optional<ByteBuffer> optionalByteBuffer = queryExecution.getByteBufferBatchResult();
+        if (!optionalByteBuffer.isPresent()) {
+          break;
+        }
+
+        ByteBuffer byteBuffer = optionalByteBuffer.get();
+        byteBuffer.mark();
+        int valueColumnCount = byteBuffer.getInt();
+        if (valueColumnCount == 0) {
+          continue;
+        }
+        for (int i = 0; i < valueColumnCount; i++) {
+          byteBuffer.get();
+        }
+        int positionCount = byteBuffer.getInt();
+        byteBuffer.reset();
+
+        res.add(byteBuffer);
+        rowCount += positionCount;
+
+      } catch (IoTDBException e) {
+        throw new RuntimeException(e);
+      }
+    }
+    return res;
+  }
+
+  @Override
+  public TSExecuteStatementResp executeStatementV2(TSExecuteStatementReq req) throws TException {
+    String statement = req.getStatement();
+    if (!SESSION_MANAGER.checkLogin(req.getSessionId())) {
+      return RpcUtils.getTSExecuteStatementResp(getNotLoggedInStatus());
+    }
+
+    long startTime = System.currentTimeMillis();
+    try {
+      Statement s =
+          StatementGenerator.createStatement(
+              statement, SESSION_MANAGER.getZoneId(req.getSessionId()));
+
+      if (s == null) {
+        return RpcUtils.getTSExecuteStatementResp(
+            RpcUtils.getStatus(
+                TSStatusCode.SQL_PARSE_ERROR, "This operation type is not supported"));
+      }
+      // permission check
+      TSStatus status = AuthorityChecker.checkAuthority(s, req.sessionId);
+      if (status.getCode() != TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
+        return RpcUtils.getTSExecuteStatementResp(status);
+      }
+
+      QUERY_FREQUENCY_RECORDER.incrementAndGet();
+      AUDIT_LOGGER.debug("Session {} execute Query: {}", req.sessionId, statement);
+
+      long queryId = SESSION_MANAGER.requestQueryId(req.statementId, true);
+      // create and cache dataset
+      ExecutionResult result =
+          COORDINATOR.execute(
+              s,
+              queryId,
+              SESSION_MANAGER.getSessionInfo(req.sessionId),
+              statement,
+              PARTITION_FETCHER,
+              SCHEMA_FETCHER,
+              req.getTimeout());
+
+      if (result.status.code != TSStatusCode.SUCCESS_STATUS.getStatusCode()
+          && result.status.code != TSStatusCode.NEED_REDIRECTION.getStatusCode()) {
+        return RpcUtils.getTSExecuteStatementResp(result.status);
+      }
+
+      IQueryExecution queryExecution = COORDINATOR.getQueryExecution(queryId);
+
+      try (SetThreadName threadName = new SetThreadName(result.queryId.getId())) {
+        TSExecuteStatementResp resp;
+        if (queryExecution != null && queryExecution.isQuery()) {
+          resp = createResponse(queryExecution.getDatasetHeader(), queryId);
+          resp.setStatus(result.status);
+          resp.setQueryResult(convertQueryResultByFetchSize(queryExecution, req.getFetchSize()));
+        } else {
+          resp = RpcUtils.getTSExecuteStatementResp(result.status);
+        }
+        return resp;
+      }
+    } catch (Exception e) {
+      return RpcUtils.getTSExecuteStatementResp(
+          onQueryException(e, "\"" + statement + "\". " + OperationType.EXECUTE_STATEMENT));
+    } finally {
+      addOperationLatency(Operation.EXECUTE_QUERY, startTime);
+      long costTime = System.currentTimeMillis() - startTime;
+      if (costTime >= CONFIG.getSlowQueryThreshold()) {
+        SLOW_SQL_LOGGER.info("Cost: {} ms, sql is {}", costTime, statement);
+      }
+    }
+  }
+
+  @Override
+  public TSExecuteStatementResp executeRawDataQueryV2(TSRawDataQueryReq req) throws TException {
+    if (!SESSION_MANAGER.checkLogin(req.getSessionId())) {
+      return RpcUtils.getTSExecuteStatementResp(getNotLoggedInStatus());
+    }
+    long startTime = System.currentTimeMillis();
+    try {
+      Statement s =
+          StatementGenerator.createStatement(req, SESSION_MANAGER.getZoneId(req.getSessionId()));
+
+      // permission check
+      TSStatus status = AuthorityChecker.checkAuthority(s, req.sessionId);
+      if (status.getCode() != TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
+        return RpcUtils.getTSExecuteStatementResp(status);
+      }
+
+      QUERY_FREQUENCY_RECORDER.incrementAndGet();
+      AUDIT_LOGGER.debug("Session {} execute Raw Data Query: {}", req.sessionId, req);
+      long queryId = SESSION_MANAGER.requestQueryId(req.statementId, true);
+      // create and cache dataset
+      ExecutionResult result =
+          COORDINATOR.execute(
+              s,
+              queryId,
+              SESSION_MANAGER.getSessionInfo(req.sessionId),
+              "",
+              PARTITION_FETCHER,
+              SCHEMA_FETCHER,
+              req.getTimeout());
+
+      if (result.status.code != TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
+        throw new RuntimeException("error code: " + result.status);
+      }
+
+      IQueryExecution queryExecution = COORDINATOR.getQueryExecution(queryId);
+
+      try (SetThreadName threadName = new SetThreadName(result.queryId.getId())) {
+        TSExecuteStatementResp resp;
+        if (queryExecution.isQuery()) {
+          resp = createResponse(queryExecution.getDatasetHeader(), queryId);
+          resp.setStatus(result.status);
+          resp.setQueryResult(convertQueryResultByFetchSize(queryExecution, req.fetchSize));
+        } else {
+          resp = RpcUtils.getTSExecuteStatementResp(result.status);
+        }
+        return resp;
+      }
+    } catch (Exception e) {
+      // TODO call the coordinator to release query resource
+      return RpcUtils.getTSExecuteStatementResp(
+          onQueryException(e, "\"" + req + "\". " + OperationType.EXECUTE_RAW_DATA_QUERY));
+    } finally {
+      addOperationLatency(Operation.EXECUTE_QUERY, startTime);
+      long costTime = System.currentTimeMillis() - startTime;
+      if (costTime >= CONFIG.getSlowQueryThreshold()) {
+        SLOW_SQL_LOGGER.info("Cost: {} ms, sql is {}", costTime, req);
+      }
+    }
+  }
+
+  @Override
+  public TSExecuteStatementResp executeLastDataQueryV2(TSLastDataQueryReq req) throws TException {
+    if (!SESSION_MANAGER.checkLogin(req.getSessionId())) {
+      return RpcUtils.getTSExecuteStatementResp(getNotLoggedInStatus());
+    }
+    long startTime = System.currentTimeMillis();
+    try {
+      Statement s =
+          StatementGenerator.createStatement(req, SESSION_MANAGER.getZoneId(req.getSessionId()));
+      // permission check
+      TSStatus status = AuthorityChecker.checkAuthority(s, req.sessionId);
+      if (status.getCode() != TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
+        return RpcUtils.getTSExecuteStatementResp(status);
+      }
+      QUERY_FREQUENCY_RECORDER.incrementAndGet();
+      AUDIT_LOGGER.debug("Session {} execute Last Data Query: {}", req.sessionId, req);
+      long queryId = SESSION_MANAGER.requestQueryId(req.statementId, true);
+      // create and cache dataset
+      ExecutionResult result =
+          COORDINATOR.execute(
+              s,
+              queryId,
+              SESSION_MANAGER.getSessionInfo(req.sessionId),
+              "",
+              PARTITION_FETCHER,
+              SCHEMA_FETCHER,
+              req.getTimeout());
+
+      if (result.status.code != TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
+        throw new RuntimeException("error code: " + result.status);
+      }
+
+      IQueryExecution queryExecution = COORDINATOR.getQueryExecution(queryId);
+
+      try (SetThreadName threadName = new SetThreadName(result.queryId.getId())) {
+        TSExecuteStatementResp resp;
+        if (queryExecution.isQuery()) {
+          resp = createResponse(queryExecution.getDatasetHeader(), queryId);
+          resp.setStatus(result.status);
+          resp.setQueryResult(convertQueryResultByFetchSize(queryExecution, req.fetchSize));
+        } else {
+          resp = RpcUtils.getTSExecuteStatementResp(result.status);
+        }
+        return resp;
+      }
+
+    } catch (Exception e) {
+      // TODO call the coordinator to release query resource
+      return RpcUtils.getTSExecuteStatementResp(
+          onQueryException(e, "\"" + req + "\". " + OperationType.EXECUTE_LAST_DATA_QUERY));
+    } finally {
+      addOperationLatency(Operation.EXECUTE_QUERY, startTime);
+      long costTime = System.currentTimeMillis() - startTime;
+      if (costTime >= CONFIG.getSlowQueryThreshold()) {
+        SLOW_SQL_LOGGER.info("Cost: {} ms, sql is {}", costTime, req);
+      }
+    }
+  }
+
+  @Override
+  public TSFetchResultsResp fetchResultsV2(TSFetchResultsReq req) throws TException {

Review Comment:
   extract common codes.



##########
service-rpc/pom.xml:
##########
@@ -62,6 +62,14 @@
             <groupId>org.xerial.snappy</groupId>
             <artifactId>snappy-java</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.openjdk.jol</groupId>
+            <artifactId>jol-core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>io.airlift</groupId>
+            <artifactId>slice</artifactId>
+        </dependency>

Review Comment:
   why we need to add these dependencies?



##########
service-rpc/src/main/java/org/apache/iotdb/rpc/IoTDBRpcDataSet.java:
##########
@@ -69,11 +64,14 @@ public class IoTDBRpcDataSet {
   public long statementId;
   public boolean ignoreTimeStamp;
 
-  public int rowsIndex = 0; // used to record the row index in current TSQueryDataSet
-
-  public TSQueryDataSet tsQueryDataSet = null;
-  public byte[] time; // used to cache the current time value
-  public byte[] currentBitmap; // used to cache the current bitmap for every column
+  public TsBlockSerde serde;
+  public List<ByteBuffer> queryResult;
+  public TsBlock curTsBlock;
+  public Long time; // used to cache the current time value

Review Comment:
   ```suggestion
     public long time; // used to cache the current time value
   ```
   Actually, there is no need to save this, each time  we need to return current time, we can just get it from `curTsBlock`.



##########
server/src/main/java/org/apache/iotdb/db/service/thrift/impl/ClientRPCServiceImpl.java:
##########
@@ -158,6 +159,270 @@ public ClientRPCServiceImpl() {
     }
   }
 
+  @Override
+  public TSExecuteStatementResp executeQueryStatementV2(TSExecuteStatementReq req)
+      throws TException {
+    return executeStatementV2(req);
+  }
+
+  @Override
+  public TSExecuteStatementResp executeUpdateStatementV2(TSExecuteStatementReq req)
+      throws TException {
+    return executeStatementV2(req);
+  }
+
+  // To fetch required amounts of data and combine them through List
+  private List<ByteBuffer> convertQueryResultByFetchSize(
+      IQueryExecution queryExecution, int fetchSize) {
+    int rowCount = 0;
+    List<ByteBuffer> res = new LinkedList<>();
+    while (rowCount < fetchSize) {
+      try {
+        Optional<ByteBuffer> optionalByteBuffer = queryExecution.getByteBufferBatchResult();
+        if (!optionalByteBuffer.isPresent()) {
+          break;
+        }
+
+        ByteBuffer byteBuffer = optionalByteBuffer.get();
+        byteBuffer.mark();
+        int valueColumnCount = byteBuffer.getInt();
+        if (valueColumnCount == 0) {
+          continue;
+        }
+        for (int i = 0; i < valueColumnCount; i++) {
+          byteBuffer.get();
+        }
+        int positionCount = byteBuffer.getInt();
+        byteBuffer.reset();
+
+        res.add(byteBuffer);
+        rowCount += positionCount;
+
+      } catch (IoTDBException e) {
+        throw new RuntimeException(e);
+      }
+    }
+    return res;
+  }
+
+  @Override
+  public TSExecuteStatementResp executeStatementV2(TSExecuteStatementReq req) throws TException {
+    String statement = req.getStatement();
+    if (!SESSION_MANAGER.checkLogin(req.getSessionId())) {
+      return RpcUtils.getTSExecuteStatementResp(getNotLoggedInStatus());
+    }
+
+    long startTime = System.currentTimeMillis();
+    try {
+      Statement s =
+          StatementGenerator.createStatement(
+              statement, SESSION_MANAGER.getZoneId(req.getSessionId()));
+
+      if (s == null) {
+        return RpcUtils.getTSExecuteStatementResp(
+            RpcUtils.getStatus(
+                TSStatusCode.SQL_PARSE_ERROR, "This operation type is not supported"));
+      }
+      // permission check
+      TSStatus status = AuthorityChecker.checkAuthority(s, req.sessionId);
+      if (status.getCode() != TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
+        return RpcUtils.getTSExecuteStatementResp(status);
+      }
+
+      QUERY_FREQUENCY_RECORDER.incrementAndGet();
+      AUDIT_LOGGER.debug("Session {} execute Query: {}", req.sessionId, statement);
+
+      long queryId = SESSION_MANAGER.requestQueryId(req.statementId, true);
+      // create and cache dataset
+      ExecutionResult result =
+          COORDINATOR.execute(
+              s,
+              queryId,
+              SESSION_MANAGER.getSessionInfo(req.sessionId),
+              statement,
+              PARTITION_FETCHER,
+              SCHEMA_FETCHER,
+              req.getTimeout());
+
+      if (result.status.code != TSStatusCode.SUCCESS_STATUS.getStatusCode()
+          && result.status.code != TSStatusCode.NEED_REDIRECTION.getStatusCode()) {
+        return RpcUtils.getTSExecuteStatementResp(result.status);
+      }
+
+      IQueryExecution queryExecution = COORDINATOR.getQueryExecution(queryId);
+
+      try (SetThreadName threadName = new SetThreadName(result.queryId.getId())) {
+        TSExecuteStatementResp resp;
+        if (queryExecution != null && queryExecution.isQuery()) {
+          resp = createResponse(queryExecution.getDatasetHeader(), queryId);
+          resp.setStatus(result.status);
+          resp.setQueryResult(convertQueryResultByFetchSize(queryExecution, req.getFetchSize()));
+        } else {
+          resp = RpcUtils.getTSExecuteStatementResp(result.status);
+        }
+        return resp;
+      }
+    } catch (Exception e) {
+      return RpcUtils.getTSExecuteStatementResp(
+          onQueryException(e, "\"" + statement + "\". " + OperationType.EXECUTE_STATEMENT));
+    } finally {
+      addOperationLatency(Operation.EXECUTE_QUERY, startTime);
+      long costTime = System.currentTimeMillis() - startTime;
+      if (costTime >= CONFIG.getSlowQueryThreshold()) {
+        SLOW_SQL_LOGGER.info("Cost: {} ms, sql is {}", costTime, statement);
+      }
+    }
+  }
+
+  @Override
+  public TSExecuteStatementResp executeRawDataQueryV2(TSRawDataQueryReq req) throws TException {
+    if (!SESSION_MANAGER.checkLogin(req.getSessionId())) {
+      return RpcUtils.getTSExecuteStatementResp(getNotLoggedInStatus());
+    }
+    long startTime = System.currentTimeMillis();
+    try {
+      Statement s =
+          StatementGenerator.createStatement(req, SESSION_MANAGER.getZoneId(req.getSessionId()));
+
+      // permission check
+      TSStatus status = AuthorityChecker.checkAuthority(s, req.sessionId);
+      if (status.getCode() != TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
+        return RpcUtils.getTSExecuteStatementResp(status);
+      }
+
+      QUERY_FREQUENCY_RECORDER.incrementAndGet();
+      AUDIT_LOGGER.debug("Session {} execute Raw Data Query: {}", req.sessionId, req);
+      long queryId = SESSION_MANAGER.requestQueryId(req.statementId, true);
+      // create and cache dataset
+      ExecutionResult result =
+          COORDINATOR.execute(
+              s,
+              queryId,
+              SESSION_MANAGER.getSessionInfo(req.sessionId),
+              "",
+              PARTITION_FETCHER,
+              SCHEMA_FETCHER,
+              req.getTimeout());
+
+      if (result.status.code != TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
+        throw new RuntimeException("error code: " + result.status);
+      }
+
+      IQueryExecution queryExecution = COORDINATOR.getQueryExecution(queryId);
+
+      try (SetThreadName threadName = new SetThreadName(result.queryId.getId())) {
+        TSExecuteStatementResp resp;
+        if (queryExecution.isQuery()) {
+          resp = createResponse(queryExecution.getDatasetHeader(), queryId);
+          resp.setStatus(result.status);
+          resp.setQueryResult(convertQueryResultByFetchSize(queryExecution, req.fetchSize));
+        } else {
+          resp = RpcUtils.getTSExecuteStatementResp(result.status);
+        }
+        return resp;
+      }
+    } catch (Exception e) {
+      // TODO call the coordinator to release query resource
+      return RpcUtils.getTSExecuteStatementResp(
+          onQueryException(e, "\"" + req + "\". " + OperationType.EXECUTE_RAW_DATA_QUERY));
+    } finally {
+      addOperationLatency(Operation.EXECUTE_QUERY, startTime);
+      long costTime = System.currentTimeMillis() - startTime;
+      if (costTime >= CONFIG.getSlowQueryThreshold()) {
+        SLOW_SQL_LOGGER.info("Cost: {} ms, sql is {}", costTime, req);
+      }
+    }
+  }
+
+  @Override
+  public TSExecuteStatementResp executeLastDataQueryV2(TSLastDataQueryReq req) throws TException {

Review Comment:
   extract common codes.



##########
server/src/main/java/org/apache/iotdb/db/mpp/execution/exchange/SourceHandle.java:
##########
@@ -66,8 +66,8 @@ public class SourceHandle implements ISourceHandle {
   private final TsBlockSerde serde;
   private final SourceHandleListener sourceHandleListener;
 
-  private final Map<Integer, TsBlock> sequenceIdToTsBlock = new HashMap<>();
   private final Map<Integer, Long> sequenceIdToDataBlockSize = new HashMap<>();
+  private final Map<Integer, ByteBuffer> sequenceIdToBfBlock = new HashMap<>();

Review Comment:
   ```suggestion
     private final Map<Integer, ByteBuffer> sequenceIdToTsBlock = new HashMap<>();
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] JackieTien97 merged pull request #7613: [IOTDB-3936]Add an interface in IClientRPCService to directly return bytebuffer instead of TSQueryDataSet

Posted by GitBox <gi...@apache.org>.
JackieTien97 merged PR #7613:
URL: https://github.com/apache/iotdb/pull/7613


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] ycycse commented on pull request #7613: [IOTDB-3936]Add an interface in IClientRPCService to directly return bytebuffer instead of TSQueryDataSet

Posted by GitBox <gi...@apache.org>.
ycycse commented on PR #7613:
URL: https://github.com/apache/iotdb/pull/7613#issuecomment-1287684998

   In the modification in jdbc client. Besides some regular change which is simirlar as session client, I rewrite the codes in IoTDBDatabaseMetadata for the new structure of IoTDBJDBCResultSet.
   The workflow in the former code is:
   1. get the type-value data in the form of List<List<map>> from List data of tsDataType and value.
   2. addToDataSet() method change the map into the form of rowRecord and generate ListData.
   3. use convertQueryDataSetByFetchSize() to transfer ListData into TsQueryDataSet.
   Now the new workflow is following:
   1. send the List data of tsDataType and value to convertTsBlock()
   2. convertTsBlock() generate the TsBlock directly through TsBlockBuilder


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] ycycse commented on pull request #7613: [IOTDB-3936]Add an interface in IClientRPCService to directly return bytebuffer instead of TSQueryDataSet

Posted by GitBox <gi...@apache.org>.
ycycse commented on PR #7613:
URL: https://github.com/apache/iotdb/pull/7613#issuecomment-1280010727

   The new method was tested in stand-alone and distributed environment. The stand-alone environment tested the LocalSourceHandle and the distributed one tested the SourceHandle. Details in https://apache-iotdb.feishu.cn/docx/ETLLdse6koirtTxB5zOcHt1jnpc
   ![exp_res](https://user-images.githubusercontent.com/51467236/196048126-96e37b9c-786c-4880-be11-648953f38bc8.jpg)
   The result shows for SourceHandle which saves a deserialization and a serialization gets better performance. And results for LocalSourceHandle with a extra deserialization maintains the performance comparing with the old method.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org