Skip to content

Commit

Permalink
style: renaming name -> table_name & target -> source_name an…
Browse files Browse the repository at this point in the history
…d make `Create Table ... Like` testcase more complicated
  • Loading branch information
KKould committed Feb 28, 2024
1 parent d896e34 commit d4cdf2b
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/frontend/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,8 +472,8 @@ pub fn check_permission(
validate_param(&stmt.name, query_ctx)?;
}
Statement::CreateTableLike(stmt) => {
validate_param(&stmt.name, query_ctx)?;
validate_param(&stmt.target, query_ctx)?;
validate_param(&stmt.table_name, query_ctx)?;
validate_param(&stmt.source_name, query_ctx)?;
}
Statement::DropTable(drop_stmt) => {
validate_param(drop_stmt.table_name(), query_ctx)?;
Expand Down
2 changes: 1 addition & 1 deletion src/operator/src/expr_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ pub(crate) async fn create_external_expr(
Ok(expr)
}

/// Convert `CreateTable` statement to `CreateTableExpr` gRPC request.
/// Convert `CreateTable` statement to [`CreateTableExpr`] gRPC request.
pub fn create_to_expr(create: &CreateTable, query_ctx: QueryContextRef) -> Result<CreateTableExpr> {
let (catalog_name, schema_name, table_name) =
table_idents_to_full_name(&create.name, &query_ctx)
Expand Down
4 changes: 2 additions & 2 deletions src/operator/src/statement/ddl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl StatementExecutor {
stmt: CreateTableLike,
ctx: QueryContextRef,
) -> Result<TableRef> {
let (catalog, schema, table) = table_idents_to_full_name(&stmt.target, &ctx)
let (catalog, schema, table) = table_idents_to_full_name(&stmt.source_name, &ctx)
.map_err(BoxedError::new)
.context(error::ExternalSnafu)?;
let table_ref = self
Expand All @@ -103,7 +103,7 @@ impl StatementExecutor {
let mut create_stmt =
show_create_table::create_table_stmt(&table_ref.table_info(), quote_style)
.context(error::ParseQuerySnafu)?;
create_stmt.name = stmt.name;
create_stmt.name = stmt.table_name;
create_stmt.if_not_exists = false;

let partitions = create_partitions_stmt(partitions)?.and_then(|mut partitions| {
Expand Down
10 changes: 5 additions & 5 deletions src/sql/src/parsers/create_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,11 @@ impl<'a> ParserContext<'a> {
let table_name = self.parse_table_name()?;

if self.parser.parse_keyword(Keyword::LIKE) {
let target_table_name = self.parse_table_name()?;
let source_name = self.parse_table_name()?;

return Ok(Statement::CreateTableLike(CreateTableLike {
name: table_name,
target: target_table_name,
table_name,
source_name,
}));
}

Expand Down Expand Up @@ -900,8 +900,8 @@ mod tests {
assert_eq!(1, stmts.len());
match &stmts[0] {
Statement::CreateTableLike(c) => {
assert_eq!(c.name.to_string(), "t1");
assert_eq!(c.target.to_string(), "t2");
assert_eq!(c.table_name.to_string(), "t1");
assert_eq!(c.source_name.to_string(), "t2");
}
_ => unreachable!(),
}
Expand Down
5 changes: 3 additions & 2 deletions src/sql/src/statements/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,9 @@ pub struct CreateExternalTable {
#[derive(Debug, PartialEq, Eq, Clone, Visit, VisitMut)]
pub struct CreateTableLike {
/// Table name
pub name: ObjectName,
pub target: ObjectName,
pub table_name: ObjectName,
/// The table that is designated to be imitated by `Like`
pub source_name: ObjectName,
}

#[cfg(test)]
Expand Down
8 changes: 5 additions & 3 deletions tests/cases/standalone/common/create/create.result
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ DROP TABLE neg_default_value;

Affected Rows: 0

CREATE TABLE test_like_1 (i INTEGER, j TIMESTAMP TIME INDEX);
CREATE TABLE test_like_1 (PK STRING PRIMARY KEY, i INTEGER DEFAULT 7, j TIMESTAMP TIME INDEX);

Affected Rows: 0

Expand All @@ -160,7 +160,8 @@ DESC TABLE test_like_1;
+--------+----------------------+-----+------+---------+---------------+
| Column | Type | Key | Null | Default | Semantic Type |
+--------+----------------------+-----+------+---------+---------------+
| i | Int32 | | YES | | FIELD |
| pk | String | PRI | YES | | TAG |
| i | Int32 | | YES | 7 | FIELD |
| j | TimestampMillisecond | PRI | NO | | TIMESTAMP |
+--------+----------------------+-----+------+---------+---------------+

Expand All @@ -169,7 +170,8 @@ DESC TABLE test_like_2;
+--------+----------------------+-----+------+---------+---------------+
| Column | Type | Key | Null | Default | Semantic Type |
+--------+----------------------+-----+------+---------+---------------+
| i | Int32 | | YES | | FIELD |
| pk | String | PRI | YES | | TAG |
| i | Int32 | | YES | 7 | FIELD |
| j | TimestampMillisecond | PRI | NO | | TIMESTAMP |
+--------+----------------------+-----+------+---------+---------------+

Expand Down
2 changes: 1 addition & 1 deletion tests/cases/standalone/common/create/create.sql
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ desc TABLE neg_default_value;

DROP TABLE neg_default_value;

CREATE TABLE test_like_1 (i INTEGER, j TIMESTAMP TIME INDEX);
CREATE TABLE test_like_1 (PK STRING PRIMARY KEY, i INTEGER DEFAULT 7, j TIMESTAMP TIME INDEX);

CREATE TABLE test_like_2 LIKE test_like_1;

Expand Down

0 comments on commit d4cdf2b

Please sign in to comment.