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:09 UTC

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

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");