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 02:43:14 UTC

(iotdb) branch date_float_IT created (now 843397b68e9)

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

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


      at 843397b68e9 Add Date and Float data IT

This branch includes the following new commits:

     new 843397b68e9 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 date_float_IT
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit 843397b68e946f38c48bd7f996b112a579c9da13
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 f404046d28a..22189f0d3bb 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
@@ -1185,4 +1185,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 c2a47408954..c0ffde67b76 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>2.1.0-250207-SNAPSHOT</tsfile.version>
+        <tsfile.version>2.1.0-250219-SNAPSHOT</tsfile.version>
     </properties>
     <!--
     if we claim dependencies in dependencyManagement, then we do not claim