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

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

commit f089cf41c6e6bcc4888e36ada093789e001f3e22
Author: EJTTianyu <[email protected]>
AuthorDate: Mon Oct 5 16:36:39 2020 +0800

    fix float loss precision
---
 .../src/assembly/resources/conf/iotdb-engine.properties   |  4 ++++
 .../main/java/org/apache/iotdb/db/conf/IoTDBConfig.java   | 15 +++++++++++++++
 .../java/org/apache/iotdb/db/conf/IoTDBDescriptor.java    |  3 +++
 .../org/apache/iotdb/db/utils/TypeInferenceUtils.java     |  9 +++++++++
 4 files changed, 31 insertions(+)

diff --git a/server/src/assembly/resources/conf/iotdb-engine.properties 
b/server/src/assembly/resources/conf/iotdb-engine.properties
index 07bf45d..031354d 100644
--- a/server/src/assembly/resources/conf/iotdb-engine.properties
+++ b/server/src/assembly/resources/conf/iotdb-engine.properties
@@ -424,6 +424,10 @@ boolean_string_infer_type=BOOLEAN
 # register time series as which type when receiving an integer string "67"
 integer_string_infer_type=FLOAT
 
+# register time series as which type when receiving an integer string and 
using float may lose precision
+# num > 2 ^ 24
+long_string_infer_type=DOUBLE
+
 # register time series as which type when receiving a floating number string 
"6.7"
 floating_string_infer_type=FLOAT
 
diff --git a/server/src/main/java/org/apache/iotdb/db/conf/IoTDBConfig.java 
b/server/src/main/java/org/apache/iotdb/db/conf/IoTDBConfig.java
index ab4d3cb..14e78c3 100644
--- a/server/src/main/java/org/apache/iotdb/db/conf/IoTDBConfig.java
+++ b/server/src/main/java/org/apache/iotdb/db/conf/IoTDBConfig.java
@@ -420,6 +420,12 @@ public class IoTDBConfig {
   private TSDataType integerStringInferType = TSDataType.FLOAT;
 
   /**
+   * register time series as which type when receiving an integer string and 
using float may lose precision
+   * num > 2 ^ 24
+   */
+  private TSDataType longStringInferType = TSDataType.DOUBLE;
+
+  /**
    * register time series as which type when receiving a floating number 
string "6.7"
    */
   private TSDataType floatingStringInferType = TSDataType.FLOAT;
@@ -1448,6 +1454,15 @@ public class IoTDBConfig {
     this.integerStringInferType = integerStringInferType;
   }
 
+  public void setLongStringInferType(
+      TSDataType longStringInferType) {
+    this.longStringInferType = longStringInferType;
+  }
+
+  public TSDataType getLongStringInferType() {
+    return longStringInferType;
+  }
+
   public TSDataType getFloatingStringInferType() {
     return floatingStringInferType;
   }
diff --git a/server/src/main/java/org/apache/iotdb/db/conf/IoTDBDescriptor.java 
b/server/src/main/java/org/apache/iotdb/db/conf/IoTDBDescriptor.java
index 747916a..585522f 100644
--- a/server/src/main/java/org/apache/iotdb/db/conf/IoTDBDescriptor.java
+++ b/server/src/main/java/org/apache/iotdb/db/conf/IoTDBDescriptor.java
@@ -556,6 +556,9 @@ public class IoTDBDescriptor {
     conf.setIntegerStringInferType(
         TSDataType.valueOf(properties.getProperty("integer_string_infer_type",
             conf.getIntegerStringInferType().toString())));
+    conf.setLongStringInferType(
+        TSDataType.valueOf(properties.getProperty("long_string_infer_type",
+            conf.getLongStringInferType().toString())));
     conf.setFloatingStringInferType(
         TSDataType.valueOf(properties.getProperty("floating_string_infer_type",
             conf.getFloatingStringInferType().toString())));
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 04580fd..a9174d1 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
@@ -30,6 +30,8 @@ public class TypeInferenceUtils {
 
   private static TSDataType integerStringInferType = 
IoTDBDescriptor.getInstance().getConfig().getIntegerStringInferType();
 
+  private static TSDataType longStringInferType = 
IoTDBDescriptor.getInstance().getConfig().getLongStringInferType();
+
   private static TSDataType floatingStringInferType = 
IoTDBDescriptor.getInstance().getConfig().getFloatingStringInferType();
 
   private static TSDataType nanStringInferType = 
IoTDBDescriptor.getInstance().getConfig().getNanStringInferType();
@@ -52,6 +54,10 @@ public class TypeInferenceUtils {
         .equalsIgnoreCase(SQLConstant.BOOLEAN_FALSE);
   }
 
+  private static boolean isConvertFloatPrecisionLack(String s){
+    return Long.parseLong(s) > (2 << 24);
+  }
+
   /**
    * Get predicted DataType of the given value
    */
@@ -63,6 +69,9 @@ public class TypeInferenceUtils {
         return booleanStringInferType;
       } else if (isNumber(strValue)){
         if (!strValue.contains(TsFileConstant.PATH_SEPARATOR)) {
+          if (isConvertFloatPrecisionLack(strValue)) {
+            return longStringInferType;
+          }
           return integerStringInferType;
         } else {
           return floatingStringInferType;

Reply via email to