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

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


The following commit(s) were added to refs/heads/master by this push:
     new d58ccb0  [ISSUE-2687] fix 500  error when inserting NaN (#2691)
d58ccb0 is described below

commit d58ccb09409005b1748a20d7132a0c5838c3306a
Author: Haonan <[email protected]>
AuthorDate: Fri Feb 19 09:18:37 2021 +0800

    [ISSUE-2687] fix 500  error when inserting NaN (#2691)
---
 .../iotdb/db/utils/datastructure/DoubleTVList.java |  2 +-
 .../iotdb/db/utils/datastructure/FloatTVList.java  |  2 +-
 .../iotdb/db/integration/IoTDBInsertNaNIT.java     | 42 ++++++++++++++++++----
 3 files changed, 38 insertions(+), 8 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 363e7ba..d7e8178 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
@@ -186,7 +186,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 (!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 9ed90f2..d2ead4b 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
@@ -186,7 +186,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 (!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 0c58629..a8174b8 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
@@ -19,7 +19,6 @@
 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;
@@ -111,7 +110,7 @@ public class IoTDBInsertNaNIT {
             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()) {
@@ -120,19 +119,19 @@ public class IoTDBInsertNaNIT {
           assertEquals(TIMESTAMP + "", resultSet.getString(TIMESTAMP_STR));
           for (int i = 0; i < 10; i++) {
             Assert.assertEquals(
-                MathUtils.roundWithGivenPrecision(Float.parseFloat(VALUE), i),
+                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),
+                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),
+                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),
+                Double.parseDouble(VALUE),
                 resultSet.getDouble(String.format("root.vehicle.%s.%s", "d0", 
"s" + i + "2f")),
                 DELTA_DOUBLE);
           }
@@ -147,6 +146,37 @@ 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(

Reply via email to