You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ja...@apache.org on 2020/05/12 03:22:16 UTC

[incubator-iotdb] branch TyDatasetOptimize created (now 16c9ffc)

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

jackietien pushed a change to branch TyDatasetOptimize
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git.


      at 16c9ffc  optimize contruct dataset values array logic

This branch includes the following new commits:

     new 16c9ffc  optimize contruct dataset values array logic

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[incubator-iotdb] 01/01: optimize contruct dataset values array logic

Posted by ja...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 16c9ffc1d47e13cb9709e87d438abb9b298378e2
Author: JackieTien97 <Ja...@foxmail.com>
AuthorDate: Tue May 12 11:21:08 2020 +0800

    optimize contruct dataset values array logic
---
 .../java/org/apache/iotdb/rpc/IoTDBRpcDataSet.java | 68 +++++++++++-----------
 1 file changed, 35 insertions(+), 33 deletions(-)

diff --git a/service-rpc/src/main/java/org/apache/iotdb/rpc/IoTDBRpcDataSet.java b/service-rpc/src/main/java/org/apache/iotdb/rpc/IoTDBRpcDataSet.java
index 0ae79f6..25c5879 100644
--- a/service-rpc/src/main/java/org/apache/iotdb/rpc/IoTDBRpcDataSet.java
+++ b/service-rpc/src/main/java/org/apache/iotdb/rpc/IoTDBRpcDataSet.java
@@ -81,7 +81,6 @@ public class IoTDBRpcDataSet {
     this.client = client;
     this.fetchSize = fetchSize;
     this.columnNameList = columnNameList;
-    currentBitmap = new byte[columnNameList.size()];
     columnSize = columnNameList.size();
 
     this.columnNameList = new ArrayList<>();
@@ -123,8 +122,35 @@ public class IoTDBRpcDataSet {
     }
 
     time = new byte[Long.BYTES];
-    currentBitmap = new byte[columnNameList.size()];
-    values = new byte[columnNameList.size()][];
+    currentBitmap = new byte[columnTypeDeduplicatedList.size()];
+    values = new byte[columnTypeDeduplicatedList.size()][];
+    for (int i = 0; i < values.length; i++) {
+      TSDataType dataType = columnTypeDeduplicatedList.get(i);
+      switch (dataType) {
+        case BOOLEAN:
+          values[i] = new byte[1];
+          break;
+        case INT32:
+          values[i] = new byte[Integer.BYTES];
+          break;
+        case INT64:
+          values[i] = new byte[Long.BYTES];
+          break;
+        case FLOAT:
+          values[i] = new byte[Float.BYTES];
+          break;
+        case DOUBLE:
+          values[i] = new byte[Double.BYTES];
+          break;
+        case TEXT:
+          values[i] = null;
+          break;
+        default:
+          throw new UnSupportedDataTypeException(
+              String
+                  .format("Data type %s is not supported.", columnTypeDeduplicatedList.get(i)));
+      }
+    }
     this.tsQueryDataSet = queryDataSet;
   }
 
@@ -195,39 +221,15 @@ public class IoTDBRpcDataSet {
       if (rowsIndex % 8 == 0) {
         currentBitmap[i] = bitmapBuffer.get();
       }
-      values[i] = null;
       if (!isNull(i, rowsIndex)) {
         ByteBuffer valueBuffer = tsQueryDataSet.valueList.get(i);
         TSDataType dataType = columnTypeDeduplicatedList.get(i);
         switch (dataType) {
           case BOOLEAN:
-            if (values[i] == null) {
-              values[i] = new byte[1];
-            }
-            valueBuffer.get(values[i]);
-            break;
           case INT32:
-            if (values[i] == null) {
-              values[i] = new byte[Integer.BYTES];
-            }
-            valueBuffer.get(values[i]);
-            break;
           case INT64:
-            if (values[i] == null) {
-              values[i] = new byte[Long.BYTES];
-            }
-            valueBuffer.get(values[i]);
-            break;
           case FLOAT:
-            if (values[i] == null) {
-              values[i] = new byte[Float.BYTES];
-            }
-            valueBuffer.get(values[i]);
-            break;
           case DOUBLE:
-            if (values[i] == null) {
-              values[i] = new byte[Double.BYTES];
-            }
             valueBuffer.get(values[i]);
             break;
           case TEXT:
@@ -258,7 +260,7 @@ public class IoTDBRpcDataSet {
   public boolean getBoolean(String columnName) throws StatementExecutionException {
     checkRecord();
     int index = columnOrdinalMap.get(columnName) - START_INDEX;
-    if (values[index] != null) {
+    if (!isNull(index, rowsIndex-1)) {
       return BytesUtils.bytesToBool(values[index]);
     } else {
       throw new StatementExecutionException(String.format(VALUE_IS_NULL, columnName));
@@ -272,7 +274,7 @@ public class IoTDBRpcDataSet {
   public double getDouble(String columnName) throws StatementExecutionException {
     checkRecord();
     int index = columnOrdinalMap.get(columnName) - START_INDEX;
-    if (values[index] != null) {
+    if (!isNull(index, rowsIndex-1)) {
       return BytesUtils.bytesToDouble(values[index]);
     } else {
       throw new StatementExecutionException(String.format(VALUE_IS_NULL, columnName));
@@ -286,7 +288,7 @@ public class IoTDBRpcDataSet {
   public float getFloat(String columnName) throws StatementExecutionException {
     checkRecord();
     int index = columnOrdinalMap.get(columnName) - START_INDEX;
-    if (values[index] != null) {
+    if (!isNull(index, rowsIndex-1)) {
       return BytesUtils.bytesToFloat(values[index]);
     } else {
       throw new StatementExecutionException(String.format(VALUE_IS_NULL, columnName));
@@ -300,7 +302,7 @@ public class IoTDBRpcDataSet {
   public int getInt(String columnName) throws StatementExecutionException {
     checkRecord();
     int index = columnOrdinalMap.get(columnName) - START_INDEX;
-    if (values[index] != null) {
+    if (!isNull(index, rowsIndex-1)) {
       return BytesUtils.bytesToInt(values[index]);
     } else {
       throw new StatementExecutionException(String.format(VALUE_IS_NULL, columnName));
@@ -317,7 +319,7 @@ public class IoTDBRpcDataSet {
       return BytesUtils.bytesToLong(time);
     }
     int index = columnOrdinalMap.get(columnName) - START_INDEX;
-    if (values[index] != null) {
+    if (!isNull(index, rowsIndex-1)) {
       return BytesUtils.bytesToLong(values[index]);
     } else {
       throw new StatementExecutionException(String.format(VALUE_IS_NULL, columnName));
@@ -358,7 +360,7 @@ public class IoTDBRpcDataSet {
       return String.valueOf(BytesUtils.bytesToLong(time));
     }
     int index = columnOrdinalMap.get(columnName) - START_INDEX;
-    if (index < 0 || index >= values.length || values[index] == null) {
+    if (index < 0 || index >= values.length || isNull(index, rowsIndex-1)) {
       return null;
     }
     return getString(index, columnTypeDeduplicatedList.get(index), values);