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

[incubator-iotdb] branch fix_sonar updated: fix sonar problem in tsfile read query and reader package

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

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


The following commit(s) were added to refs/heads/fix_sonar by this push:
     new 66571d2  fix sonar problem in tsfile read query and reader package
66571d2 is described below

commit 66571d2cf65da00fc7da700c9240437367b1209d
Author: CGF <cg...@foxmail.com>
AuthorDate: Wed Jan 23 21:10:07 2019 +0800

    fix sonar problem in tsfile read query and reader package
---
 .../query/dataset/DataSetWithoutTimeGenerator.java |  3 -
 .../iotdb/tsfile/read/reader/page/PageReader.java  | 98 +++++++++++++---------
 .../reader/series/SeriesReaderByTimestamp.java     |  2 +-
 3 files changed, 61 insertions(+), 42 deletions(-)

diff --git a/tsfile/src/main/java/org/apache/iotdb/tsfile/read/query/dataset/DataSetWithoutTimeGenerator.java b/tsfile/src/main/java/org/apache/iotdb/tsfile/read/query/dataset/DataSetWithoutTimeGenerator.java
index dc3b8e8..80af768 100644
--- a/tsfile/src/main/java/org/apache/iotdb/tsfile/read/query/dataset/DataSetWithoutTimeGenerator.java
+++ b/tsfile/src/main/java/org/apache/iotdb/tsfile/read/query/dataset/DataSetWithoutTimeGenerator.java
@@ -98,9 +98,6 @@ public class DataSetWithoutTimeGenerator extends QueryDataSet {
   @Override
   public RowRecord next() throws IOException {
     long minTime = timeHeapGet();
-    if (minTime == 1480562618999L) {
-      System.out.println("debug");
-    }
 
     RowRecord record = new RowRecord(minTime);
 
diff --git a/tsfile/src/main/java/org/apache/iotdb/tsfile/read/reader/page/PageReader.java b/tsfile/src/main/java/org/apache/iotdb/tsfile/read/reader/page/PageReader.java
index 136ec29..16497d7 100644
--- a/tsfile/src/main/java/org/apache/iotdb/tsfile/read/reader/page/PageReader.java
+++ b/tsfile/src/main/java/org/apache/iotdb/tsfile/read/reader/page/PageReader.java
@@ -32,16 +32,16 @@ public class PageReader {
 
   private TSDataType dataType;
 
-  // decoder for value column
+  /** decoder for value column */
   private Decoder valueDecoder;
 
-  // decoder for time column
+  /** decoder for time column */
   private Decoder timeDecoder;
 
-  // time column in memory
+  /** time column in memory */
   private ByteBuffer timeBuffer;
 
-  // value column in memory
+  /** value column in memory */
   private ByteBuffer valueBuffer;
 
   private BatchData data = null;
@@ -68,8 +68,6 @@ public class PageReader {
    *
    * @param pageData
    *            uncompressed bytes size of time column, time column, value column
-   * @throws IOException
-   *             exception in reading data from pageContent
    */
   private void splitDataToTimeStampAndValue(ByteBuffer pageData) {
     int timeBufferLength = ReadWriteForEncodingUtils.readUnsignedVarInt(pageData);
@@ -92,7 +90,7 @@ public class PageReader {
     if (filter == null) {
       data = getAllPageData();
     } else {
-      data = getAllPageData(filter);
+      data = getAllPageDataWithFilter();
     }
 
     return data;
@@ -136,7 +134,7 @@ public class PageReader {
     return pageData;
   }
 
-  private BatchData getAllPageData(Filter filter) throws IOException {
+  private BatchData getAllPageDataWithFilter() throws IOException {
     BatchData pageData = new BatchData(dataType, true);
 
     while (timeDecoder.hasNext(timeBuffer)) {
@@ -144,46 +142,22 @@ public class PageReader {
 
       switch (dataType) {
         case BOOLEAN:
-          boolean aBoolean = valueDecoder.readBoolean(valueBuffer);
-          if (filter.satisfy(timestamp, aBoolean)) {
-            pageData.putTime(timestamp);
-            pageData.putBoolean(aBoolean);
-          }
+          readBoolean(pageData, timestamp);
           break;
         case INT32:
-          int anInt = valueDecoder.readInt(valueBuffer);
-          if (filter.satisfy(timestamp, anInt)) {
-            pageData.putTime(timestamp);
-            pageData.putInt(anInt);
-          }
+          readInt(pageData, timestamp);
           break;
         case INT64:
-          long aLong = valueDecoder.readLong(valueBuffer);
-          if (filter.satisfy(timestamp, aLong)) {
-            pageData.putTime(timestamp);
-            pageData.putLong(aLong);
-          }
+          readLong(pageData, timestamp);
           break;
         case FLOAT:
-          float aFloat = valueDecoder.readFloat(valueBuffer);
-          if (filter.satisfy(timestamp, aFloat)) {
-            pageData.putTime(timestamp);
-            pageData.putFloat(aFloat);
-          }
+          readFloat(pageData, timestamp);
           break;
         case DOUBLE:
-          double aDouble = valueDecoder.readDouble(valueBuffer);
-          if (filter.satisfy(timestamp, aDouble)) {
-            pageData.putTime(timestamp);
-            pageData.putDouble(aDouble);
-          }
+          readDouble(pageData, timestamp);
           break;
         case TEXT:
-          Binary aBinary = valueDecoder.readBinary(valueBuffer);
-          if (filter.satisfy(timestamp, aBinary)) {
-            pageData.putTime(timestamp);
-            pageData.putBinary(aBinary);
-          }
+          readText(pageData, timestamp);
           break;
         default:
           throw new UnSupportedDataTypeException(String.valueOf(dataType));
@@ -193,6 +167,54 @@ public class PageReader {
     return pageData;
   }
 
+  private void readBoolean(BatchData pageData, long timestamp) {
+    boolean aBoolean = valueDecoder.readBoolean(valueBuffer);
+    if (filter.satisfy(timestamp, aBoolean)) {
+      pageData.putTime(timestamp);
+      pageData.putBoolean(aBoolean);
+    }
+  }
+
+  private void readInt(BatchData pageData, long timestamp) {
+    int anInt = valueDecoder.readInt(valueBuffer);
+    if (filter.satisfy(timestamp, anInt)) {
+      pageData.putTime(timestamp);
+      pageData.putInt(anInt);
+    }
+  }
+
+  private void readLong(BatchData pageData, long timestamp) {
+    long aLong = valueDecoder.readLong(valueBuffer);
+    if (filter.satisfy(timestamp, aLong)) {
+      pageData.putTime(timestamp);
+      pageData.putLong(aLong);
+    }
+  }
+
+  private void readFloat(BatchData pageData, long timestamp) {
+    float aFloat = valueDecoder.readFloat(valueBuffer);
+    if (filter.satisfy(timestamp, aFloat)) {
+      pageData.putTime(timestamp);
+      pageData.putFloat(aFloat);
+    }
+  }
+
+  private void readDouble(BatchData pageData, long timestamp) {
+    double aDouble = valueDecoder.readDouble(valueBuffer);
+    if (filter.satisfy(timestamp, aDouble)) {
+      pageData.putTime(timestamp);
+      pageData.putDouble(aDouble);
+    }
+  }
+
+  private void readText(BatchData pageData, long timestamp) {
+    Binary aBinary = valueDecoder.readBinary(valueBuffer);
+    if (filter.satisfy(timestamp, aBinary)) {
+      pageData.putTime(timestamp);
+      pageData.putBinary(aBinary);
+    }
+  }
+
   public void close() {
     timeBuffer = null;
     valueBuffer = null;
diff --git a/tsfile/src/main/java/org/apache/iotdb/tsfile/read/reader/series/SeriesReaderByTimestamp.java b/tsfile/src/main/java/org/apache/iotdb/tsfile/read/reader/series/SeriesReaderByTimestamp.java
index 1c356a1..2d2e11c 100644
--- a/tsfile/src/main/java/org/apache/iotdb/tsfile/read/reader/series/SeriesReaderByTimestamp.java
+++ b/tsfile/src/main/java/org/apache/iotdb/tsfile/read/reader/series/SeriesReaderByTimestamp.java
@@ -91,7 +91,7 @@ public class SeriesReaderByTimestamp {
         }
         return null;
       } else {
-        if (chunkReader.hasNextBatch()) { // data does not has next
+        if (chunkReader.hasNextBatch()) {
           data = chunkReader.nextBatch();
         } else if (!constructNextSatisfiedChunkReader()) {
           return null;