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

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


The following commit(s) were added to refs/heads/master by this push:
     new c2fdc634b1f Fix pipe text date conversion (#17984)
c2fdc634b1f is described below

commit c2fdc634b1f002700c29ae6d77da5ecb36a49fe8
Author: Caideyipi <[email protected]>
AuthorDate: Mon Jun 22 12:34:47 2026 +0800

    Fix pipe text date conversion (#17984)
---
 .../IoTDBPipeTypeConversionISessionIT.java         |  1 +
 .../manual/IoTDBPipeTypeConversionISessionIT.java  |  1 +
 .../transform/converter/ValueConverter.java        | 30 ++++++++--
 .../transform/converter/ValueConverterTest.java    | 70 ++++++++++++++++++++++
 4 files changed, 97 insertions(+), 5 deletions(-)

diff --git 
a/integration-test/src/test/java/org/apache/iotdb/pipe/it/dual/tablemodel/manual/enhanced/IoTDBPipeTypeConversionISessionIT.java
 
b/integration-test/src/test/java/org/apache/iotdb/pipe/it/dual/tablemodel/manual/enhanced/IoTDBPipeTypeConversionISessionIT.java
index 46bc9e71607..2da24a820e0 100644
--- 
a/integration-test/src/test/java/org/apache/iotdb/pipe/it/dual/tablemodel/manual/enhanced/IoTDBPipeTypeConversionISessionIT.java
+++ 
b/integration-test/src/test/java/org/apache/iotdb/pipe/it/dual/tablemodel/manual/enhanced/IoTDBPipeTypeConversionISessionIT.java
@@ -346,6 +346,7 @@ public class IoTDBPipeTypeConversionISessionIT extends 
AbstractPipeTableModelDua
       "enable =  true",
       "true",
       "false",
+      "2024-06-28 08:00:00",
     };
     for (int i = 0; i < generateDataSize; i++) {
       tablet.addValue(
diff --git 
a/integration-test/src/test/java/org/apache/iotdb/pipe/it/dual/treemodel/manual/IoTDBPipeTypeConversionISessionIT.java
 
b/integration-test/src/test/java/org/apache/iotdb/pipe/it/dual/treemodel/manual/IoTDBPipeTypeConversionISessionIT.java
index c99a119d61e..efb2eeee14a 100644
--- 
a/integration-test/src/test/java/org/apache/iotdb/pipe/it/dual/treemodel/manual/IoTDBPipeTypeConversionISessionIT.java
+++ 
b/integration-test/src/test/java/org/apache/iotdb/pipe/it/dual/treemodel/manual/IoTDBPipeTypeConversionISessionIT.java
@@ -547,6 +547,7 @@ public class IoTDBPipeTypeConversionISessionIT extends 
AbstractPipeDualTreeModel
       "enable =  true",
       "true",
       "false",
+      "2024-06-28 08:00:00",
       "12345678910",
       "123231232132131233213123123123123123131312",
       "123231232132131233213123123123123123131312.212312321312312",
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/receiver/transform/converter/ValueConverter.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/receiver/transform/converter/ValueConverter.java
index db81d583aa3..2e9fc5ebc40 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/receiver/transform/converter/ValueConverter.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/receiver/transform/converter/ValueConverter.java
@@ -808,16 +808,36 @@ public class ValueConverter {
   }
 
   private static int parseDate(final String value) {
-    if (value == null || value.isEmpty()) {
+    if (value == null) {
       return DEFAULT_DATE;
     }
-    try {
-      if (TypeInferenceUtils.isNumber(value)) {
-        int date = Integer.parseInt(value);
+    final String trimmedValue = StringUtils.trim(value);
+    if (trimmedValue.isEmpty()) {
+      return DEFAULT_DATE;
+    }
+    if (TypeInferenceUtils.isNumber(trimmedValue)) {
+      try {
+        int date = Integer.parseInt(trimmedValue);
         DateUtils.parseIntToLocalDate(date);
         return date;
+      } catch (final Exception e) {
+        return DEFAULT_DATE;
       }
-      return DateTimeUtils.parseDateExpressionToInt(StringUtils.trim(value));
+    }
+    try {
+      return DateTimeUtils.parseDateExpressionToInt(trimmedValue);
+    } catch (final Exception e) {
+      return parseDateTimeToDate(trimmedValue);
+    }
+  }
+
+  private static int parseDateTimeToDate(final String value) {
+    try {
+      return DateUtils.parseDateExpressionToInt(
+          Instant.ofEpochMilli(
+                  DateTimeUtils.convertDatetimeStrToLong(value, 
ZoneOffset.UTC, 0, "ms"))
+              .atZone(ZoneOffset.UTC)
+              .toLocalDate());
     } catch (final Exception e) {
       return DEFAULT_DATE;
     }
diff --git 
a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/pipe/receiver/transform/converter/ValueConverterTest.java
 
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/pipe/receiver/transform/converter/ValueConverterTest.java
new file mode 100644
index 00000000000..94a3d7a88e2
--- /dev/null
+++ 
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/pipe/receiver/transform/converter/ValueConverterTest.java
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.db.pipe.receiver.transform.converter;
+
+import org.apache.tsfile.common.conf.TSFileConfig;
+import org.apache.tsfile.enums.TSDataType;
+import org.apache.tsfile.utils.Binary;
+import org.apache.tsfile.utils.DateUtils;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class ValueConverterTest {
+
+  @Test
+  public void testTextLikeDateTimeToDate() {
+    final int expectedDate = DateUtils.parseDateExpressionToInt("2024-06-28");
+    final Binary dateTime = binary("2024-06-28 08:00:00");
+
+    Assert.assertEquals(expectedDate, 
ValueConverter.convertTextToDate(dateTime));
+    Assert.assertEquals(expectedDate, 
ValueConverter.convertStringToDate(dateTime));
+    Assert.assertEquals(expectedDate, 
ValueConverter.convertBlobToDate(dateTime));
+  }
+
+  @Test
+  public void testTextLikeDateToDateKeepsExistingFallbacks() {
+    final int expectedDate = DateUtils.parseDateExpressionToInt("2024-06-28");
+    final int defaultDate = DateUtils.parseDateExpressionToInt("1970-01-01");
+
+    Assert.assertEquals(expectedDate, 
ValueConverter.convertTextToDate(binary("20240628")));
+    Assert.assertEquals(expectedDate, 
ValueConverter.convertTextToDate(binary("2024-06-28")));
+    Assert.assertEquals(defaultDate, 
ValueConverter.convertTextToDate(binary("12345678910")));
+    Assert.assertEquals(defaultDate, 
ValueConverter.convertTextToDate(binary("invalid-date")));
+  }
+
+  @Test
+  public void testTextArrayDateTimeToDate() {
+    final int expectedDate = DateUtils.parseDateExpressionToInt("2024-06-28");
+    final int defaultDate = DateUtils.parseDateExpressionToInt("1970-01-01");
+
+    final int[] dates =
+        (int[])
+            ArrayConverter.convert(
+                TSDataType.TEXT,
+                TSDataType.DATE,
+                new Binary[] {binary("2024-06-28 08:00:00"), 
binary("invalid-date")});
+
+    Assert.assertArrayEquals(new int[] {expectedDate, defaultDate}, dates);
+  }
+
+  private static Binary binary(final String value) {
+    return new Binary(value, TSFileConfig.STRING_CHARSET);
+  }
+}

Reply via email to