You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ji...@apache.org on 2024/12/18 08:12:55 UTC
(iotdb) 01/01: add test
This is an automated email from the ASF dual-hosted git repository.
jiangtian pushed a commit to branch fix_insert_long_min_max
in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit 6ef78aff8499be2fa7d0df3e98bc6b42fff5e856
Author: Tian Jiang <jt...@163.com>
AuthorDate: Wed Dec 18 16:15:33 2024 +0800
add test
---
.../iotdb/session/it/IoTDBSessionSimpleIT.java | 76 ++++++++++++++++++++++
.../db/queryengine/plan/parser/ASTVisitor.java | 3 +-
.../iotdb/db/utils/TimestampPrecisionUtils.java | 10 ++-
.../conf/iotdb-system.properties.template | 2 +-
4 files changed, 86 insertions(+), 5 deletions(-)
diff --git a/integration-test/src/test/java/org/apache/iotdb/session/it/IoTDBSessionSimpleIT.java b/integration-test/src/test/java/org/apache/iotdb/session/it/IoTDBSessionSimpleIT.java
index 7cfbed9fabe..f06bd2ba38f 100644
--- a/integration-test/src/test/java/org/apache/iotdb/session/it/IoTDBSessionSimpleIT.java
+++ b/integration-test/src/test/java/org/apache/iotdb/session/it/IoTDBSessionSimpleIT.java
@@ -36,12 +36,17 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.tsfile.common.conf.TSFileConfig;
import org.apache.tsfile.common.constant.TsFileConstant;
import org.apache.tsfile.enums.TSDataType;
+import org.apache.tsfile.exception.write.WriteProcessException;
+import org.apache.tsfile.file.metadata.IDeviceID;
+import org.apache.tsfile.file.metadata.IDeviceID.Factory;
import org.apache.tsfile.file.metadata.enums.CompressionType;
import org.apache.tsfile.file.metadata.enums.TSEncoding;
import org.apache.tsfile.read.common.Field;
import org.apache.tsfile.read.common.RowRecord;
import org.apache.tsfile.utils.Binary;
import org.apache.tsfile.utils.BitMap;
+import org.apache.tsfile.write.TsFileWriter;
+import org.apache.tsfile.write.record.TSRecord;
import org.apache.tsfile.write.record.Tablet;
import org.apache.tsfile.write.schema.IMeasurementSchema;
import org.apache.tsfile.write.schema.MeasurementSchema;
@@ -55,6 +60,8 @@ import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.io.File;
+import java.io.IOException;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.Arrays;
@@ -1859,4 +1866,73 @@ public class IoTDBSessionSimpleIT {
e.printStackTrace();
}
}
+
+ @Test
+ @Category({LocalStandaloneIT.class, ClusterIT.class})
+ public void insertMinMaxTimeTest() throws IoTDBConnectionException, StatementExecutionException {
+ EnvFactory.getEnv().cleanClusterEnvironment();
+ EnvFactory.getEnv().getConfig().getCommonConfig().setTimestampPrecisionCheckEnabled(false);
+ EnvFactory.getEnv().initClusterEnvironment();
+ try {
+ try (ISession session = EnvFactory.getEnv().getSessionConnection()) {
+ session.executeNonQueryStatement(
+ String.format("INSERT INTO root.test.d1(timestamp, s1) VALUES (%d, 1)", Long.MIN_VALUE));
+ session.executeNonQueryStatement(
+ String.format("INSERT INTO root.test.d1(timestamp, s1) VALUES (%d, 1)", Long.MAX_VALUE));
+
+ SessionDataSet dataSet = session.executeQueryStatement("SELECT * FROM root.test.d1");
+ RowRecord record = dataSet.next();
+ assertEquals(Long.MIN_VALUE, record.getTimestamp());
+ record = dataSet.next();
+ assertEquals(Long.MAX_VALUE, record.getTimestamp());
+ assertFalse(dataSet.hasNext());
+
+ session.executeNonQueryStatement("FLUSH");
+ dataSet = session.executeQueryStatement("SELECT * FROM root.test.d1");
+ record = dataSet.next();
+ assertEquals(Long.MIN_VALUE, record.getTimestamp());
+ record = dataSet.next();
+ assertEquals(Long.MAX_VALUE, record.getTimestamp());
+ assertFalse(dataSet.hasNext());
+ }
+ } finally {
+ EnvFactory.getEnv().getConfig().getCommonConfig().setTimestampPrecisionCheckEnabled(true);
+ }
+ }
+
+ @Test
+ @Category({LocalStandaloneIT.class, ClusterIT.class})
+ public void loadMinMaxTimeTest()
+ throws IoTDBConnectionException,
+ StatementExecutionException,
+ IOException,
+ WriteProcessException {
+ File file = new File("target", "test.tsfile");
+ try (TsFileWriter writer = new TsFileWriter(file)) {
+ IDeviceID deviceID = Factory.DEFAULT_FACTORY.create(new String[] {"root", "test", "d1"});
+ writer.registerTimeseries(deviceID, new MeasurementSchema("s1", TSDataType.INT32));
+ TSRecord record = new TSRecord(deviceID, Long.MIN_VALUE);
+ record.addPoint("s1", 1);
+ writer.writeRecord(record);
+ record.setTime(Long.MAX_VALUE);
+ }
+
+ EnvFactory.getEnv().cleanClusterEnvironment();
+ EnvFactory.getEnv().getConfig().getCommonConfig().setTimestampPrecisionCheckEnabled(false);
+ EnvFactory.getEnv().initClusterEnvironment();
+ try {
+ try (ISession session = EnvFactory.getEnv().getSessionConnection()) {
+ session.executeNonQueryStatement("LOAD " + file.getAbsolutePath());
+
+ SessionDataSet dataSet = session.executeQueryStatement("SELECT * FROM root.test.d1");
+ RowRecord record = dataSet.next();
+ assertEquals(Long.MIN_VALUE, record.getTimestamp());
+ record = dataSet.next();
+ assertEquals(Long.MAX_VALUE, record.getTimestamp());
+ assertFalse(dataSet.hasNext());
+ }
+ } finally {
+ EnvFactory.getEnv().getConfig().getCommonConfig().setTimestampPrecisionCheckEnabled(true);
+ }
+ }
}
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/parser/ASTVisitor.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/parser/ASTVisitor.java
index 60bfcb81cd0..ebc84c33a45 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/parser/ASTVisitor.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/parser/ASTVisitor.java
@@ -1995,12 +1995,13 @@ public class ASTVisitor extends IoTDBSqlParserBaseVisitor<Statement> {
if (constant.INTEGER_LITERAL() != null) {
try {
if (constant.MINUS() != null) {
- return -Long.parseLong(constant.INTEGER_LITERAL().getText());
+ return Long.parseLong("-" + constant.INTEGER_LITERAL().getText());
}
return Long.parseLong(constant.INTEGER_LITERAL().getText());
} catch (NumberFormatException e) {
throw new SemanticException(
String.format(
+ "Failed to parse the timestamp: " + e.getMessage() +
"Current system timestamp precision is %s, "
+ "please check whether the timestamp %s is correct.",
TIMESTAMP_PRECISION, constant.INTEGER_LITERAL().getText()));
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/TimestampPrecisionUtils.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/TimestampPrecisionUtils.java
index 768d0030e96..fb0604d0919 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/TimestampPrecisionUtils.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/TimestampPrecisionUtils.java
@@ -73,8 +73,10 @@ public class TimestampPrecisionUtils {
if (time > 10_000_000_000_000L) {
throw new SemanticException(
String.format(
+ "The timestamp is unexpectedly large, you may forget to set the timestamp precision." +
"Current system timestamp precision is %s, "
- + "please check whether the timestamp %s is correct.",
+ + "please check whether the timestamp %s is correct." +
+ "If you insist to insert this timestamp, please set timestamp_precision_check_enabled=false and restart the server.",
TIMESTAMP_PRECISION, time));
}
break;
@@ -82,8 +84,10 @@ public class TimestampPrecisionUtils {
if (time > 10_000_000_000_000_000L) {
throw new SemanticException(
String.format(
- "Current system timestamp precision is %s, "
- + "please check whether the timestamp %s is correct.",
+ "The timestamp is unexpectedly large, you may forget to set the timestamp precision." +
+ "Current system timestamp precision is %s, "
+ + "please check whether the timestamp %s is correct." +
+ "If you insist to insert this timestamp, please set timestamp_precision_check_enabled=false and restart the server.",
TIMESTAMP_PRECISION, time));
}
break;
diff --git a/iotdb-core/node-commons/src/assembly/resources/conf/iotdb-system.properties.template b/iotdb-core/node-commons/src/assembly/resources/conf/iotdb-system.properties.template
index f370aebbfa6..705fe85d757 100644
--- a/iotdb-core/node-commons/src/assembly/resources/conf/iotdb-system.properties.template
+++ b/iotdb-core/node-commons/src/assembly/resources/conf/iotdb-system.properties.template
@@ -1070,7 +1070,7 @@ timestamp_precision=ms
# When the timestamp precision check is enabled, the timestamps those are over 13 digits for ms precision, or over 16 digits for us precision are not allowed to be inserted.
# For all precisions, ms, us and ns, the timestamps cannot exceed the range of [-9223372036854775808, 9223372036854775807], regardless of whether the check is enabled or not.
-# effectiveMode: first_start
+# effectiveMode: restart
# Datatype: Boolean
timestamp_precision_check_enabled=true