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 <[email protected]> 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 <[email protected]> --- .../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()); + } + } + }
