This is an automated email from the ASF dual-hosted git repository.
jiangtian 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 a377463095e Reject inserting invalid timestamp string (#14913) (#14920)
a377463095e is described below
commit a377463095e86fdc1d36bcecd92af8165373f7c7
Author: Haonan <[email protected]>
AuthorDate: Fri Feb 21 15:12:37 2025 +0800
Reject inserting invalid timestamp string (#14913) (#14920)
* Reject inserting invalid timestamp string
* fix subscription IT
---
.../java/org/apache/iotdb/db/it/IoTDBSimpleQueryIT.java | 14 ++++++++++++++
.../it/triple/regression/param/IoTDBTestParamTopicIT.java | 2 +-
.../main/java/org/apache/iotdb/db/utils/DateTimeUtils.java | 4 +++-
.../java/org/apache/iotdb/db/utils/DateTimeUtilsTest.java | 14 ++++++++++++++
4 files changed, 32 insertions(+), 2 deletions(-)
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 f920c0553a3..441b3afbbcb 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
@@ -1197,6 +1197,8 @@ public class IoTDBSimpleQueryIT {
statement.execute("CREATE DATABASE root.sg1");
statement.execute(
"CREATE TIMESERIES root.sg1.d1.s4 WITH DATATYPE=DATE,
ENCODING=PLAIN, COMPRESSOR=SNAPPY");
+ statement.execute(
+ "CREATE TIMESERIES root.sg1.d1.s5 WITH DATATYPE=TIMESTAMP,
ENCODING=PLAIN, COMPRESSOR=SNAPPY");
try {
statement.execute("insert into root.sg1.d1(timestamp, s4) values(1,
'2022-04-31')");
fail();
@@ -1208,6 +1210,18 @@ public class IoTDBSimpleQueryIT {
+ "Please use YYYY-MM-DD format.]",
e.getMessage());
}
+ try {
+ statement.execute(
+ "insert into root.sg1.d1(timestamp, s5)
values(1999-04-31T00:00:00.000+08:00, 1999-04-31T00:00:00.000+08:00)");
+ fail();
+ } catch (Exception e) {
+ assertEquals(
+ TSStatusCode.SEMANTIC_ERROR.getStatusCode()
+ + ": Input time format 1999-04-31T00:00:00.000+08:00 error. "
+ + "Input like yyyy-MM-dd HH:mm:ss, yyyy-MM-ddTHH:mm:ss "
+ + "or refer to user document for more info.",
+ e.getMessage());
+ }
} catch (SQLException e) {
fail();
}
diff --git
a/integration-test/src/test/java/org/apache/iotdb/subscription/it/triple/regression/param/IoTDBTestParamTopicIT.java
b/integration-test/src/test/java/org/apache/iotdb/subscription/it/triple/regression/param/IoTDBTestParamTopicIT.java
index 89ca62bfb45..bad7f39bda1 100644
---
a/integration-test/src/test/java/org/apache/iotdb/subscription/it/triple/regression/param/IoTDBTestParamTopicIT.java
+++
b/integration-test/src/test/java/org/apache/iotdb/subscription/it/triple/regression/param/IoTDBTestParamTopicIT.java
@@ -184,7 +184,7 @@ public class IoTDBTestParamTopicIT extends
AbstractSubscriptionRegressionIT {
printTopics("testCreateTopic_invalidTime5");
}
- @Test
+ @Test(expected = StatementExecutionException.class)
public void testCreateTopic_invalidTime6()
throws IoTDBConnectionException,
StatementExecutionException,
diff --git
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/DateTimeUtils.java
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/DateTimeUtils.java
index 6f7e7179858..a63eea9fe44 100644
---
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/DateTimeUtils.java
+++
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/DateTimeUtils.java
@@ -42,6 +42,7 @@ import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.time.format.DateTimeParseException;
+import java.time.format.ResolverStyle;
import java.time.format.SignStyle;
import java.time.temporal.ChronoField;
import java.util.Calendar;
@@ -475,7 +476,8 @@ public class DateTimeUtils {
/** such as '2011.12.03 10:15:30+01:00' or '2011.12.03
10:15:30.123456789+01:00'. */
.appendOptional(ISO_OFFSET_DATE_TIME_WITH_DOT_WITH_SPACE_NS)
- .toFormatter();
+ .toFormatter()
+ .withResolverStyle(ResolverStyle.STRICT);
public static long convertTimestampOrDatetimeStrToLongWithDefaultZone(String
timeStr) {
try {
diff --git
a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/utils/DateTimeUtilsTest.java
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/utils/DateTimeUtilsTest.java
index 0e99f01fe8a..676ca09c7cd 100644
---
a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/utils/DateTimeUtilsTest.java
+++
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/utils/DateTimeUtilsTest.java
@@ -32,6 +32,7 @@ import java.time.ZonedDateTime;
import java.util.TimeZone;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
public class DateTimeUtilsTest {
@@ -77,6 +78,19 @@ public class DateTimeUtilsTest {
testConvertDateStrToLong(zoneOffset, zoneId, timestamp1 + delta);
}
+ @Test
+ public void convertDatetimeStrToLongTest4() {
+ zoneOffset = ZoneOffset.UTC;
+ try {
+ DateTimeUtils.convertDatetimeStrToLong("1999-02-29T00:00:00.000",
zoneOffset, 0, "ms");
+ fail();
+ } catch (Exception e) {
+ assertEquals(
+ "Text '1999-02-29T00:00:00.000+00:00' could not be parsed: Invalid
date 'February 29' as '1999' is not a leap year",
+ e.getMessage());
+ }
+ }
+
/** Test time precision is ms. */
@Test
public void convertDurationStrToLongTest1() {