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

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


The following commit(s) were added to refs/heads/serialize-physicalplan by this 
push:
     new b7ac301  remove ByteBufferUtils and use ReadWriteIOUtils
b7ac301 is described below

commit b7ac301317619382ff70f2c94b0b7ca898e4b313
Author: lta <[email protected]>
AuthorDate: Thu Mar 28 11:56:22 2019 +0800

    remove ByteBufferUtils and use ReadWriteIOUtils
---
 .../iotdb/db/qp/logical/sys/AuthorOperator.java    |   2 +-
 .../iotdb/db/qp/logical/sys/PropertyOperator.java  |   2 +-
 .../org/apache/iotdb/db/utils/ByteBufferUtils.java |  59 -------
 .../iotdb/db/writelog/transfer/CodecInstances.java | 182 +++++++++++++++------
 4 files changed, 133 insertions(+), 112 deletions(-)

diff --git 
a/iotdb/src/main/java/org/apache/iotdb/db/qp/logical/sys/AuthorOperator.java 
b/iotdb/src/main/java/org/apache/iotdb/db/qp/logical/sys/AuthorOperator.java
index 65a17d4..b2bb858 100644
--- a/iotdb/src/main/java/org/apache/iotdb/db/qp/logical/sys/AuthorOperator.java
+++ b/iotdb/src/main/java/org/apache/iotdb/db/qp/logical/sys/AuthorOperator.java
@@ -205,7 +205,7 @@ public class AuthorOperator extends RootOperator {
         case LIST_ROLE_USERS:
           return 16;
           default:
-          return 0;
+          return -1;
       }
     }
   }
diff --git 
a/iotdb/src/main/java/org/apache/iotdb/db/qp/logical/sys/PropertyOperator.java 
b/iotdb/src/main/java/org/apache/iotdb/db/qp/logical/sys/PropertyOperator.java
index 6a6ae4c..b4309b1 100644
--- 
a/iotdb/src/main/java/org/apache/iotdb/db/qp/logical/sys/PropertyOperator.java
+++ 
b/iotdb/src/main/java/org/apache/iotdb/db/qp/logical/sys/PropertyOperator.java
@@ -99,7 +99,7 @@ public class PropertyOperator extends RootOperator {
         case DEL_PROPERTY_FROM_METADATA:
           return 4;
         default:
-          return 0;
+          return -1;
       }
     }
   }
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/utils/ByteBufferUtils.java 
b/iotdb/src/main/java/org/apache/iotdb/db/utils/ByteBufferUtils.java
deleted file mode 100644
index 0035847..0000000
--- a/iotdb/src/main/java/org/apache/iotdb/db/utils/ByteBufferUtils.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.iotdb.db.utils;
-
-import java.nio.ByteBuffer;
-import org.apache.iotdb.tsfile.utils.BytesUtils;
-
-public class ByteBufferUtils {
-
-  /**
-   * Put a string to ByteBuffer, first put a int which represents the bytes 
len of string, then put
-   * the bytes of string to ByteBuffer
-   *
-   * @param buffer Target ByteBuffer to put a string value
-   * @param value String value to be put
-   */
-  public static void putString(ByteBuffer buffer, String value) {
-    if(value == null){
-      buffer.putInt(-1);
-    }else{
-      byte[] vBytes = BytesUtils.stringToBytes(value);
-      buffer.putInt(vBytes.length);
-      buffer.put(vBytes);
-    }
-  }
-
-  /**
-   * Read a string value from ByteBuffer, first read a int that represents the 
bytes len of string,
-   * then read bytes len value, finally transfer bytes to string
-   *
-   * @param buffer ByteBuffer to be read
-   * @return string value
-   */
-  public static String readString(ByteBuffer buffer) {
-    int valueLen = buffer.getInt();
-    if(valueLen == -1)
-      return null;
-    byte[] valueBytes = new byte[valueLen];
-    buffer.get(valueBytes);
-    return BytesUtils.bytesToString(valueBytes);
-  }
-
-}
diff --git 
a/iotdb/src/main/java/org/apache/iotdb/db/writelog/transfer/CodecInstances.java 
b/iotdb/src/main/java/org/apache/iotdb/db/writelog/transfer/CodecInstances.java
index 6e7ebda..c3851d1 100644
--- 
a/iotdb/src/main/java/org/apache/iotdb/db/writelog/transfer/CodecInstances.java
+++ 
b/iotdb/src/main/java/org/apache/iotdb/db/writelog/transfer/CodecInstances.java
@@ -41,12 +41,12 @@ import org.apache.iotdb.db.qp.physical.sys.AuthorPlan;
 import org.apache.iotdb.db.qp.physical.sys.LoadDataPlan;
 import org.apache.iotdb.db.qp.physical.sys.MetadataPlan;
 import org.apache.iotdb.db.qp.physical.sys.PropertyPlan;
-import org.apache.iotdb.db.utils.ByteBufferUtils;
 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.Path;
 import org.apache.iotdb.tsfile.utils.Pair;
+import org.apache.iotdb.tsfile.utils.ReadWriteIOUtils;
 
 public class CodecInstances {
 
@@ -55,6 +55,36 @@ public class CodecInstances {
   private CodecInstances() {
   }
 
+
+  /**
+   * Put a string to ByteBuffer, first put a int which represents the bytes 
len of string, then put
+   * the bytes of string to ByteBuffer, string may be null
+   *
+   * @param buffer Target ByteBuffer to put a string value
+   * @param value String value to be put
+   */
+  static void putString(ByteBuffer buffer, String value) {
+    if(value == null){
+      buffer.putInt(-1);
+    }else{
+      ReadWriteIOUtils.write(value, buffer);
+    }
+  }
+
+  /**
+   * Read a string value from ByteBuffer, first read a int that represents the 
bytes len of string,
+   * then read bytes len value, finally transfer bytes to string, string may 
be null
+   *
+   * @param buffer ByteBuffer to be read
+   * @return string value
+   */
+  static String readString(ByteBuffer buffer) {
+    int valueLen = buffer.getInt();
+    if(valueLen == -1)
+      return null;
+    return ReadWriteIOUtils.readStringWithoutLength(buffer, valueLen);
+  }
+  
   static final Codec<DeletePlan> deletePlanCodec = new Codec<DeletePlan>() {
     ThreadLocal<ByteBuffer> localBuffer = new ThreadLocal<>();
 
@@ -69,7 +99,7 @@ public class CodecInstances {
       buffer.clear();
       buffer.put((byte) type);
       buffer.putLong(t.getDeleteTime());
-      ByteBufferUtils.putString(buffer, t.getPaths().get(0).getFullPath());
+      putString(buffer, t.getPaths().get(0).getFullPath());
 
       return Arrays.copyOfRange(buffer.array(), 0, buffer.position());
     }
@@ -80,7 +110,7 @@ public class CodecInstances {
       buffer.get(); // read  and skip an int representing "type".
       long time = buffer.getLong();
 
-      String path = ByteBufferUtils.readString(buffer);
+      String path = readString(buffer);
 
       return new DeletePlan(time, new Path(path));
     }
@@ -105,8 +135,8 @@ public class CodecInstances {
         buffer.putLong(pair.right);
       }
 
-      ByteBufferUtils.putString(buffer, updatePlan.getValue());
-      ByteBufferUtils.putString(buffer, updatePlan.getPath().getFullPath());
+      putString(buffer, updatePlan.getValue());
+      putString(buffer, updatePlan.getPath().getFullPath());
 
       return Arrays.copyOfRange(buffer.array(), 0, buffer.position());
     }
@@ -124,8 +154,8 @@ public class CodecInstances {
         timeArrayList.add(new Pair<>(startTime, endTime));
       }
 
-      String value = ByteBufferUtils.readString(buffer);
-      String path = ByteBufferUtils.readString(buffer);
+      String value = readString(buffer);
+      String path = readString(buffer);
 
       return new UpdatePlan(timeArrayList, value, new Path(path));
     }
@@ -146,18 +176,18 @@ public class CodecInstances {
       buffer.put((byte) plan.getInsertType());
       buffer.putLong(plan.getTime());
 
-      ByteBufferUtils.putString(buffer, plan.getDeviceId());
+      putString(buffer, plan.getDeviceId());
 
       List<String> measurementList = plan.getMeasurements();
       buffer.putInt(measurementList.size());
       for (String m : measurementList) {
-        ByteBufferUtils.putString(buffer, m);
+        putString(buffer, m);
       }
 
       List<String> valueList = plan.getValues();
       buffer.putInt(valueList.size());
       for (String m : valueList) {
-        ByteBufferUtils.putString(buffer, m);
+        putString(buffer, m);
       }
 
       return Arrays.copyOfRange(buffer.array(), 0, buffer.position());
@@ -171,18 +201,18 @@ public class CodecInstances {
       int insertType = buffer.get();
       long time = buffer.getLong();
 
-      String device = ByteBufferUtils.readString(buffer);
+      String device = readString(buffer);
 
       int mmListLength = buffer.getInt();
       List<String> measurementsList = new ArrayList<>(mmListLength);
       for (int i = 0; i < mmListLength; i++) {
-        measurementsList.add(ByteBufferUtils.readString(buffer));
+        measurementsList.add(readString(buffer));
       }
 
       int valueListLength = buffer.getInt();
       List<String> valuesList = new ArrayList<>(valueListLength);
       for (int i = 0; i < valueListLength; i++) {
-        valuesList.add(ByteBufferUtils.readString(buffer));
+        valuesList.add(readString(buffer));
       }
 
       InsertPlan ans = new InsertPlan(device, time, measurementsList, 
valuesList);
@@ -203,13 +233,37 @@ public class CodecInstances {
       ByteBuffer buffer = localBuffer.get();
       buffer.clear();
       buffer.put((byte) type);
-      buffer.put((byte) plan.getNamespaceType().serialize());
-      buffer.put((byte) plan.getDataType().serialize());
-      buffer.put((byte) plan.getCompressor().serialize());
-      buffer.put((byte) plan.getEncoding().serialize());
+
+      MetadataOperator.NamespaceType namespaceType = plan.getNamespaceType();
+      if (namespaceType != null) {
+        buffer.put((byte) plan.getNamespaceType().serialize());
+      } else {
+        buffer.put((byte) -1);
+      }
+
+      TSDataType dataType = plan.getDataType();
+      if (dataType != null) {
+        buffer.put((byte) plan.getDataType().serialize());
+      } else {
+        buffer.put((byte) -1);
+      }
+
+      CompressionType compressionType = plan.getCompressor();
+      if (compressionType != null) {
+        buffer.put((byte) plan.getCompressor().serialize());
+      } else {
+        buffer.put((byte) -1);
+      }
+
+      TSEncoding tsEncoding = plan.getEncoding();
+      if (tsEncoding != null) {
+        buffer.put((byte) plan.getEncoding().serialize());
+      } else {
+        buffer.put((byte) -1);
+      }
 
       String path = plan.getPath().toString();
-      ByteBufferUtils.putString(buffer, path);
+      putString(buffer, path);
 
       List<Path> deletePathList = plan.getDeletePathList();
       if (deletePathList == null) {
@@ -217,15 +271,19 @@ public class CodecInstances {
       } else {
         buffer.putInt(deletePathList.size());
         for (Path deletePath : deletePathList) {
-          ByteBufferUtils.putString(buffer, deletePath.toString());
+          putString(buffer, deletePath.toString());
         }
       }
 
       Map<String, String> props = plan.getProps();
-      buffer.putInt(props.size());
-      for (Entry<String, String> entry : props.entrySet()) {
-        ByteBufferUtils.putString(buffer, entry.getKey());
-        ByteBufferUtils.putString(buffer, entry.getValue());
+      if (props != null) {
+        buffer.putInt(props.size());
+        for (Entry<String, String> entry : props.entrySet()) {
+          putString(buffer, entry.getKey());
+          putString(buffer, entry.getValue());
+        }
+      } else {
+        buffer.putInt(-1);
       }
 
       return Arrays.copyOfRange(buffer.array(), 0, buffer.position());
@@ -237,26 +295,48 @@ public class CodecInstances {
 
       buffer.get(); // read and skip an int representing "type"
 
-      MetadataOperator.NamespaceType namespaceType = 
MetadataOperator.NamespaceType
-          .deserialize(buffer.get());
-      TSDataType dataType = TSDataType.deserialize(buffer.get());
-      CompressionType compressor = CompressionType.deserialize(buffer.get());
-      TSEncoding encoding = TSEncoding.deserialize(buffer.get());
+      byte namespaceTypeByte = buffer.get();
+      MetadataOperator.NamespaceType namespaceType = null;
+      if (namespaceTypeByte != -1) {
+        namespaceType = MetadataOperator.NamespaceType
+            .deserialize(namespaceTypeByte);
+      }
 
-      String path = ByteBufferUtils.readString(buffer);
+      byte dataTypeByte = buffer.get();
+      TSDataType dataType = null;
+      if (dataTypeByte != -1) {
+        dataType = TSDataType.deserialize(dataTypeByte);
+      }
+
+      byte compressorByte = buffer.get();
+      CompressionType compressor = null;
+      if (compressorByte != -1) {
+        compressor = CompressionType.deserialize(compressorByte);
+      }
+
+      byte encodingByte = buffer.get();
+      TSEncoding encoding = null;
+      if (compressorByte != -1) {
+        encoding = TSEncoding.deserialize(encodingByte);
+      }
+
+      String path = readString(buffer);
       int pathListLen = buffer.getInt();
       List<Path> deletePathList = null;
       if (pathListLen != -1) {
         deletePathList = new ArrayList<>(pathListLen);
         for (int i = 0; i < pathListLen; i++) {
-          deletePathList.add(new Path(ByteBufferUtils.readString(buffer)));
+          deletePathList.add(new Path(readString(buffer)));
         }
       }
 
       int propsLen = buffer.getInt();
-      Map<String, String> props = new HashMap<>(propsLen);
-      for (int i = 0; i < propsLen; i++) {
-        props.put(ByteBufferUtils.readString(buffer), 
ByteBufferUtils.readString(buffer));
+      Map<String, String> props = null;
+      if (propsLen != -1) {
+        props = new HashMap<>(propsLen);
+        for (int i = 0; i < propsLen; i++) {
+          props.put(readString(buffer), readString(buffer));
+        }
       }
 
       return new MetadataPlan(namespaceType, new Path(path), dataType, 
compressor, encoding, props,
@@ -280,11 +360,11 @@ public class CodecInstances {
       int authorType = plan.getAuthorType().serialize();
       buffer.put((byte) authorType);
 
-      ByteBufferUtils.putString(buffer, plan.getUserName());
-      ByteBufferUtils.putString(buffer, plan.getRoleName());
-      ByteBufferUtils.putString(buffer, plan.getPassword());
-      ByteBufferUtils.putString(buffer, plan.getNewPassword());
-      ByteBufferUtils.putString(buffer, plan.getNodeName().toString());
+      putString(buffer, plan.getUserName());
+      putString(buffer, plan.getRoleName());
+      putString(buffer, plan.getPassword());
+      putString(buffer, plan.getNewPassword());
+      putString(buffer, plan.getNodeName().toString());
 
       Set<Integer> permissions = plan.getPermissions();
       if (permissions == null) {
@@ -305,11 +385,11 @@ public class CodecInstances {
       buffer.get(); // read and skip an int representing "type"
 
       AuthorOperator.AuthorType authorType = 
AuthorOperator.AuthorType.deserialize(buffer.get());
-      String userName = ByteBufferUtils.readString(buffer);
-      String roleName = ByteBufferUtils.readString(buffer);
-      String password = ByteBufferUtils.readString(buffer);
-      String newPassword = ByteBufferUtils.readString(buffer);
-      Path nodeName = new Path(ByteBufferUtils.readString(buffer));
+      String userName = readString(buffer);
+      String roleName = readString(buffer);
+      String password = readString(buffer);
+      String newPassword = readString(buffer);
+      Path nodeName = new Path(readString(buffer));
       Set<Integer> permissions = null;
       int permissionListLen = buffer.getInt();
       if (permissionListLen != -1) {
@@ -343,8 +423,8 @@ public class CodecInstances {
       buffer.clear();
       buffer.put((byte) type);
 
-      ByteBufferUtils.putString(buffer, plan.getInputFilePath());
-      ByteBufferUtils.putString(buffer, plan.getMeasureType());
+      putString(buffer, plan.getInputFilePath());
+      putString(buffer, plan.getMeasureType());
 
       return Arrays.copyOfRange(buffer.array(), 0, buffer.position());
     }
@@ -355,8 +435,8 @@ public class CodecInstances {
 
       buffer.get(); // read and skip an int representing "type"
 
-      String inputFilePath = ByteBufferUtils.readString(buffer);
-      String measureType = ByteBufferUtils.readString(buffer);
+      String inputFilePath = readString(buffer);
+      String measureType = readString(buffer);
       return new LoadDataPlan(inputFilePath, measureType);
     }
   };
@@ -379,8 +459,8 @@ public class CodecInstances {
 
       Path metadataPath = plan.getMetadataPath();
       Path propertyPath = plan.getPropertyPath();
-      ByteBufferUtils.putString(buffer, metadataPath == null ? null : 
metadataPath.toString());
-      ByteBufferUtils.putString(buffer, propertyPath == null ? null : 
propertyPath.toString());
+      putString(buffer, metadataPath == null ? null : metadataPath.toString());
+      putString(buffer, propertyPath == null ? null : propertyPath.toString());
 
       return Arrays.copyOfRange(buffer.array(), 0, buffer.position());
     }
@@ -393,8 +473,8 @@ public class CodecInstances {
 
       PropertyOperator.PropertyType propertyType = 
PropertyOperator.PropertyType
           .deserialize(buffer.get());
-      String metadataPath = ByteBufferUtils.readString(buffer);
-      String propertyPath = ByteBufferUtils.readString(buffer);
+      String metadataPath = readString(buffer);
+      String propertyPath = readString(buffer);
       return new PropertyPlan(propertyType, propertyPath == null ? null : new 
Path(propertyPath),
           metadataPath == null ? null : new Path(metadataPath));
     }

Reply via email to