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

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

commit 6e366de2f6df9f8f9de4650c4d16711798d24164
Author: HTHou <[email protected]>
AuthorDate: Wed Jul 10 22:37:14 2024 +0800

    Allow inserting negative timestamp type
---
 .../apache/iotdb/db/it/IoTDBInsertWithQueryIT.java | 56 +++++++++++++++++-----
 .../org/apache/iotdb/db/utils/CommonUtils.java     |  2 +-
 2 files changed, 46 insertions(+), 12 deletions(-)

diff --git 
a/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBInsertWithQueryIT.java
 
b/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBInsertWithQueryIT.java
index 2ef61ed7b28..04d63c4d060 100644
--- 
a/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBInsertWithQueryIT.java
+++ 
b/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBInsertWithQueryIT.java
@@ -149,19 +149,23 @@ public class IoTDBInsertWithQueryIT {
 
   @Test
   public void insertNegativeTimestampWithQueryTest() {
-    // insert
-    insertData(-1000, 1);
-
-    // select
-    selectAndCount(1001);
-
-    // insert
-    insertData(-2000, -1000);
+    //    // insert
+    //    insertData(-1000, 1);
+    //
+    //    // select
+    //    selectAndCount(1001);
+    //
+    //    // insert
+    //    insertData(-2000, -1000);
+    //
+    //    // select
+    //    selectAndCount(2001);
+    //
+    //    negativeTimestampAggregationTest();
 
-    // select
-    selectAndCount(2001);
+    insertNegativeTimestampTypeData();
 
-    negativeTimestampAggregationTest();
+    queryNegativeTimestampTypeDataTest();
   }
 
   @Test
@@ -423,6 +427,36 @@ public class IoTDBInsertWithQueryIT {
     }
   }
 
+  private void insertNegativeTimestampTypeData() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute("create timeseries root.fans.d0.s2 with datatype = 
timestamp");
+      statement.execute(
+          String.format(
+              "insert into root.fans.d0(time,s2) values(%s,%s)",
+              Long.MIN_VALUE + 1, Long.MIN_VALUE + 1));
+      statement.execute("insert into root.fans.d0(time,s2) 
values(-999999,-9999999)");
+      statement.execute(
+          "insert into root.fans.d0(time,s2) values(1900-01-01 
10:00:00,1900-01-01 10:00:00)");
+    } catch (SQLException e) {
+      fail(e.getMessage());
+    }
+  }
+
+  private void queryNegativeTimestampTypeDataTest() {
+    String[] expectedHeader =
+        new String[] {
+          "Time", "root.fans.d0.s2",
+        };
+    String[] retArray =
+        new String[] {
+          "-9223372036854775807,-9223372036854775807,",
+          "-2208952800000,-2208952800000,",
+          "-999999,-9999999,"
+        };
+    resultSetEqualTest("SELECT s2 FROM root.fans.d0;", expectedHeader, 
retArray);
+  }
+
   private void flush() {
     try (Connection connection = EnvFactory.getEnv().getConnection();
         Statement statement = connection.createStatement()) {
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/CommonUtils.java 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/CommonUtils.java
index 04bbb4221e6..d7489730613 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/CommonUtils.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/CommonUtils.java
@@ -87,7 +87,7 @@ public class CommonUtils {
           }
         case TIMESTAMP:
           try {
-            if (StringUtils.isNumeric(value)) {
+            if (TypeInferenceUtils.isNumber(value)) {
               return Long.parseLong(value);
             } else {
               return 
DateTimeUtils.parseDateTimeExpressionToLong(StringUtils.trim(value), zoneId);

Reply via email to