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

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

commit 05f63d12d607b738774328e9b9bd4b2535b7c404
Author: HTHou <[email protected]>
AuthorDate: Tue May 31 18:18:53 2022 +0800

    [IOTDB-3358] Fix error message of insert wrong type of data by sql is 
meaningless
---
 .../org/apache/iotdb/db/utils/CommonUtils.java     | 30 +++++++++++++++++++---
 1 file changed, 26 insertions(+), 4 deletions(-)

diff --git a/server/src/main/java/org/apache/iotdb/db/utils/CommonUtils.java 
b/server/src/main/java/org/apache/iotdb/db/utils/CommonUtils.java
index cd218ce637..1c7f8d7a3b 100644
--- a/server/src/main/java/org/apache/iotdb/db/utils/CommonUtils.java
+++ b/server/src/main/java/org/apache/iotdb/db/utils/CommonUtils.java
@@ -52,17 +52,39 @@ public class CommonUtils {
         case BOOLEAN:
           return parseBoolean(value);
         case INT32:
-          return Integer.parseInt(StringUtils.trim(value));
+          try {
+            return Integer.parseInt(StringUtils.trim(value));
+          } catch (NumberFormatException e) {
+            throw new NumberFormatException(
+                "data type is not consistent, input " + value + ", registered 
" + dataType);
+          }
         case INT64:
-          return Long.parseLong(StringUtils.trim(value));
+          try {
+            return Long.parseLong(StringUtils.trim(value));
+          } catch (NumberFormatException e) {
+            throw new NumberFormatException(
+                "data type is not consistent, input " + value + ", registered 
" + dataType);
+          }
         case FLOAT:
-          float f = Float.parseFloat(value);
+          float f;
+          try {
+            f = Float.parseFloat(value);
+          } catch (NumberFormatException e) {
+            throw new NumberFormatException(
+                "data type is not consistent, input " + value + ", registered 
" + dataType);
+          }
           if (Float.isInfinite(f)) {
             throw new NumberFormatException("The input float value is 
Infinity");
           }
           return f;
         case DOUBLE:
-          double d = Double.parseDouble(value);
+          double d;
+          try {
+            d = Double.parseDouble(value);
+          } catch (NumberFormatException e) {
+            throw new NumberFormatException(
+                "data type is not consistent, input " + value + ", registered 
" + dataType);
+          }
           if (Double.isInfinite(d)) {
             throw new NumberFormatException("The input double value is 
Infinity");
           }

Reply via email to