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 2021/02/19 01:23:06 UTC

[iotdb] branch NaNBug11 created (now 75d4252)

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

haonan pushed a change to branch NaNBug11
in repository https://gitbox.apache.org/repos/asf/iotdb.git.


      at 75d4252  [ISSUE-2687] fix insert NaN bug

This branch includes the following new commits:

     new 714a5f9  [ISSUE-2476] fix the case that isNumber method returns true when the input is "NaN" (#2477)
     new 3636298  [ISSUE-2687] fix insert NaN bug
     new 75d4252  [ISSUE-2687] fix insert NaN bug

The 3 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] 02/03: [ISSUE-2687] fix insert NaN bug

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

haonan pushed a commit to branch NaNBug11
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit 363629891dced859fb16e18655d2c96ae9c5aebf
Author: HTHou <hh...@outlook.com>
AuthorDate: Thu Feb 18 16:23:44 2021 +0800

    [ISSUE-2687] fix insert NaN bug
---
 .../main/java/org/apache/iotdb/db/utils/datastructure/DoubleTVList.java | 2 +-
 .../main/java/org/apache/iotdb/db/utils/datastructure/FloatTVList.java  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/server/src/main/java/org/apache/iotdb/db/utils/datastructure/DoubleTVList.java b/server/src/main/java/org/apache/iotdb/db/utils/datastructure/DoubleTVList.java
index 817c6d1..1d49aeb 100644
--- a/server/src/main/java/org/apache/iotdb/db/utils/datastructure/DoubleTVList.java
+++ b/server/src/main/java/org/apache/iotdb/db/utils/datastructure/DoubleTVList.java
@@ -179,7 +179,7 @@ public class DoubleTVList extends TVList {
   protected TimeValuePair getTimeValuePair(int index, long time, Integer floatPrecision,
       TSEncoding encoding) {
     double value = getDouble(index);
-    if (encoding == TSEncoding.RLE || encoding == TSEncoding.TS_2DIFF) {
+    if (value != Double.NaN && (encoding == TSEncoding.RLE || encoding == TSEncoding.TS_2DIFF)) {
       value = MathUtils.roundWithGivenPrecision(value, floatPrecision);
     }
     return new TimeValuePair(time, TsPrimitiveType.getByType(TSDataType.DOUBLE, value));
diff --git a/server/src/main/java/org/apache/iotdb/db/utils/datastructure/FloatTVList.java b/server/src/main/java/org/apache/iotdb/db/utils/datastructure/FloatTVList.java
index 8b02238..7f3b7ab 100644
--- a/server/src/main/java/org/apache/iotdb/db/utils/datastructure/FloatTVList.java
+++ b/server/src/main/java/org/apache/iotdb/db/utils/datastructure/FloatTVList.java
@@ -178,7 +178,7 @@ public class FloatTVList extends TVList {
   protected TimeValuePair getTimeValuePair(int index, long time, Integer floatPrecision,
       TSEncoding encoding) {
     float value = getFloat(index);
-    if (encoding == TSEncoding.RLE || encoding == TSEncoding.TS_2DIFF) {
+    if (value != Float.NaN && (encoding == TSEncoding.RLE || encoding == TSEncoding.TS_2DIFF)) {
       value = MathUtils.roundWithGivenPrecision(value, floatPrecision);
     }
     return new TimeValuePair(time, TsPrimitiveType.getByType(TSDataType.FLOAT, value));


[iotdb] 01/03: [ISSUE-2476] fix the case that isNumber method returns true when the input is "NaN" (#2477)

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

haonan pushed a commit to branch NaNBug11
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit 714a5f946a348efc6bf0e500c9ebb3f1f4228872
Author: Al Wei <10...@qq.com>
AuthorDate: Wed Jan 13 11:31:27 2021 +0800

    [ISSUE-2476] fix the case that isNumber method returns true when the input is "NaN" (#2477)
    
    * [FIX] fix the case that isNumber method returns true when the input is "NaN"
    
    * [ADD] add UT
    
    Co-authored-by: weizihan0110 <wz...@163.com>
---
 .../apache/iotdb/db/utils/TypeInferenceUtils.java  |  3 ++
 .../iotdb/db/integration/IoTDBInsertNaNIT.java     | 46 ++++++++++++++++------
 2 files changed, 38 insertions(+), 11 deletions(-)

diff --git a/server/src/main/java/org/apache/iotdb/db/utils/TypeInferenceUtils.java b/server/src/main/java/org/apache/iotdb/db/utils/TypeInferenceUtils.java
index a9174d1..145d84c 100644
--- a/server/src/main/java/org/apache/iotdb/db/utils/TypeInferenceUtils.java
+++ b/server/src/main/java/org/apache/iotdb/db/utils/TypeInferenceUtils.java
@@ -41,6 +41,9 @@ public class TypeInferenceUtils {
   }
 
   static boolean isNumber(String s) {
+    if (s == null || s.equals("NaN")) {
+      return false;
+    }
     try {
       Double.parseDouble(s);
     } catch (NumberFormatException e) {
diff --git a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBInsertNaNIT.java b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBInsertNaNIT.java
index 0e6fd16..5dda867 100644
--- a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBInsertNaNIT.java
+++ b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBInsertNaNIT.java
@@ -18,13 +18,10 @@
  */
 package org.apache.iotdb.db.integration;
 
-import org.apache.iotdb.db.utils.EnvironmentUtils;
-import org.apache.iotdb.db.utils.MathUtils;
-import org.apache.iotdb.jdbc.Config;
-import org.junit.AfterClass;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import static org.apache.iotdb.db.constant.TestConstant.TIMESTAMP_STR;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 import java.sql.Connection;
 import java.sql.DriverManager;
@@ -32,10 +29,13 @@ import java.sql.ResultSet;
 import java.sql.Statement;
 import java.util.ArrayList;
 import java.util.List;
-
-import static org.apache.iotdb.db.constant.TestConstant.TIMESTAMP_STR;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
+import org.apache.iotdb.db.utils.EnvironmentUtils;
+import org.apache.iotdb.db.utils.MathUtils;
+import org.apache.iotdb.jdbc.Config;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
 
 /**
  * Notice that, all test begins with "IoTDB" is integration test. All test which will start the IoTDB server should be
@@ -47,6 +47,7 @@ public class IoTDBInsertNaNIT {
 
   private static final String CREATE_TEMPLATE_SQL = "CREATE TIMESERIES root.vehicle.%s.%s WITH DATATYPE=%s, ENCODING=%s, MAX_POINT_NUMBER=%d";
   private static final String INSERT_TEMPLATE_SQL = "insert into root.vehicle.%s(timestamp,%s) values(%d,%s)";
+  private static final String INSERT_BRAND_NEW_TEMPLATE_SQL = "insert into root.cycle.%s(timestamp,%s) values(%d,%s)";
   private static List<String> sqls = new ArrayList<>();
   private static final int TIMESTAMP = 10;
   private static final String VALUE = "NaN";
@@ -136,4 +137,27 @@ public class IoTDBInsertNaNIT {
     }
   }
 
+  @Test
+  public void testNaNValue() {
+    try (Connection connection = DriverManager
+        .getConnection(Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute(String.format(INSERT_BRAND_NEW_TEMPLATE_SQL, "d0", "s0"+"2f", TIMESTAMP, VALUE));
+      boolean hasResultSet = statement.execute("show timeseries");
+      Assert.assertTrue(hasResultSet);
+      boolean exist = false;
+      try (ResultSet resultSet = statement.getResultSet()) {
+        while (resultSet.next()) {
+          if ((resultSet.getString("timeseries")).contains("root.cycle.d0.s0")) {
+            exist = true;
+          }
+        }
+      }
+      assertTrue(exist);
+    } catch (Exception e) {
+      e.printStackTrace();
+      fail(e.getMessage());
+    }
+  }
+
 }


[iotdb] 03/03: [ISSUE-2687] fix insert NaN bug

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

haonan pushed a commit to branch NaNBug11
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit 75d4252ee7f9a0ce4093dd6614099eca62e6abe9
Author: HTHou <hh...@outlook.com>
AuthorDate: Thu Feb 18 17:10:11 2021 +0800

    [ISSUE-2687] fix insert NaN bug
---
 .../iotdb/db/utils/datastructure/DoubleTVList.java |  2 +-
 .../iotdb/db/utils/datastructure/FloatTVList.java  |  2 +-
 .../iotdb/db/integration/IoTDBInsertNaNIT.java     | 37 +++++++++++++++++++---
 3 files changed, 34 insertions(+), 7 deletions(-)

diff --git a/server/src/main/java/org/apache/iotdb/db/utils/datastructure/DoubleTVList.java b/server/src/main/java/org/apache/iotdb/db/utils/datastructure/DoubleTVList.java
index 1d49aeb..5143979 100644
--- a/server/src/main/java/org/apache/iotdb/db/utils/datastructure/DoubleTVList.java
+++ b/server/src/main/java/org/apache/iotdb/db/utils/datastructure/DoubleTVList.java
@@ -179,7 +179,7 @@ public class DoubleTVList extends TVList {
   protected TimeValuePair getTimeValuePair(int index, long time, Integer floatPrecision,
       TSEncoding encoding) {
     double value = getDouble(index);
-    if (value != Double.NaN && (encoding == TSEncoding.RLE || encoding == TSEncoding.TS_2DIFF)) {
+    if (!Double.isNaN(value) && (encoding == TSEncoding.RLE || encoding == TSEncoding.TS_2DIFF)) {
       value = MathUtils.roundWithGivenPrecision(value, floatPrecision);
     }
     return new TimeValuePair(time, TsPrimitiveType.getByType(TSDataType.DOUBLE, value));
diff --git a/server/src/main/java/org/apache/iotdb/db/utils/datastructure/FloatTVList.java b/server/src/main/java/org/apache/iotdb/db/utils/datastructure/FloatTVList.java
index 7f3b7ab..f418ed9 100644
--- a/server/src/main/java/org/apache/iotdb/db/utils/datastructure/FloatTVList.java
+++ b/server/src/main/java/org/apache/iotdb/db/utils/datastructure/FloatTVList.java
@@ -178,7 +178,7 @@ public class FloatTVList extends TVList {
   protected TimeValuePair getTimeValuePair(int index, long time, Integer floatPrecision,
       TSEncoding encoding) {
     float value = getFloat(index);
-    if (value != Float.NaN && (encoding == TSEncoding.RLE || encoding == TSEncoding.TS_2DIFF)) {
+    if (!Float.isNaN(value) && (encoding == TSEncoding.RLE || encoding == TSEncoding.TS_2DIFF)) {
       value = MathUtils.roundWithGivenPrecision(value, floatPrecision);
     }
     return new TimeValuePair(time, TsPrimitiveType.getByType(TSDataType.FLOAT, value));
diff --git a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBInsertNaNIT.java b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBInsertNaNIT.java
index 5dda867..df124ee 100644
--- a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBInsertNaNIT.java
+++ b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBInsertNaNIT.java
@@ -106,7 +106,7 @@ public class IoTDBInsertNaNIT {
     try (Connection connection = DriverManager
         .getConnection(Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
         Statement statement = connection.createStatement()) {
-      boolean hasResultSet = statement.execute("select * from root");
+      boolean hasResultSet = statement.execute("select * from root.vehicle.*");
       Assert.assertTrue(hasResultSet);
       int cnt;
       try (ResultSet resultSet = statement.getResultSet()) {
@@ -114,16 +114,16 @@ public class IoTDBInsertNaNIT {
         while (resultSet.next()) {
           assertEquals(TIMESTAMP + "", resultSet.getString(TIMESTAMP_STR));
           for (int i = 0; i < 10; i++) {
-            Assert.assertEquals(MathUtils.roundWithGivenPrecision(Float.parseFloat(VALUE), i),
+            Assert.assertEquals(Float.parseFloat(VALUE),
                 resultSet.getFloat(String.format("root.vehicle.%s.%s", "f0", "s" + i + "rle")),
                 DELTA_FLOAT);
-            Assert.assertEquals(MathUtils.roundWithGivenPrecision(Float.parseFloat(VALUE), i),
+            Assert.assertEquals(Float.parseFloat(VALUE),
                 resultSet.getFloat(String.format("root.vehicle.%s.%s", "f0", "s" + i + "2f")),
                 DELTA_FLOAT);
-            Assert.assertEquals(MathUtils.roundWithGivenPrecision(Double.parseDouble(VALUE), i),
+            Assert.assertEquals(Double.parseDouble(VALUE),
                 resultSet.getDouble(String.format("root.vehicle.%s.%s", "d0", "s" + i + "rle")),
                 DELTA_DOUBLE);
-            Assert.assertEquals(MathUtils.roundWithGivenPrecision(Double.parseDouble(VALUE), i),
+            Assert.assertEquals(Double.parseDouble(VALUE),
                 resultSet.getDouble(String.format("root.vehicle.%s.%s", "d0", "s" + i + "2f")),
                 DELTA_DOUBLE);
           }
@@ -138,6 +138,33 @@ public class IoTDBInsertNaNIT {
   }
 
   @Test
+  public void selectTest() throws ClassNotFoundException {
+    try (Connection connection = DriverManager
+        .getConnection(Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement statement = connection.createStatement()) {
+      statement.execute("CREATE TIMESERIES root.happy.device1.sensor1.temperature WITH DATATYPE=DOUBLE, ENCODING=RLE");
+      statement.execute("INSERT INTO root.happy.device1.sensor1(timestamp,temperature) values(7925, NaN)");
+      boolean hasResultSet = statement.execute("select * from root.happy.device1.sensor1");
+      Assert.assertTrue(hasResultSet);
+      int cnt;
+      try (ResultSet resultSet = statement.getResultSet()) {
+        cnt = 0;
+        while (resultSet.next()) {
+          assertEquals(7925 + "", resultSet.getString(TIMESTAMP_STR));
+          assertEquals(Double.parseDouble(VALUE),
+              resultSet.getDouble("root.happy.device1.sensor1.temperature"),
+              DELTA_DOUBLE);
+          cnt++;
+        }
+        Assert.assertEquals(1, cnt);
+      }
+    } catch (Exception e) {
+      e.printStackTrace();
+      fail(e.getMessage());
+    }
+  }
+
+  @Test
   public void testNaNValue() {
     try (Connection connection = DriverManager
         .getConnection(Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");