This is an automated email from the ASF dual-hosted git repository.
jt2594838 pushed a commit to branch dev/1.3
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/dev/1.3 by this push:
new f0dc49ec0be Fix pipe text date conversion (#17984) (#17997)
f0dc49ec0be is described below
commit f0dc49ec0be1c7acda0ff1f2a75fc9c4b9f676cc
Author: Caideyipi <[email protected]>
AuthorDate: Mon Jun 22 17:32:37 2026 +0800
Fix pipe text date conversion (#17984) (#17997)
---
.../manual/IoTDBPipeTypeConversionISessionIT.java | 1 +
.../transform/converter/ValueConverter.java | 30 ++++++++--
.../transform/converter/ValueConverterTest.java | 70 ++++++++++++++++++++++
3 files changed, 96 insertions(+), 5 deletions(-)
diff --git
a/integration-test/src/test/java/org/apache/iotdb/pipe/it/manual/IoTDBPipeTypeConversionISessionIT.java
b/integration-test/src/test/java/org/apache/iotdb/pipe/it/manual/IoTDBPipeTypeConversionISessionIT.java
index 6e6de4e822c..152a0bf160c 100644
---
a/integration-test/src/test/java/org/apache/iotdb/pipe/it/manual/IoTDBPipeTypeConversionISessionIT.java
+++
b/integration-test/src/test/java/org/apache/iotdb/pipe/it/manual/IoTDBPipeTypeConversionISessionIT.java
@@ -536,6 +536,7 @@ public class IoTDBPipeTypeConversionISessionIT extends
AbstractPipeDualManualIT
"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 09e2f265ec5..1a075468830 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
@@ -804,16 +804,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);
+ }
+}