You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by qi...@apache.org on 2022/11/03 04:05:12 UTC

[iotdb] branch master updated: [IOTDB-4842] Fix type infer error when insert a large number (#7887)

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

qiaojialin 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 5a448c6e21 [IOTDB-4842] Fix type infer error when insert a large number (#7887)
5a448c6e21 is described below

commit 5a448c6e210a64c6bd570d0f5a67ed145f602bbd
Author: Haonan <hh...@outlook.com>
AuthorDate: Thu Nov 3 12:05:07 2022 +0800

    [IOTDB-4842] Fix type infer error when insert a large number (#7887)
---
 .../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++) {