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 2022/11/03 02:17:41 UTC

[iotdb] 01/01: [IOTDB-4842] Fix type infer error when insert a large number

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

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

commit 16b7c3b02a4a82606c20ffc4f1cac4639975b416
Author: HTHou <hh...@outlook.com>
AuthorDate: Thu Nov 3 10:16:40 2022 +0800

    [IOTDB-4842] Fix type infer error when insert a large number
---
 .../iotdb/db/it/aligned/IoTDBInsertAlignedValuesIT.java       | 11 +++++++++++
 .../java/org/apache/iotdb/db/utils/TypeInferenceUtils.java    |  6 +++++-
 .../org/apache/iotdb/db/utils/TypeInferenceUtilsTest.java     |  2 ++
 3 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/integration-test/src/test/java/org/apache/iotdb/db/it/aligned/IoTDBInsertAlignedValuesIT.java b/integration-test/src/test/java/org/apache/iotdb/db/it/aligned/IoTDBInsertAlignedValuesIT.java
index 8a9e571f4c..d2683d06e6 100644
--- a/integration-test/src/test/java/org/apache/iotdb/db/it/aligned/IoTDBInsertAlignedValuesIT.java
+++ b/integration-test/src/test/java/org/apache/iotdb/db/it/aligned/IoTDBInsertAlignedValuesIT.java
@@ -337,4 +337,15 @@ public class IoTDBInsertAlignedValuesIT {
       assertTrue(e.getMessage(), e.getMessage().contains("data type is not consistent"));
     }
   }
+
+  @Test
+  public void testInsertLargeNumber() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "insert into root.sg1.d1(time, s98, s99) aligned values(10, 2, 271840880000000000000000)");
+    } catch (SQLException e) {
+      fail();
+    }
+  }
 }
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 6135b2b31b..3485e62eaa 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
@@ -64,7 +64,11 @@ public class TypeInferenceUtils {
   }
 
   private static boolean isConvertFloatPrecisionLack(String s) {
-    return Long.parseLong(s) > (1 << 24);
+    try {
+      return Long.parseLong(s) > (1 << 24);
+    } catch (NumberFormatException e) {
+      return true;
+    }
   }
 
   /** Get predicted DataType of the given value */
diff --git a/server/src/test/java/org/apache/iotdb/db/utils/TypeInferenceUtilsTest.java b/server/src/test/java/org/apache/iotdb/db/utils/TypeInferenceUtilsTest.java
index 4b374c87e0..89b8b00bd6 100644
--- a/server/src/test/java/org/apache/iotdb/db/utils/TypeInferenceUtilsTest.java
+++ b/server/src/test/java/org/apache/iotdb/db/utils/TypeInferenceUtilsTest.java
@@ -75,6 +75,7 @@ public class TypeInferenceUtilsTest {
       " 7112324 ",
       "16777217", // 2^24 + 1
       "16777216", // 2^24
+      "271840880000000000000000",
     };
     TSDataType[] encodings = {
       IoTDBDescriptor.getInstance().getConfig().getIntegerStringInferType(),
@@ -90,6 +91,7 @@ public class TypeInferenceUtilsTest {
       IoTDBDescriptor.getInstance().getConfig().getIntegerStringInferType(),
       IoTDBDescriptor.getInstance().getConfig().getLongStringInferType(),
       IoTDBDescriptor.getInstance().getConfig().getIntegerStringInferType(),
+      IoTDBDescriptor.getInstance().getConfig().getLongStringInferType(),
     };
 
     for (int i = 0; i < values.length; i++) {