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/08/09 02:32:46 UTC
(iotdb) branch ty/TableModelGrammar updated: Altered the create table / database behaviour to keep up with the definition
This is an automated email from the ASF dual-hosted git repository.
jackietien pushed a commit to branch ty/TableModelGrammar
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/ty/TableModelGrammar by this push:
new ddc2ac5c4a9 Altered the create table / database behaviour to keep up with the definition
ddc2ac5c4a9 is described below
commit ddc2ac5c4a971fcb5af757be2a641e30ca13ea35
Author: Caideyipi <87...@users.noreply.github.com>
AuthorDate: Fri Aug 9 10:32:39 2024 +0800
Altered the create table / database behaviour to keep up with the definition
---
.../relational/it/schema/IoTDBDatabaseIT.java | 15 +++++++++
.../iotdb/relational/it/schema/IoTDBTableIT.java | 3 ++
.../manager/schema/ClusterSchemaManager.java | 16 ++-------
.../config/executor/ClusterConfigTaskExecutor.java | 39 ++++++++++++++++++----
.../db/relational/grammar/sql/RelationalSql.g4 | 2 +-
5 files changed, 55 insertions(+), 20 deletions(-)
diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/schema/IoTDBDatabaseIT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/schema/IoTDBDatabaseIT.java
index 6f123efbc24..c6bb263dc5d 100644
--- a/integration-test/src/test/java/org/apache/iotdb/relational/it/schema/IoTDBDatabaseIT.java
+++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/schema/IoTDBDatabaseIT.java
@@ -164,6 +164,21 @@ public class IoTDBDatabaseIT {
// statement.execute("use \"a.b\"");
// statement.execute("drop database \"a.b\"");
+ // Test length limitation
+ statement.execute(
+ "create database thisDatabaseLengthIsPreciselySixtyFourThusItCanBeNormallyCreated");
+
+ try {
+ statement.execute(
+ "create database thisDatabaseLengthHasExceededSixtyFourThusItCantBeNormallyCreated");
+ fail(
+ "create database thisDatabaseLengthHasExceededSixtyFourThusItCantBeNormallyCreated shouldn't succeed because it's length has exceeded 64");
+ } catch (SQLException e) {
+ assertTrue(
+ e.getMessage(),
+ e.getMessage().contains("the length of database name shall not exceed 64"));
+ }
+
} catch (SQLException e) {
e.printStackTrace();
fail(e.getMessage());
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 183073682f6..2688ac8b692 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
@@ -221,6 +221,9 @@ public class IoTDBTableIT {
assertEquals(tableNames.length, cnt);
}
+ // Test create table with only time column
+ statement.execute("create table table3()");
+
// show tables from a non-exist database
try {
statement.executeQuery("SHOW tables from test3");
diff --git a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/schema/ClusterSchemaManager.java b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/schema/ClusterSchemaManager.java
index c1f028a1049..871f148873c 100644
--- a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/schema/ClusterSchemaManager.java
+++ b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/schema/ClusterSchemaManager.java
@@ -22,7 +22,6 @@ package org.apache.iotdb.confignode.manager.schema;
import org.apache.iotdb.common.rpc.thrift.TConsensusGroupType;
import org.apache.iotdb.common.rpc.thrift.TDataNodeLocation;
import org.apache.iotdb.common.rpc.thrift.TSStatus;
-import org.apache.iotdb.commons.exception.IllegalPathException;
import org.apache.iotdb.commons.exception.MetadataException;
import org.apache.iotdb.commons.path.PartialPath;
import org.apache.iotdb.commons.path.PathPatternTree;
@@ -105,8 +104,6 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Collectors;
-import static org.apache.iotdb.commons.conf.IoTDBConstant.MAX_DATABASE_NAME_LENGTH;
-
/** The ClusterSchemaManager Manages cluster schemaengine read and write requests. */
public class ClusterSchemaManager {
@@ -141,16 +138,9 @@ public class ClusterSchemaManager {
// ======================================================
/** Set Database */
- public TSStatus setDatabase(DatabaseSchemaPlan databaseSchemaPlan, boolean isGeneratedByPipe) {
+ public TSStatus setDatabase(
+ final DatabaseSchemaPlan databaseSchemaPlan, final boolean isGeneratedByPipe) {
TSStatus result;
- if (databaseSchemaPlan.getSchema().getName().length() > MAX_DATABASE_NAME_LENGTH) {
- IllegalPathException illegalPathException =
- new IllegalPathException(
- databaseSchemaPlan.getSchema().getName(),
- "the length of database name shall not exceed " + MAX_DATABASE_NAME_LENGTH);
- return RpcUtils.getStatus(
- illegalPathException.getErrorCode(), illegalPathException.getMessage());
- }
if (getPartitionManager().isDatabasePreDeleted(databaseSchemaPlan.getSchema().getName())) {
return RpcUtils.getStatus(
@@ -185,7 +175,7 @@ public class ClusterSchemaManager {
databaseSchemaPlan.getSchema().getSchemaReplicationFactor());
// Adjust the maximum RegionGroup number of each Database
adjustMaxRegionGroupNum();
- } catch (ConsensusException e) {
+ } catch (final ConsensusException e) {
LOGGER.warn(CONSENSUS_WRITE_ERROR, e);
result = new TSStatus(TSStatusCode.EXECUTE_STATEMENT_ERROR.getStatusCode());
result.setMessage(e.getMessage());
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/executor/ClusterConfigTaskExecutor.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/executor/ClusterConfigTaskExecutor.java
index bb15dc94ee9..fcd7fe48de6 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/executor/ClusterConfigTaskExecutor.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/executor/ClusterConfigTaskExecutor.java
@@ -280,6 +280,7 @@ import java.util.Map;
import java.util.TreeMap;
import java.util.stream.Collectors;
+import static org.apache.iotdb.commons.conf.IoTDBConstant.MAX_DATABASE_NAME_LENGTH;
import static org.apache.iotdb.commons.schema.SchemaConstant.ALL_MATCH_SCOPE;
import static org.apache.iotdb.commons.schema.SchemaConstant.ALL_RESULT_NODES;
import static org.apache.iotdb.db.protocol.client.ConfigNodeClient.MSG_RECONNECTION_FAIL;
@@ -313,15 +314,29 @@ public class ClusterConfigTaskExecutor implements IConfigTaskExecutor {
@Override
public SettableFuture<ConfigTaskResult> setDatabase(
- DatabaseSchemaStatement databaseSchemaStatement) {
- SettableFuture<ConfigTaskResult> future = SettableFuture.create();
+ final DatabaseSchemaStatement databaseSchemaStatement) {
+ final SettableFuture<ConfigTaskResult> future = SettableFuture.create();
+ // Check database length here
+ // We need to calculate the database name without "root."
+ final String databaseName = databaseSchemaStatement.getDatabasePath().getFullPath();
+ if (databaseName.length() > MAX_DATABASE_NAME_LENGTH) {
+ final IllegalPathException illegalPathException =
+ new IllegalPathException(
+ databaseName,
+ "the length of database name shall not exceed " + MAX_DATABASE_NAME_LENGTH);
+ future.setException(
+ new IoTDBException(
+ illegalPathException.getMessage(), illegalPathException.getErrorCode()));
+ return future;
+ }
+
// Construct request using statement
- TDatabaseSchema databaseSchema =
+ final TDatabaseSchema databaseSchema =
DatabaseSchemaTask.constructDatabaseSchema(databaseSchemaStatement);
- try (ConfigNodeClient configNodeClient =
+ try (final ConfigNodeClient configNodeClient =
CONFIG_NODE_CLIENT_MANAGER.borrowClient(ConfigNodeInfo.CONFIG_REGION_ID)) {
// Send request to some API server
- TSStatus tsStatus = configNodeClient.setDatabase(databaseSchema);
+ final TSStatus tsStatus = configNodeClient.setDatabase(databaseSchema);
// Get response or throw exception
if (TSStatusCode.SUCCESS_STATUS.getStatusCode() != tsStatus.getCode()) {
// If database already exists when loading, we do not throw exceptions to avoid printing too
@@ -340,7 +355,7 @@ public class ClusterConfigTaskExecutor implements IConfigTaskExecutor {
} else {
future.set(new ConfigTaskResult(TSStatusCode.SUCCESS_STATUS));
}
- } catch (ClientManagerException | TException e) {
+ } catch (final ClientManagerException | TException e) {
future.setException(e);
}
return future;
@@ -2975,6 +2990,18 @@ public class ClusterConfigTaskExecutor implements IConfigTaskExecutor {
@Override
public SettableFuture<ConfigTaskResult> createDatabase(final CreateDB createDB) {
final SettableFuture<ConfigTaskResult> future = SettableFuture.create();
+ // Check database length here
+ // We need to calculate the database name without "root."
+ if (createDB.getDbName().length() > MAX_DATABASE_NAME_LENGTH) {
+ final IllegalPathException illegalPathException =
+ new IllegalPathException(
+ createDB.getDbName(),
+ "the length of database name shall not exceed " + MAX_DATABASE_NAME_LENGTH);
+ future.setException(
+ new IoTDBException(
+ illegalPathException.getMessage(), illegalPathException.getErrorCode()));
+ return future;
+ }
// Construct request using statement
final TDatabaseSchema databaseSchema = new TDatabaseSchema();
databaseSchema.setName(ROOT + PATH_SEPARATOR_CHAR + createDB.getDbName());
diff --git a/iotdb-core/relational-grammar/src/main/antlr4/org/apache/iotdb/db/relational/grammar/sql/RelationalSql.g4 b/iotdb-core/relational-grammar/src/main/antlr4/org/apache/iotdb/db/relational/grammar/sql/RelationalSql.g4
index 0d7188d0245..e0359b2bf9d 100644
--- a/iotdb-core/relational-grammar/src/main/antlr4/org/apache/iotdb/db/relational/grammar/sql/RelationalSql.g4
+++ b/iotdb-core/relational-grammar/src/main/antlr4/org/apache/iotdb/db/relational/grammar/sql/RelationalSql.g4
@@ -130,7 +130,7 @@ dropDbStatement
// ------------------------------------------- Table Statement ---------------------------------------------------------
createTableStatement
: CREATE TABLE (IF NOT EXISTS)? qualifiedName
- '(' columnDefinition (',' columnDefinition)* ')'
+ '(' (columnDefinition (',' columnDefinition)*)? ')'
charsetDesc?
(WITH properties)?
;