Skip to content

Commit

Permalink
chore: relax table name constraint (#4766)
Browse files Browse the repository at this point in the history
chore/relax-table-name-constraint: Updated NAME_PATTERN to allow '@' and '#' characters and adjusted tests for new table name validation rules.
  • Loading branch information
v0y4g3r authored Sep 25, 2024
1 parent e3c0b54 commit cd4bf23
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/common/meta/src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ use crate::rpc::router::{region_distribution, RegionRoute, RegionStatus};
use crate::rpc::store::BatchDeleteRequest;
use crate::DatanodeId;

pub const NAME_PATTERN: &str = r"[a-zA-Z_:-][a-zA-Z0-9_:\-\.]*";
pub const NAME_PATTERN: &str = r"[a-zA-Z_:-][a-zA-Z0-9_:\-\.@#]*";
pub const MAINTENANCE_KEY: &str = "__maintenance";

const DATANODE_TABLE_KEY_PREFIX: &str = "__dn_table";
Expand Down
8 changes: 7 additions & 1 deletion src/operator/src/statement/ddl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ impl StatementExecutor {
ensure!(
NAME_PATTERN_REG.is_match(&create_table.table_name),
InvalidTableNameSnafu {
table_name: create_table.table_name.clone(),
table_name: &create_table.table_name,
}
);

Expand Down Expand Up @@ -1516,6 +1516,12 @@ mod test {
assert!(!NAME_PATTERN_REG.is_match("/adaf"));
assert!(!NAME_PATTERN_REG.is_match("🈲"));
assert!(NAME_PATTERN_REG.is_match("hello"));
assert!(NAME_PATTERN_REG.is_match("test@"));
assert!(!NAME_PATTERN_REG.is_match("@test"));
assert!(NAME_PATTERN_REG.is_match("test#"));
assert!(!NAME_PATTERN_REG.is_match("#test"));
assert!(!NAME_PATTERN_REG.is_match("@"));
assert!(!NAME_PATTERN_REG.is_match("#"));
}

#[tokio::test]
Expand Down
16 changes: 16 additions & 0 deletions tests/cases/standalone/common/create/create.result
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,22 @@ CREATE TABLE 'N.~' (i TIMESTAMP TIME INDEX);

Error: 1004(InvalidArguments), Invalid table name: N.~

CREATE TABLE `p_perftest001@cc3kvQ_D1D9H9GOZGMIY97TWH20R1LRC8U0SFBA` (i INTEGER, j TIMESTAMP TIME INDEX);

Affected Rows: 0

DROP TABLE `p_perftest001@cc3kvQ_D1D9H9GOZGMIY97TWH20R1LRC8U0SFBA`;

Affected Rows: 0

CREATE TABLE `p_perftest001#cc3kvQ_D1D9H9GOZGMIY97TWH20R1LRC8U0SFBA` (i INTEGER, j TIMESTAMP TIME INDEX);

Affected Rows: 0

DROP TABLE `p_perftest001#cc3kvQ_D1D9H9GOZGMIY97TWH20R1LRC8U0SFBA`;

Affected Rows: 0

CREATE TABLE neg_default_value_min(i TIMESTAMP TIME INDEX, j SMALLINT DEFAULT -32768);

Affected Rows: 0
Expand Down
8 changes: 8 additions & 0 deletions tests/cases/standalone/common/create/create.sql
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ CREATE TABLE test2 (i INTEGER, j TIMESTAMP TIME INDEX);

CREATE TABLE 'N.~' (i TIMESTAMP TIME INDEX);

CREATE TABLE `p_perftest001@cc3kvQ_D1D9H9GOZGMIY97TWH20R1LRC8U0SFBA` (i INTEGER, j TIMESTAMP TIME INDEX);

DROP TABLE `p_perftest001@cc3kvQ_D1D9H9GOZGMIY97TWH20R1LRC8U0SFBA`;

CREATE TABLE `p_perftest001#cc3kvQ_D1D9H9GOZGMIY97TWH20R1LRC8U0SFBA` (i INTEGER, j TIMESTAMP TIME INDEX);

DROP TABLE `p_perftest001#cc3kvQ_D1D9H9GOZGMIY97TWH20R1LRC8U0SFBA`;

CREATE TABLE neg_default_value_min(i TIMESTAMP TIME INDEX, j SMALLINT DEFAULT -32768);

DESC TABLE neg_default_value_min;
Expand Down

0 comments on commit cd4bf23

Please sign in to comment.