This is an automated email from the ASF dual-hosted git repository.
haonan pushed a commit to branch rel/0.11
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/rel/0.11 by this push:
new 5e6d436 [ISSUE-2687] [To rel/0.11] fix insert NaN bug (#2694)
5e6d436 is described below
commit 5e6d436b6430b4491353c855c811b78675e2bf8c
Author: Haonan <[email protected]>
AuthorDate: Fri Feb 19 10:25:52 2021 +0800
[ISSUE-2687] [To rel/0.11] fix insert NaN bug (#2694)
* [ISSUE-2476] fix the case that isNumber method returns true when the
input is "NaN" (#2477)
* fix the print 0.0 if insert NaN
Co-authored-by: Al Wei <[email protected]>
Co-authored-by: weizihan0110 <[email protected]>
---
.../apache/iotdb/db/utils/TypeInferenceUtils.java | 3 +
.../iotdb/db/utils/datastructure/DoubleTVList.java | 2 +-
.../iotdb/db/utils/datastructure/FloatTVList.java | 2 +-
.../iotdb/db/integration/IoTDBInsertNaNIT.java | 83 +++++++++++++++++-----
4 files changed, 72 insertions(+), 18 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/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..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 (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 8b02238..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 (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 0e6fd16..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
@@ -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";
@@ -105,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()) {
@@ -113,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);
}
@@ -136,4 +137,54 @@ 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");
+ 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());
+ }
+ }
+
}