You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ha...@apache.org on 2020/12/02 09:47:52 UTC

[iotdb] branch jira-1028-11 created (now 3b6bc6c)

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

haonan pushed a change to branch jira-1028-11
in repository https://gitbox.apache.org/repos/asf/iotdb.git.


      at 3b6bc6c  add MAX_POINT_NUMBER format check (#2148)

This branch includes the following new commits:

     new 3b6bc6c  add MAX_POINT_NUMBER format check (#2148)

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.



[iotdb] 01/01: add MAX_POINT_NUMBER format check (#2148)

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

haonan pushed a commit to branch jira-1028-11
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit 3b6bc6cd8554b92fd8e23072c148c89489a1b59b
Author: Haonan <hh...@outlook.com>
AuthorDate: Mon Nov 30 22:21:53 2020 +0800

    add MAX_POINT_NUMBER format check (#2148)
---
 .../db/engine/querycontext/ReadOnlyMemChunk.java   | 16 +++++++-
 .../iotdb/db/integration/IoTDBSimpleQueryIT.java   | 43 ++++++++++++++++++++++
 .../tsfile/encoding/encoder/TSEncodingBuilder.java | 14 ++++++-
 3 files changed, 70 insertions(+), 3 deletions(-)

diff --git a/server/src/main/java/org/apache/iotdb/db/engine/querycontext/ReadOnlyMemChunk.java b/server/src/main/java/org/apache/iotdb/db/engine/querycontext/ReadOnlyMemChunk.java
index 5be7104..8890923 100644
--- a/server/src/main/java/org/apache/iotdb/db/engine/querycontext/ReadOnlyMemChunk.java
+++ b/server/src/main/java/org/apache/iotdb/db/engine/querycontext/ReadOnlyMemChunk.java
@@ -31,6 +31,8 @@ import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
 import org.apache.iotdb.tsfile.file.metadata.statistics.Statistics;
 import org.apache.iotdb.tsfile.read.TimeValuePair;
 import org.apache.iotdb.tsfile.read.reader.IPointReader;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class ReadOnlyMemChunk {
 
@@ -38,6 +40,7 @@ public class ReadOnlyMemChunk {
   private TSDataType dataType;
   private TSEncoding encoding;
 
+  private static final Logger logger = LoggerFactory.getLogger(ReadOnlyMemChunk.class);
   private long version;
 
   private int floatPrecision = TSFileDescriptor.getInstance().getConfig().getFloatPrecision();
@@ -56,7 +59,18 @@ public class ReadOnlyMemChunk {
     this.encoding = encoding;
     this.version = version;
     if (props != null && props.containsKey(Encoder.MAX_POINT_NUMBER)) {
-      this.floatPrecision = Integer.parseInt(props.get(Encoder.MAX_POINT_NUMBER));
+      try {
+        this.floatPrecision = Integer.parseInt(props.get(Encoder.MAX_POINT_NUMBER));
+      } catch (NumberFormatException e) {
+        logger.warn("The format of MAX_POINT_NUMBER {}  is not correct."
+            + " Using default float precision.", props.get(Encoder.MAX_POINT_NUMBER));
+      }
+      if (floatPrecision < 0) {
+        logger.warn("The MAX_POINT_NUMBER shouldn't be less than 0."
+            + " Using default float precision {}.",
+            TSFileDescriptor.getInstance().getConfig().getFloatPrecision());
+        floatPrecision = TSFileDescriptor.getInstance().getConfig().getFloatPrecision();
+      }
     }
     tvList.sort();
     this.chunkData = tvList;
diff --git a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBSimpleQueryIT.java b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBSimpleQueryIT.java
index be8bbf8..4afa443 100644
--- a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBSimpleQueryIT.java
+++ b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBSimpleQueryIT.java
@@ -639,4 +639,47 @@ public class IoTDBSimpleQueryIT {
       Assert.assertEquals(r3.getLong(3), 10L);
     }
   }
+
+  @Test
+  public void testInvalidMaxPointNumber() throws ClassNotFoundException {
+    Class.forName(Config.JDBC_DRIVER_NAME);
+    try (Connection connection = DriverManager
+        .getConnection(Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/",
+            "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute("SET STORAGE GROUP TO root.sg1");
+      statement.execute("CREATE TIMESERIES root.sg1.d1.s1 with datatype=FLOAT, encoding=TS_2DIFF, "
+          + "max_point_number=4");
+      statement.execute("CREATE TIMESERIES root.sg1.d1.s2 with datatype=FLOAT, encoding=TS_2DIFF, "
+          + "max_point_number=2.5");
+      statement.execute("CREATE TIMESERIES root.sg1.d1.s3 with datatype=FLOAT, encoding=RLE, "
+          + "max_point_number=q");
+      statement.execute("CREATE TIMESERIES root.sg1.d1.s4 with datatype=FLOAT, encoding=RLE, "
+          + "max_point_number=-1");
+      statement.execute("insert into root.sg1.d1(timestamp,s1,s2,s3,s4) values(1,1.1234,1.1234,1.1234,1.1234)");
+
+      try (ResultSet r1 = statement.executeQuery("select s1 from root.sg1.d1")) {
+        r1.next();
+        Assert.assertEquals(1.1234f, r1.getFloat(2), 0);
+      }
+
+      try (ResultSet r2 = statement.executeQuery("select s3 from root.sg1.d1")) {
+        r2.next();
+        Assert.assertEquals(1.12f, r2.getFloat(2), 0);
+      }
+
+      try (ResultSet r3 = statement.executeQuery("select s3 from root.sg1.d1")) {
+        r3.next();
+        Assert.assertEquals(1.12f, r3.getFloat(2), 0);
+      }
+
+      try (ResultSet r4 = statement.executeQuery("select s4 from root.sg1.d1")) {
+        r4.next();
+        Assert.assertEquals(1.12f, r4.getFloat(2), 0);
+      }
+
+    } catch (SQLException e) {
+      fail();
+    }
+  }
 }
diff --git a/tsfile/src/main/java/org/apache/iotdb/tsfile/encoding/encoder/TSEncodingBuilder.java b/tsfile/src/main/java/org/apache/iotdb/tsfile/encoding/encoder/TSEncodingBuilder.java
index 0f6cd7c..0903cd1 100644
--- a/tsfile/src/main/java/org/apache/iotdb/tsfile/encoding/encoder/TSEncodingBuilder.java
+++ b/tsfile/src/main/java/org/apache/iotdb/tsfile/encoding/encoder/TSEncodingBuilder.java
@@ -158,7 +158,12 @@ public abstract class TSEncodingBuilder {
       if (props == null || !props.containsKey(Encoder.MAX_POINT_NUMBER)) {
         maxPointNumber = TSFileDescriptor.getInstance().getConfig().getFloatPrecision();
       } else {
-        maxPointNumber = Integer.valueOf(props.get(Encoder.MAX_POINT_NUMBER));
+        try {
+          this.maxPointNumber = Integer.parseInt(props.get(Encoder.MAX_POINT_NUMBER));
+        } catch (NumberFormatException e) {
+          logger.warn("The format of max point number {} is not correct."
+              + " Using default float precision.", props.get(Encoder.MAX_POINT_NUMBER));
+        }
         if (maxPointNumber < 0) {
           maxPointNumber = TSFileDescriptor.getInstance().getConfig().getFloatPrecision();
           logger
@@ -206,7 +211,12 @@ public abstract class TSEncodingBuilder {
       if (props == null || !props.containsKey(Encoder.MAX_POINT_NUMBER)) {
         maxPointNumber = TSFileDescriptor.getInstance().getConfig().getFloatPrecision();
       } else {
-        maxPointNumber = Integer.valueOf(props.get(Encoder.MAX_POINT_NUMBER));
+        try {
+          this.maxPointNumber = Integer.parseInt(props.get(Encoder.MAX_POINT_NUMBER));
+        } catch (NumberFormatException e) {
+          logger.warn("The format of max point number {} is not correct."
+              + " Using default float precision.", props.get(Encoder.MAX_POINT_NUMBER));
+        }
         if (maxPointNumber < 0) {
           maxPointNumber = TSFileDescriptor.getInstance().getConfig().getFloatPrecision();
           logger