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 67642d6dd37 Added check for table TTL to ensure that it's equal to or
greater than 0
67642d6dd37 is described below
commit 67642d6dd373f0375412d701f5f6e0397f9bb5bd
Author: Caideyipi <[email protected]>
AuthorDate: Wed Aug 14 17:45:34 2024 +0800
Added check for table TTL to ensure that it's equal to or greater than 0
---
.../iotdb/relational/it/schema/IoTDBTableIT.java | 19 +++++++++++++++++++
.../plan/execution/config/TableConfigTaskVisitor.java | 13 +++++++++++--
2 files changed, 30 insertions(+), 2 deletions(-)
diff --git
a/integration-test/src/test/java/org/apache/iotdb/relational/it/schema/IoTDBTableIT.java
b/integration-test/src/test/java/org/apache/iotdb/relational/it/schema/IoTDBTableIT.java
index 2688ac8b692..dd930228612 100644
---
a/integration-test/src/test/java/org/apache/iotdb/relational/it/schema/IoTDBTableIT.java
+++
b/integration-test/src/test/java/org/apache/iotdb/relational/it/schema/IoTDBTableIT.java
@@ -160,6 +160,25 @@ public class IoTDBTableIT {
assertEquals("701: Table property unknown is currently not allowed.",
e.getMessage());
}
+ try {
+ statement.execute(
+ "create table table2(region_id STRING ID, plant_id STRING ID,
device_id STRING ID, model STRING ATTRIBUTE, temperature FLOAT MEASUREMENT,
humidity DOUBLE MEASUREMENT) with (TTL=null)");
+ fail();
+ } catch (final SQLException e) {
+ assertEquals(
+ "701: TTL' value must be a LongLiteral, but now is NullLiteral,
value: null",
+ e.getMessage());
+ }
+
+ try {
+ statement.execute(
+ "create table table2(region_id STRING ID, plant_id STRING ID,
device_id STRING ID, model STRING ATTRIBUTE, temperature FLOAT MEASUREMENT,
humidity DOUBLE MEASUREMENT) with (TTL=-1)");
+ fail();
+ } catch (final SQLException e) {
+ assertEquals(
+ "701: TTL' value must be equal to or greater than 0, but now is:
-1", e.getMessage());
+ }
+
try {
statement.execute(
"create table table2(region_id TEXT ID, plant_id STRING ID,
device_id STRING ID, model STRING ATTRIBUTE, temperature FLOAT MEASUREMENT,
humidity DOUBLE MEASUREMENT) with (TTL=3600000)");
diff --git
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/TableConfigTaskVisitor.java
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/TableConfigTaskVisitor.java
index 46bd1139943..c3ef4c4d42d 100644
---
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/TableConfigTaskVisitor.java
+++
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/TableConfigTaskVisitor.java
@@ -182,11 +182,20 @@ public class TableConfigTaskVisitor extends
AstVisitor<IConfigTask, MPPQueryCont
// Ignore default values
continue;
}
+ // TODO: support validation for other properties
if (!(value instanceof LongLiteral)) {
throw new SemanticException(
- "TTL' value must be a LongLiteral, but now is: " +
value.toString());
+ "TTL' value must be a LongLiteral, but now is "
+ + (Objects.nonNull(value) ?
value.getClass().getSimpleName() : null)
+ + ", value: "
+ + value);
}
- map.put(key, String.valueOf(((LongLiteral) value).getParsedValue()));
+ final long parsedValue = ((LongLiteral) value).getParsedValue();
+ if (parsedValue < 0) {
+ throw new SemanticException(
+ "TTL' value must be equal to or greater than 0, but now is: "
+ value);
+ }
+ map.put(key, String.valueOf(parsedValue));
}
} else {
throw new SemanticException("Table property " + key + " is currently
not allowed.");