You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ja...@apache.org on 2024/10/13 07:20:04 UTC
(iotdb) branch master updated: Modify the exception thrown when the date conversion year overflows
This is an automated email from the ASF dual-hosted git repository.
jackietien 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 04f9f80fc26 Modify the exception thrown when the date conversion year overflows
04f9f80fc26 is described below
commit 04f9f80fc267b10ce684d09f755340295ef03f39
Author: FearfulTomcat27 <14...@qq.com>
AuthorDate: Sun Oct 13 15:19:57 2024 +0800
Modify the exception thrown when the date conversion year overflows
---
.../scalar/IoTDBCastFunctionTableIT.java | 39 ++++++++++
.../scalar/IoTDBCastFunctionTableSpecialIT.java | 85 ++++++++++++++++++++++
.../it/query/old/query/IoTDBArithmeticTableIT.java | 23 ++++++
.../java/org/apache/iotdb/rpc/TSStatusCode.java | 1 +
.../ArithmeticBinaryColumnTransformer.ftl | 74 +++++++++++++++----
.../scalar/CastFunctionColumnTransformer.java | 72 ++++++++++--------
.../org/apache/iotdb/db/utils/DateTimeUtils.java | 34 ++++++---
.../apache/iotdb/db/utils/ErrorHandlingUtils.java | 3 +-
8 files changed, 274 insertions(+), 57 deletions(-)
diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/builtinfunction/scalar/IoTDBCastFunctionTableIT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/builtinfunction/scalar/IoTDBCastFunctionTableIT.java
index c390fd33f92..16075573251 100644
--- a/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/builtinfunction/scalar/IoTDBCastFunctionTableIT.java
+++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/builtinfunction/scalar/IoTDBCastFunctionTableIT.java
@@ -19,6 +19,7 @@
package org.apache.iotdb.relational.it.query.old.builtinfunction.scalar;
+import org.apache.iotdb.db.utils.DateTimeUtils;
import org.apache.iotdb.it.env.EnvFactory;
import org.apache.iotdb.it.framework.IoTDBTestRunner;
import org.apache.iotdb.itbase.category.TableClusterIT;
@@ -35,6 +36,7 @@ import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
+import static org.apache.iotdb.db.it.utils.TestUtils.tableAssertTestFail;
import static org.apache.iotdb.db.it.utils.TestUtils.tableResultSetEqualTest;
import static org.apache.iotdb.itbase.constant.TestConstant.TIMESTAMP_STR;
import static org.junit.Assert.fail;
@@ -93,6 +95,12 @@ public class IoTDBCastFunctionTableIT {
"INSERT INTO special(Time, device_id ,s6) values(2, 'd1', '1.1')",
"INSERT INTO special(Time, device_id ,s6) values(3, 'd1', '4e60')",
"INSERT INTO special(Time, device_id ,s6) values(4, 'd1', '4e60000')",
+ "flush",
+
+ // special cases for date and timestamp
+ "create table dateType(device_id STRING ID, s1 DATE MEASUREMENT, s2 TIMESTAMP MEASUREMENT)",
+ "INSERT INTO dateType(Time,device_id, s1, s2) values(1,'d1', '9999-12-31', 253402271999999)",
+ "INSERT INTO dateType(Time,device_id, s1, s2) values(2,'d1', '1000-01-01', -30610224000000)",
};
@BeforeClass
@@ -776,5 +784,36 @@ public class IoTDBCastFunctionTableIT {
}
}
+ @Test
+ public void testDateOutOfRange() {
+ tableAssertTestFail(
+ String.format(
+ "select CAST((s1 + %d) AS TIMESTAMP) from dateType where time = 1",
+ DateTimeUtils.correctPrecision(86400000)),
+ "752: Year must be between 1000 and 9999.",
+ DATABASE_NAME);
+
+ tableAssertTestFail(
+ String.format(
+ "select CAST((s2 + %d) AS DATE) from dateType where time = 1",
+ DateTimeUtils.correctPrecision(86400000)),
+ "752: Year must be between 1000 and 9999.",
+ DATABASE_NAME);
+
+ tableAssertTestFail(
+ String.format(
+ "select CAST((s1 - %d) AS TIMESTAMP) from dateType where time = 2",
+ DateTimeUtils.correctPrecision(86400000)),
+ "752: Year must be between 1000 and 9999.",
+ DATABASE_NAME);
+
+ tableAssertTestFail(
+ String.format(
+ "select CAST((s2 - %d) AS DATE) from dateType where time = 2",
+ DateTimeUtils.correctPrecision(86400000)),
+ "752: Year must be between 1000 and 9999.",
+ DATABASE_NAME);
+ }
+
// endregion
}
diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/builtinfunction/scalar/IoTDBCastFunctionTableSpecialIT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/builtinfunction/scalar/IoTDBCastFunctionTableSpecialIT.java
new file mode 100644
index 00000000000..c06ac09a010
--- /dev/null
+++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/builtinfunction/scalar/IoTDBCastFunctionTableSpecialIT.java
@@ -0,0 +1,85 @@
+/*
+ * Licensed 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.relational.it.query.old.builtinfunction.scalar;
+
+import org.apache.iotdb.it.env.EnvFactory;
+import org.apache.iotdb.it.framework.IoTDBTestRunner;
+import org.apache.iotdb.itbase.category.TableClusterIT;
+import org.apache.iotdb.itbase.category.TableLocalStandaloneIT;
+import org.apache.iotdb.itbase.env.BaseEnv;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+
+import java.sql.Connection;
+import java.sql.Statement;
+
+import static org.apache.iotdb.db.it.utils.TestUtils.tableAssertTestFail;
+
+@RunWith(IoTDBTestRunner.class)
+@Category({TableLocalStandaloneIT.class, TableClusterIT.class})
+public class IoTDBCastFunctionTableSpecialIT {
+
+ private static final String DATABASE_NAME = "db";
+
+ private static final String[] SQLs =
+ new String[] {
+ "CREATE DATABASE " + DATABASE_NAME,
+ "USE " + DATABASE_NAME,
+ "create table special(device_id STRING ID, s1 DATE MEASUREMENT)",
+ "INSERT INTO special(time, device_id, s1) values(1, 'd1', '2262-04-13')",
+ "INSERT INTO special(time, device_id, s1) values(2, 'd1', '1677-09-21')",
+ };
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+ EnvFactory.getEnv().getConfig().getCommonConfig().setTimestampPrecision("ns");
+ EnvFactory.getEnv().initClusterEnvironment();
+ insertData();
+ }
+
+ protected static void insertData() {
+ try (Connection connection = EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT);
+ Statement statement = connection.createStatement()) {
+
+ for (String sql : SQLs) {
+ statement.execute(sql);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @AfterClass
+ public static void tearDown() throws Exception {
+ EnvFactory.getEnv().cleanClusterEnvironment();
+ }
+
+ @Test
+ public void testTimestampOverflow() {
+ tableAssertTestFail(
+ "select cast(s1 as TIMESTAMP) from special where time = 1",
+ "750: Timestamp overflow",
+ DATABASE_NAME);
+
+ tableAssertTestFail(
+ "select cast(s1 as TIMESTAMP) from special where time = 2",
+ "750: Timestamp overflow",
+ DATABASE_NAME);
+ }
+}
diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/query/IoTDBArithmeticTableIT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/query/IoTDBArithmeticTableIT.java
index 5acc139d539..229e28f863d 100644
--- a/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/query/IoTDBArithmeticTableIT.java
+++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/query/IoTDBArithmeticTableIT.java
@@ -14,6 +14,7 @@
package org.apache.iotdb.relational.it.query.old.query;
+import org.apache.iotdb.db.utils.DateTimeUtils;
import org.apache.iotdb.it.env.EnvFactory;
import org.apache.iotdb.it.framework.IoTDBTestRunner;
import org.apache.iotdb.itbase.category.TableClusterIT;
@@ -50,6 +51,8 @@ public class IoTDBArithmeticTableIT {
private static final String DATABASE_NAME = "test";
+ private static final long MILLISECONDS_IN_DAY = 24 * 60 * 60 * 1000;
+
private static final double[][] BASE_ANS = {{1, 1, 1.0, 1.0}, {2, 2, 2.0, 2.0}, {3, 3, 3.0, 3.0}};
private static final Map<String, BiFunction<Double, Double, Double>> OPERATIONS = new HashMap<>();
@@ -69,6 +72,9 @@ public class IoTDBArithmeticTableIT {
"insert into table1(device, time, s1, s2, s3, s4, s5, s6, s7, s8) values ('d1', 1, 1, 1, 1.0, 1.0, '2024-01-01', 10, true, 'test')",
"insert into table1(device, time, s1, s2, s3, s4, s5, s6, s7, s8) values ('d1', 2, 2, 2, 2.0, 2.0, '2024-02-01', 20, true, 'test')",
"insert into table1(device, time, s1, s2, s3, s4, s5, s6, s7, s8) values ('d1', 3, 3, 3, 3.0, 3.0, '2024-03-01', 30, true, 'test')",
+ "CREATE TABLE table2 (device STRING ID, date DATE MEASUREMENT)",
+ "insert into table2(device, time, date) values ('d1', 1, '9999-12-31')",
+ "insert into table2(device, time, date) values ('d1', 2, '1000-01-01')",
};
@BeforeClass
@@ -334,6 +340,23 @@ public class IoTDBArithmeticTableIT {
tableAssertTestFail("select s2%0 from table1", "751: Division by zero", "test");
}
+ @Test
+ public void testDateOutOfRange() {
+ tableAssertTestFail(
+ String.format(
+ "select date + %s from table2 where time = 1",
+ DateTimeUtils.correctPrecision(MILLISECONDS_IN_DAY)),
+ "752: Year must be between 1000 and 9999.",
+ "test");
+
+ tableAssertTestFail(
+ String.format(
+ "select date - %s from table2 where time = 2",
+ DateTimeUtils.correctPrecision(MILLISECONDS_IN_DAY)),
+ "752: Year must be between 1000 and 9999.",
+ "test");
+ }
+
private void testBinaryDifferentCombinationsFail(
String[] operators,
String[] leftOperands,
diff --git a/iotdb-client/service-rpc/src/main/java/org/apache/iotdb/rpc/TSStatusCode.java b/iotdb-client/service-rpc/src/main/java/org/apache/iotdb/rpc/TSStatusCode.java
index 3b561b2b327..0f091451e5b 100644
--- a/iotdb-client/service-rpc/src/main/java/org/apache/iotdb/rpc/TSStatusCode.java
+++ b/iotdb-client/service-rpc/src/main/java/org/apache/iotdb/rpc/TSStatusCode.java
@@ -136,6 +136,7 @@ public enum TSStatusCode {
// Arithmetic
NUMERIC_VALUE_OUT_OF_RANGE(750),
DIVISION_BY_ZERO(751),
+ DATE_OUT_OF_RANGE(752),
// Authentication
INIT_AUTH_ERROR(800),
diff --git a/iotdb-core/datanode/src/main/codegen/templates/ArithmeticBinaryColumnTransformer.ftl b/iotdb-core/datanode/src/main/codegen/templates/ArithmeticBinaryColumnTransformer.ftl
index a44e58db8f1..a197e48a205 100644
--- a/iotdb-core/datanode/src/main/codegen/templates/ArithmeticBinaryColumnTransformer.ftl
+++ b/iotdb-core/datanode/src/main/codegen/templates/ArithmeticBinaryColumnTransformer.ftl
@@ -42,6 +42,11 @@ import org.apache.tsfile.utils.DateUtils;
import java.time.ZoneId;
+<#if first.instance == "DATE">
+import java.time.format.DateTimeParseException;
+
+import static org.apache.iotdb.rpc.TSStatusCode.DATE_OUT_OF_RANGE;
+</#if>
<#if first.dataType == "int" || second.dataType == "int" || first.dataType == "long" || second.dataType == "long">
import static org.apache.iotdb.rpc.TSStatusCode.NUMERIC_VALUE_OUT_OF_RANGE;
</#if>
@@ -103,10 +108,21 @@ public class ${className} extends BinaryColumnTransformer {
<#if first.instance == "DATE">
<#--Date + int || Date + long-->
try{
- long timestamp = Math.addExact(DateTimeUtils.correctPrecision(DateUtils.parseIntToTimestamp(left,zoneId)), right);
- return DateUtils.parseDateExpressionToInt(DateTimeUtils.convertToLocalDate(timestamp, zoneId));
+ long timestamp =
+ Math.addExact(
+ DateTimeUtils.correctPrecision(DateUtils.parseIntToTimestamp(left,zoneId)), right);
+ return DateUtils.parseDateExpressionToInt(
+ DateTimeUtils.convertToLocalDate(timestamp, zoneId));
}catch (ArithmeticException e){
- throw new IoTDBRuntimeException(String.format("long ${operator.name} overflow: %s + %s", left, right),NUMERIC_VALUE_OUT_OF_RANGE.getStatusCode(),true);
+ throw new IoTDBRuntimeException(
+ String.format("long ${operator.name} overflow: %s + %s", left, right),
+ NUMERIC_VALUE_OUT_OF_RANGE.getStatusCode(),
+ true);
+ }catch (DateTimeParseException e) {
+ throw new IoTDBRuntimeException(
+ "Year must be between 1000 and 9999.",
+ DATE_OUT_OF_RANGE.getStatusCode(),
+ true);
}
<#else>
<#--Timestamp + int || Timestamp + long-->
@@ -121,17 +137,31 @@ public class ${className} extends BinaryColumnTransformer {
<#if first.instance == "DATE">
<#--Date - int || Date - long-->
try{
- long timestamp = Math.subtractExact(DateTimeUtils.correctPrecision(DateUtils.parseIntToTimestamp(left, zoneId)), right);
- return DateUtils.parseDateExpressionToInt(DateTimeUtils.convertToLocalDate(timestamp, zoneId));
+ long timestamp =
+ Math.subtractExact(
+ DateTimeUtils.correctPrecision(DateUtils.parseIntToTimestamp(left, zoneId)), right);
+ return DateUtils.parseDateExpressionToInt(
+ DateTimeUtils.convertToLocalDate(timestamp, zoneId));
}catch (ArithmeticException e){
- throw new IoTDBRuntimeException(String.format("long ${operator.name} overflow: %s - %s", left, right),NUMERIC_VALUE_OUT_OF_RANGE.getStatusCode(),true);
+ throw new IoTDBRuntimeException(
+ String.format("long ${operator.name} overflow: %s - %s", left, right),
+ NUMERIC_VALUE_OUT_OF_RANGE.getStatusCode(),
+ true);
+ }catch (DateTimeParseException e) {
+ throw new IoTDBRuntimeException(
+ "Year must be between 1000 and 9999.",
+ DATE_OUT_OF_RANGE.getStatusCode(),
+ true);
}
<#else>
<#--Timestamp - int || Timestamp - long-->
try{
return Math.subtractExact(left, right);
}catch (ArithmeticException e){
- throw new IoTDBRuntimeException(String.format("long ${operator.name} overflow: %s - %s", left, right),NUMERIC_VALUE_OUT_OF_RANGE.getStatusCode(),true);
+ throw new IoTDBRuntimeException(
+ String.format("long ${operator.name} overflow: %s - %s", left, right),
+ NUMERIC_VALUE_OUT_OF_RANGE.getStatusCode(),
+ true);
}
</#if>
<#break>
@@ -217,13 +247,19 @@ public class ${className} extends BinaryColumnTransformer {
long timestamp = Math.addExact(left,DateTimeUtils.correctPrecision(DateUtils.parseIntToTimestamp(right, zoneId)));
return DateUtils.parseDateExpressionToInt(DateTimeUtils.convertToLocalDate(timestamp, zoneId));
}catch (ArithmeticException e){
- throw new IoTDBRuntimeException(String.format("long ${operator.name} overflow: %s + %s", left, right),NUMERIC_VALUE_OUT_OF_RANGE.getStatusCode(),true);
+ throw new IoTDBRuntimeException(
+ String.format("long ${operator.name} overflow: %s + %s", left, right),
+ NUMERIC_VALUE_OUT_OF_RANGE.getStatusCode(),
+ true);
}
<#else>
try{
return Math.addExact(left, right);
}catch (ArithmeticException e){
- throw new IoTDBRuntimeException(String.format("long ${operator.name} overflow: %s + %s", left, right),NUMERIC_VALUE_OUT_OF_RANGE.getStatusCode(),true);
+ throw new IoTDBRuntimeException(
+ String.format("long ${operator.name} overflow: %s + %s", left, right),
+ NUMERIC_VALUE_OUT_OF_RANGE.getStatusCode(),
+ true);
}
</#if>
}
@@ -314,27 +350,39 @@ public class ${className} extends BinaryColumnTransformer {
try{
return Math.addExact(left, right);
}catch (ArithmeticException e){
- throw new IoTDBRuntimeException(String.format("${resultType} ${operator.name} overflow: %s + %s", left, right),NUMERIC_VALUE_OUT_OF_RANGE.getStatusCode(),false);
+ throw new IoTDBRuntimeException(
+ String.format("${resultType} ${operator.name} overflow: %s + %s", left, right),
+ NUMERIC_VALUE_OUT_OF_RANGE.getStatusCode(),
+ false);
}
<#break>
<#case "Subtraction">
try{
return Math.subtractExact(left, right);
}catch (ArithmeticException e){
- throw new IoTDBRuntimeException(String.format("${resultType} ${operator.name} overflow: %s - %s", left, right),NUMERIC_VALUE_OUT_OF_RANGE.getStatusCode(),false);
+ throw new IoTDBRuntimeException(
+ String.format("${resultType} ${operator.name} overflow: %s - %s", left, right),
+ NUMERIC_VALUE_OUT_OF_RANGE.getStatusCode(),
+ false);
}
<#break>
<#case "Multiplication">
try{
return Math.multiplyExact(left, right);
}catch (ArithmeticException e){
- throw new IoTDBRuntimeException(String.format("${resultType} ${operator.name} overflow: %s * %s", left, right),NUMERIC_VALUE_OUT_OF_RANGE.getStatusCode(),true);
+ throw new IoTDBRuntimeException(
+ String.format("${resultType} ${operator.name} overflow: %s * %s", left, right),
+ NUMERIC_VALUE_OUT_OF_RANGE.getStatusCode(),
+ true);
}
<#break>
<#case "Division">
try{
if (left == <#if first.dataType == "int">Integer.MIN_VALUE<#elseif first.dataType == "long">Long.MIN_VALUE</#if> && right == -1) {
- throw new IoTDBRuntimeException(String.format("${resultType} overflow: %s / %s", left, right),NUMERIC_VALUE_OUT_OF_RANGE.getStatusCode(),true);
+ throw new IoTDBRuntimeException(
+ String.format("${resultType} overflow: %s / %s", left, right),
+ NUMERIC_VALUE_OUT_OF_RANGE.getStatusCode(),
+ true);
}
return left / right;
}catch (ArithmeticException e){
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/CastFunctionColumnTransformer.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/CastFunctionColumnTransformer.java
index 2abeb2adc42..05b965a202d 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/CastFunctionColumnTransformer.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/CastFunctionColumnTransformer.java
@@ -19,6 +19,7 @@
package org.apache.iotdb.db.queryengine.transformation.dag.column.unary.scalar;
+import org.apache.iotdb.commons.exception.IoTDBRuntimeException;
import org.apache.iotdb.db.exception.sql.SemanticException;
import org.apache.iotdb.db.queryengine.plan.expression.multi.builtin.helper.CastFunctionHelper;
import org.apache.iotdb.db.queryengine.transformation.dag.column.ColumnTransformer;
@@ -38,6 +39,7 @@ import java.time.ZoneId;
import java.time.format.DateTimeParseException;
import static org.apache.iotdb.db.queryengine.plan.expression.multi.builtin.helper.CastFunctionHelper.ERROR_MSG;
+import static org.apache.iotdb.rpc.TSStatusCode.DATE_OUT_OF_RANGE;
public class CastFunctionColumnTransformer extends UnaryColumnTransformer {
@@ -178,38 +180,44 @@ public class CastFunctionColumnTransformer extends UnaryColumnTransformer {
}
private void castTimestamp(ColumnBuilder columnBuilder, long value) {
- switch (returnType.getTypeEnum()) {
- case INT32:
- returnType.writeInt(columnBuilder, (CastFunctionHelper.castLongToInt(value)));
- break;
- case DATE:
- returnType.writeInt(
- columnBuilder,
- DateUtils.parseDateExpressionToInt(DateTimeUtils.convertToLocalDate(value, zoneId)));
- break;
- case INT64:
- case TIMESTAMP:
- returnType.writeLong(columnBuilder, value);
- break;
- case FLOAT:
- returnType.writeFloat(columnBuilder, value);
- break;
- case DOUBLE:
- returnType.writeDouble(columnBuilder, value);
- break;
- case BOOLEAN:
- returnType.writeBoolean(columnBuilder, value != 0L);
- break;
- case TEXT:
- case STRING:
- returnType.writeBinary(
- columnBuilder, BytesUtils.valueOf(DateTimeUtils.convertLongToDate(value, zoneId)));
- break;
- case BLOB:
- returnType.writeBinary(columnBuilder, new Binary(BytesUtils.longToBytes(value)));
- break;
- default:
- throw new UnsupportedOperationException(String.format(ERROR_MSG, returnType.getTypeEnum()));
+ try {
+ switch (returnType.getTypeEnum()) {
+ case INT32:
+ returnType.writeInt(columnBuilder, (CastFunctionHelper.castLongToInt(value)));
+ break;
+ case DATE:
+ returnType.writeInt(
+ columnBuilder,
+ DateUtils.parseDateExpressionToInt(DateTimeUtils.convertToLocalDate(value, zoneId)));
+ break;
+ case INT64:
+ case TIMESTAMP:
+ returnType.writeLong(columnBuilder, value);
+ break;
+ case FLOAT:
+ returnType.writeFloat(columnBuilder, value);
+ break;
+ case DOUBLE:
+ returnType.writeDouble(columnBuilder, value);
+ break;
+ case BOOLEAN:
+ returnType.writeBoolean(columnBuilder, value != 0L);
+ break;
+ case TEXT:
+ case STRING:
+ returnType.writeBinary(
+ columnBuilder, BytesUtils.valueOf(DateTimeUtils.convertLongToDate(value, zoneId)));
+ break;
+ case BLOB:
+ returnType.writeBinary(columnBuilder, new Binary(BytesUtils.longToBytes(value)));
+ break;
+ default:
+ throw new UnsupportedOperationException(
+ String.format(ERROR_MSG, returnType.getTypeEnum()));
+ }
+ } catch (DateTimeParseException e) {
+ throw new IoTDBRuntimeException(
+ "Year must be between 1000 and 9999.", DATE_OUT_OF_RANGE.getStatusCode(), true);
}
}
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 95f24142229..285dd185393 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
@@ -19,6 +19,7 @@
package org.apache.iotdb.db.utils;
import org.apache.iotdb.commons.conf.CommonDescriptor;
+import org.apache.iotdb.commons.exception.IoTDBRuntimeException;
import org.apache.iotdb.commons.utils.TestOnly;
import org.apache.iotdb.db.protocol.session.SessionManager;
import org.apache.iotdb.db.qp.sql.IoTDBSqlParser;
@@ -49,6 +50,8 @@ import java.util.Calendar;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
+import static org.apache.iotdb.rpc.TSStatusCode.NUMERIC_VALUE_OUT_OF_RANGE;
+
public class DateTimeUtils {
private DateTimeUtils() {
@@ -59,17 +62,26 @@ public class DateTimeUtils {
CommonDescriptor.getInstance().getConfig().getTimestampPrecision();
public static long correctPrecision(long millis) {
- switch (TIMESTAMP_PRECISION) {
- case "us":
- case "microsecond":
- return millis * 1_000L;
- case "ns":
- case "nanosecond":
- return millis * 1_000_000L;
- case "ms":
- case "millisecond":
- default:
- return millis;
+ try {
+ switch (TIMESTAMP_PRECISION) {
+ case "us":
+ case "microsecond":
+ return Math.multiplyExact(millis, 1_000L);
+ case "ns":
+ case "nanosecond":
+ return Math.multiplyExact(millis, 1_000_000L);
+ case "ms":
+ case "millisecond":
+ default:
+ return millis;
+ }
+ } catch (ArithmeticException e) {
+ throw new IoTDBRuntimeException(
+ String.format(
+ "Timestamp overflow, Millisecond: %s , Timestamp precision: %s",
+ millis, TIMESTAMP_PRECISION),
+ NUMERIC_VALUE_OUT_OF_RANGE.getStatusCode(),
+ true);
}
}
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/ErrorHandlingUtils.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/ErrorHandlingUtils.java
index b232ea74bbc..b3b173ce37d 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/ErrorHandlingUtils.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/ErrorHandlingUtils.java
@@ -106,7 +106,8 @@ public class ErrorHandlingUtils {
|| status.getCode() == TSStatusCode.NO_PERMISSION.getStatusCode()
|| status.getCode() == TSStatusCode.ILLEGAL_PATH.getStatusCode()
|| status.getCode() == TSStatusCode.NUMERIC_VALUE_OUT_OF_RANGE.getStatusCode()
- || status.getCode() == TSStatusCode.DIVISION_BY_ZERO.getStatusCode()) {
+ || status.getCode() == TSStatusCode.DIVISION_BY_ZERO.getStatusCode()
+ || status.getCode() == TSStatusCode.DATE_OUT_OF_RANGE.getStatusCode()) {
LOGGER.warn(message);
} else {
LOGGER.warn(message, e);