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 2025/02/19 04:12:11 UTC

(iotdb) branch float_date_IT_13 created (now 362b3143e76)

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

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


      at 362b3143e76 Add Date and Float data IT

This branch includes the following new commits:

     new 362b3143e76 Add Date and Float data IT

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(iotdb) 01/01: Add Date and Float data IT

Posted by ha...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 362b3143e7650233204f40c1bf1d56629bfcea52
Author: HTHou <ha...@apache.org>
AuthorDate: Wed Feb 19 10:42:52 2025 +0800

    Add Date and Float data IT
---
 .../apache/iotdb/db/it/IoTDBFloatPrecisionIT.java  | 45 ++++++++++++++++++++++
 .../org/apache/iotdb/db/it/IoTDBSimpleQueryIT.java | 24 ++++++++++++
 .../java/org/apache/iotdb/db/utils/MathUtils.java  | 24 ++++++------
 pom.xml                                            |  2 +-
 4 files changed, 82 insertions(+), 13 deletions(-)

diff --git a/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBFloatPrecisionIT.java b/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBFloatPrecisionIT.java
index c72c7e41b12..3a73be3adb3 100644
--- a/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBFloatPrecisionIT.java
+++ b/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBFloatPrecisionIT.java
@@ -169,4 +169,49 @@ public class IoTDBFloatPrecisionIT {
       fail(e.getMessage());
     }
   }
+
+  @Test
+  public void bigFloatNumberTest2() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      float[] floats = new float[] {6.5536403E8F, 3.123456768E20F, Float.NaN};
+      double[] doubles = new double[] {9.223372036854E18, 9.223372036854E100, Double.NaN};
+
+      statement.execute("create timeseries root.sg.d1.s1 with datatype=float, encoding=rle");
+      statement.execute("create timeseries root.sg.d1.s2 with datatype=double, encoding=rle");
+      statement.execute(
+          "insert into root.sg.d1(time, s1, s2) values (1, 6.5536403E8, 9.223372036854E18)");
+      statement.execute(
+          "insert into root.sg.d1(time, s1, s2) values (2, 3.123456768E20, 9.223372036854E100)");
+      statement.execute("insert into root.sg.d1(time, s1, s2) values (3, NaN, NaN)");
+
+      int cnt;
+      try (ResultSet resultSet = statement.executeQuery("select s1, s2 from root.sg.d1")) {
+        assertNotNull(resultSet);
+        cnt = 0;
+        while (resultSet.next()) {
+          assertEquals(floats[cnt], resultSet.getFloat("root.sg.d1.s1"), DELTA_FLOAT);
+          assertEquals(doubles[cnt], resultSet.getDouble("root.sg.d1.s2"), DELTA_DOUBLE);
+          cnt++;
+        }
+        assertEquals(3, cnt);
+      }
+
+      statement.execute("flush");
+
+      try (ResultSet resultSet = statement.executeQuery("select s1, s2 from root.sg.d1")) {
+        assertNotNull(resultSet);
+        cnt = 0;
+        while (resultSet.next()) {
+          assertEquals(floats[cnt], resultSet.getFloat("root.sg.d1.s1"), DELTA_FLOAT);
+          assertEquals(doubles[cnt], resultSet.getDouble("root.sg.d1.s2"), DELTA_DOUBLE);
+          cnt++;
+        }
+        assertEquals(3, cnt);
+      }
+    } catch (Exception e) {
+      e.printStackTrace();
+      fail(e.getMessage());
+    }
+  }
 }
diff --git a/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBSimpleQueryIT.java b/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBSimpleQueryIT.java
index 19b48719383..f920c0553a3 100644
--- a/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBSimpleQueryIT.java
+++ b/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBSimpleQueryIT.java
@@ -1188,4 +1188,28 @@ public class IoTDBSimpleQueryIT {
       fail();
     }
   }
+
+  @Test
+  public void testIllegalDateType() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+
+      statement.execute("CREATE DATABASE root.sg1");
+      statement.execute(
+          "CREATE TIMESERIES root.sg1.d1.s4 WITH DATATYPE=DATE, ENCODING=PLAIN, COMPRESSOR=SNAPPY");
+      try {
+        statement.execute("insert into root.sg1.d1(timestamp, s4) values(1, '2022-04-31')");
+        fail();
+      } catch (Exception e) {
+        assertEquals(
+            TSStatusCode.METADATA_ERROR.getStatusCode()
+                + ": Fail to insert measurements [s4] caused by [data type is not consistent, "
+                + "input '2022-04-31', registered DATE because Invalid date format. "
+                + "Please use YYYY-MM-DD format.]",
+            e.getMessage());
+      }
+    } catch (SQLException e) {
+      fail();
+    }
+  }
 }
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/MathUtils.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/MathUtils.java
index 7aa68184164..d69adc97aee 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/MathUtils.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/MathUtils.java
@@ -29,11 +29,10 @@ public class MathUtils {
     throw new IllegalStateException("Utility class");
   }
 
-  /**
-   * @param data data should be less than Long.MAX_VALUE. otherwise Math.round() will return wrong
-   *     value.
-   */
   public static float roundWithGivenPrecision(float data, int size) {
+    if (Float.isNaN(data) || data > Integer.MAX_VALUE || data < Integer.MIN_VALUE) {
+      return data;
+    }
     if (size == 0) {
       return Math.round(data);
     }
@@ -42,6 +41,9 @@ public class MathUtils {
   }
 
   public static float roundWithGivenPrecision(float data) {
+    if (Float.isNaN(data) || data > Integer.MAX_VALUE || data < Integer.MIN_VALUE) {
+      return data;
+    }
     if (TSFileDescriptor.getInstance().getConfig().getFloatPrecision() == 0) {
       return Math.round(data);
     }
@@ -54,11 +56,10 @@ public class MathUtils {
             / (float) Math.pow(10, TSFileDescriptor.getInstance().getConfig().getFloatPrecision());
   }
 
-  /**
-   * @param data data should be less than Long.MAX_VALUE. otherwise Math.round() will return wrong
-   *     value.
-   */
   public static double roundWithGivenPrecision(double data, int size) {
+    if (Double.isNaN(data) || data > Long.MAX_VALUE || data < Long.MIN_VALUE) {
+      return data;
+    }
     if (size == 0) {
       return Math.round(data);
     }
@@ -66,11 +67,10 @@ public class MathUtils {
         + Math.round(((data - Math.round(data)) * Math.pow(10, size))) / Math.pow(10, size);
   }
 
-  /**
-   * @param data data should be less than Long.MAX_VALUE. otherwise Math.round() will return wrong
-   *     value.
-   */
   public static double roundWithGivenPrecision(double data) {
+    if (Double.isNaN(data) || data > Long.MAX_VALUE || data < Long.MIN_VALUE) {
+      return data;
+    }
     if (TSFileDescriptor.getInstance().getConfig().getFloatPrecision() == 0) {
       return Math.round(data);
     }
diff --git a/pom.xml b/pom.xml
index 61534a446be..816a459b685 100644
--- a/pom.xml
+++ b/pom.xml
@@ -167,7 +167,7 @@
         <thrift.version>0.14.1</thrift.version>
         <xz.version>1.9</xz.version>
         <zstd-jni.version>1.5.6-3</zstd-jni.version>
-        <tsfile.version>1.1.0-241216-SNAPSHOT</tsfile.version>
+        <tsfile.version>1.1.0-250219-SNAPSHOT</tsfile.version>
     </properties>
     <!--
     if we claim dependencies in dependencyManagement, then we do not claim