From 4550b6a47ed009912920e36c7b3dfa5f9261f59e Mon Sep 17 00:00:00 2001 From: jeremyhi Date: Sun, 24 Mar 2024 17:47:11 +0800 Subject: [PATCH] feat: add unit test for alter logical tables --- .../meta/src/ddl/drop_table/executor.rs | 6 +- src/common/meta/src/ddl/test_util.rs | 6 +- .../meta/src/ddl/test_util/alter_table.rs | 62 +++ src/common/meta/src/ddl/test_util/columns.rs | 50 +++ .../meta/src/ddl/test_util/create_table.rs | 36 +- src/common/meta/src/ddl/tests.rs | 1 + .../src/ddl/tests/alter_logical_tables.rs | 412 ++++++++++++++++++ .../src/ddl/tests/create_logical_tables.rs | 12 +- src/common/meta/src/ddl/tests/create_table.rs | 6 +- src/common/meta/src/rpc/ddl.rs | 15 +- src/meta-srv/src/procedure/tests.rs | 6 +- 11 files changed, 554 insertions(+), 58 deletions(-) create mode 100644 src/common/meta/src/ddl/test_util/alter_table.rs create mode 100644 src/common/meta/src/ddl/test_util/columns.rs create mode 100644 src/common/meta/src/ddl/tests/alter_logical_tables.rs diff --git a/src/common/meta/src/ddl/drop_table/executor.rs b/src/common/meta/src/ddl/drop_table/executor.rs index e7e1992b337b..d869af7c90d2 100644 --- a/src/common/meta/src/ddl/drop_table/executor.rs +++ b/src/common/meta/src/ddl/drop_table/executor.rs @@ -198,8 +198,10 @@ mod tests { use table::metadata::RawTableInfo; use super::*; - use crate::ddl::test_util::create_table::build_raw_table_info_from_expr; - use crate::ddl::test_util::{TestColumnDefBuilder, TestCreateTableExprBuilder}; + use crate::ddl::test_util::columns::TestColumnDefBuilder; + use crate::ddl::test_util::create_table::{ + build_raw_table_info_from_expr, TestCreateTableExprBuilder, + }; use crate::table_name::TableName; use crate::test_util::{new_ddl_context, MockDatanodeManager}; diff --git a/src/common/meta/src/ddl/test_util.rs b/src/common/meta/src/ddl/test_util.rs index 239a655fb2cb..0245d4fc905a 100644 --- a/src/common/meta/src/ddl/test_util.rs +++ b/src/common/meta/src/ddl/test_util.rs @@ -12,8 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. +pub mod alter_table; +pub mod columns; pub mod create_table; - -pub use create_table::{ - TestColumnDef, TestColumnDefBuilder, TestCreateTableExpr, TestCreateTableExprBuilder, -}; diff --git a/src/common/meta/src/ddl/test_util/alter_table.rs b/src/common/meta/src/ddl/test_util/alter_table.rs new file mode 100644 index 000000000000..13da97e3d82e --- /dev/null +++ b/src/common/meta/src/ddl/test_util/alter_table.rs @@ -0,0 +1,62 @@ +// Copyright 2023 Greptime Team +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use api::v1::alter_expr::Kind; +use api::v1::{AddColumn, AddColumns, AlterExpr, ColumnDef, RenameTable}; +use common_catalog::consts::{DEFAULT_CATALOG_NAME, DEFAULT_SCHEMA_NAME}; +use derive_builder::Builder; + +#[derive(Default, Builder)] +#[builder(default)] +pub struct TestAlterTableExpr { + #[builder(setter(into), default = "DEFAULT_CATALOG_NAME.to_string()")] + catalog_name: String, + #[builder(setter(into), default = "DEFAULT_SCHEMA_NAME.to_string()")] + schema_name: String, + #[builder(setter(into))] + table_name: String, + #[builder(setter(into))] + add_columns: Vec, + #[builder(setter(into))] + new_table_name: Option, +} + +impl From for AlterExpr { + fn from(value: TestAlterTableExpr) -> Self { + if let Some(new_table_name) = value.new_table_name { + Self { + catalog_name: value.catalog_name, + schema_name: value.schema_name, + table_name: value.table_name, + kind: Some(Kind::RenameTable(RenameTable { new_table_name })), + } + } else { + Self { + catalog_name: value.catalog_name, + schema_name: value.schema_name, + table_name: value.table_name, + kind: Some(Kind::AddColumns(AddColumns { + add_columns: value + .add_columns + .into_iter() + .map(|col| AddColumn { + column_def: Some(col), + location: None, + }) + .collect(), + })), + } + } + } +} diff --git a/src/common/meta/src/ddl/test_util/columns.rs b/src/common/meta/src/ddl/test_util/columns.rs new file mode 100644 index 000000000000..9e258939b021 --- /dev/null +++ b/src/common/meta/src/ddl/test_util/columns.rs @@ -0,0 +1,50 @@ +// Copyright 2023 Greptime Team +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use api::v1::{ColumnDataType, ColumnDef, SemanticType}; +use derive_builder::Builder; + +#[derive(Default, Builder)] +pub struct TestColumnDef { + #[builder(setter(into), default)] + name: String, + data_type: ColumnDataType, + #[builder(default)] + is_nullable: bool, + semantic_type: SemanticType, + #[builder(setter(into), default)] + comment: String, +} + +impl From for ColumnDef { + fn from( + TestColumnDef { + name, + data_type, + is_nullable, + semantic_type, + comment, + }: TestColumnDef, + ) -> Self { + Self { + name, + data_type: data_type as i32, + is_nullable, + default_constraint: vec![], + semantic_type: semantic_type as i32, + comment, + datatype_extension: None, + } + } +} diff --git a/src/common/meta/src/ddl/test_util/create_table.rs b/src/common/meta/src/ddl/test_util/create_table.rs index 12b13d74f93c..eb80d8c16007 100644 --- a/src/common/meta/src/ddl/test_util/create_table.rs +++ b/src/common/meta/src/ddl/test_util/create_table.rs @@ -15,7 +15,7 @@ use std::collections::HashMap; use api::v1::column_def::try_as_column_schema; -use api::v1::{ColumnDataType, ColumnDef, CreateTableExpr, SemanticType}; +use api::v1::{ColumnDef, CreateTableExpr, SemanticType}; use chrono::DateTime; use common_catalog::consts::{DEFAULT_CATALOG_NAME, DEFAULT_SCHEMA_NAME, MITO2_ENGINE}; use datatypes::schema::RawSchema; @@ -24,40 +24,6 @@ use store_api::storage::TableId; use table::metadata::{RawTableInfo, RawTableMeta, TableIdent, TableType}; use table::requests::TableOptions; -#[derive(Default, Builder)] -pub struct TestColumnDef { - #[builder(setter(into), default)] - name: String, - data_type: ColumnDataType, - #[builder(default)] - is_nullable: bool, - semantic_type: SemanticType, - #[builder(setter(into), default)] - comment: String, -} - -impl From for ColumnDef { - fn from( - TestColumnDef { - name, - data_type, - is_nullable, - semantic_type, - comment, - }: TestColumnDef, - ) -> Self { - Self { - name, - data_type: data_type as i32, - is_nullable, - default_constraint: vec![], - semantic_type: semantic_type as i32, - comment, - datatype_extension: None, - } - } -} - #[derive(Default, Builder)] #[builder(default)] pub struct TestCreateTableExpr { diff --git a/src/common/meta/src/ddl/tests.rs b/src/common/meta/src/ddl/tests.rs index 5ea7d6a85803..fcbe52189a84 100644 --- a/src/common/meta/src/ddl/tests.rs +++ b/src/common/meta/src/ddl/tests.rs @@ -12,5 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. +mod alter_logical_tables; mod create_logical_tables; mod create_table; diff --git a/src/common/meta/src/ddl/tests/alter_logical_tables.rs b/src/common/meta/src/ddl/tests/alter_logical_tables.rs new file mode 100644 index 000000000000..9be0f4c584de --- /dev/null +++ b/src/common/meta/src/ddl/tests/alter_logical_tables.rs @@ -0,0 +1,412 @@ +// Copyright 2023 Greptime Team +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use std::assert_matches::assert_matches; +use std::sync::Arc; + +use api::v1::{ColumnDataType, SemanticType}; +use common_catalog::consts::{DEFAULT_CATALOG_NAME, DEFAULT_SCHEMA_NAME}; +use common_procedure::{Procedure, ProcedureId, Status}; +use common_procedure_test::MockContextProvider; +use table::metadata::TableId; + +use crate::ddl::alter_logical_tables::AlterLogicalTablesProcedure; +use crate::ddl::create_logical_tables::CreateLogicalTablesProcedure; +use crate::ddl::test_util::alter_table::TestAlterTableExprBuilder; +use crate::ddl::test_util::columns::TestColumnDefBuilder; +use crate::ddl::tests::create_logical_tables; +use crate::ddl::tests::create_logical_tables::{ + test_create_physical_table_task, NaiveDatanodeHandler, +}; +use crate::ddl::{DdlContext, TableMetadata, TableMetadataAllocatorContext}; +use crate::error::Error::{AlterLogicalTablesInvalidArguments, TableNotFound}; +use crate::key::table_name::TableNameKey; +use crate::rpc::ddl::AlterTableTask; +use crate::test_util::{new_ddl_context, MockDatanodeManager}; +use crate::ClusterId; + +fn make_alter_logical_table_add_column_task( + schema: Option<&str>, + table: &str, + add_columns: Vec, +) -> AlterTableTask { + let add_columns = add_columns + .into_iter() + .map(|name| { + TestColumnDefBuilder::default() + .name(name) + .data_type(ColumnDataType::String) + .is_nullable(true) + .semantic_type(SemanticType::Tag) + .comment("new column".to_string()) + .build() + .unwrap() + .into() + }) + .collect::>(); + let mut alter_table = TestAlterTableExprBuilder::default(); + if let Some(schema) = schema { + alter_table.schema_name(schema.to_string()); + } + let alter_table = alter_table + .table_name(table.to_string()) + .add_columns(add_columns) + .build() + .unwrap(); + + AlterTableTask { + alter_table: alter_table.into(), + } +} + +fn make_alter_logical_table_rename_task( + schema: &str, + table: &str, + new_table_name: &str, +) -> AlterTableTask { + let alter_table = TestAlterTableExprBuilder::default() + .schema_name(schema.to_string()) + .table_name(table.to_string()) + .new_table_name(new_table_name.to_string()) + .build() + .unwrap(); + + AlterTableTask { + alter_table: alter_table.into(), + } +} + +#[tokio::test] +async fn test_on_prepare_check_schema() { + let datanode_manager = Arc::new(MockDatanodeManager::new(())); + let ddl_context = new_ddl_context(datanode_manager); + let cluster_id = 1; + let tasks = vec![ + make_alter_logical_table_add_column_task( + Some("schema1"), + "table1", + vec!["column1".to_string()], + ), + make_alter_logical_table_add_column_task( + Some("schema2"), + "table2", + vec!["column2".to_string()], + ), + ]; + let physical_table_id = 1024u32; + let mut procedure = + AlterLogicalTablesProcedure::new(cluster_id, tasks, physical_table_id, ddl_context); + let err = procedure.on_prepare().await.unwrap_err(); + assert_matches!(err, AlterLogicalTablesInvalidArguments { .. }); +} + +#[tokio::test] +async fn test_on_prepare_check_alter_kind() { + let datanode_manager = Arc::new(MockDatanodeManager::new(())); + let ddl_context = new_ddl_context(datanode_manager); + let cluster_id = 1; + let tasks = vec![make_alter_logical_table_rename_task( + "schema1", + "table1", + "new_table1", + )]; + let physical_table_id = 1024u32; + let mut procedure = + AlterLogicalTablesProcedure::new(cluster_id, tasks, physical_table_id, ddl_context); + let err = procedure.on_prepare().await.unwrap_err(); + assert_matches!(err, AlterLogicalTablesInvalidArguments { .. }); +} + +async fn create_physical_table( + ddl_context: DdlContext, + cluster_id: ClusterId, + name: &str, +) -> TableId { + // Prepares physical table metadata. + let mut create_physical_table_task = test_create_physical_table_task(name); + let TableMetadata { + table_id, + table_route, + .. + } = ddl_context + .table_metadata_allocator + .create( + &TableMetadataAllocatorContext { cluster_id }, + &create_physical_table_task, + ) + .await + .unwrap(); + create_physical_table_task.set_table_id(table_id); + create_logical_tables::create_physical_table_metadata( + &ddl_context, + create_physical_table_task.table_info.clone(), + table_route, + ) + .await; + + table_id +} + +async fn create_logical_table( + ddl_context: DdlContext, + cluster_id: ClusterId, + physical_table_id: TableId, + table_name: &str, +) { + let tasks = vec![create_logical_tables::test_create_logical_table_task( + table_name, + )]; + let mut procedure = + CreateLogicalTablesProcedure::new(cluster_id, tasks, physical_table_id, ddl_context); + let status = procedure.on_prepare().await.unwrap(); + assert_matches!(status, Status::Executing { persist: true }); + let status = procedure.on_create_metadata().await.unwrap(); + assert_matches!(status, Status::Done { .. }); +} + +#[tokio::test] +async fn test_on_prepare_different_physical_table() { + let cluster_id = 1; + let datanode_manager = Arc::new(MockDatanodeManager::new(())); + let ddl_context = new_ddl_context(datanode_manager); + + let phy1_id = create_physical_table(ddl_context.clone(), cluster_id, "phy1").await; + create_logical_table(ddl_context.clone(), cluster_id, phy1_id, "table1").await; + let phy2_id = create_physical_table(ddl_context.clone(), cluster_id, "phy2").await; + create_logical_table(ddl_context.clone(), cluster_id, phy2_id, "table2").await; + + let tasks = vec![ + make_alter_logical_table_add_column_task(None, "table1", vec!["column1".to_string()]), + make_alter_logical_table_add_column_task(None, "table2", vec!["column2".to_string()]), + ]; + + let mut procedure = AlterLogicalTablesProcedure::new(cluster_id, tasks, phy1_id, ddl_context); + let err = procedure.on_prepare().await.unwrap_err(); + assert_matches!(err, AlterLogicalTablesInvalidArguments { .. }); +} + +#[tokio::test] +async fn test_on_prepare_logical_table_not_exists() { + let cluster_id = 1; + let datanode_manager = Arc::new(MockDatanodeManager::new(())); + let ddl_context = new_ddl_context(datanode_manager); + + // Creates physical table + let phy_id = create_physical_table(ddl_context.clone(), cluster_id, "phy").await; + // Creates 3 logical tables + create_logical_table(ddl_context.clone(), cluster_id, phy_id, "table1").await; + + let tasks = vec![ + make_alter_logical_table_add_column_task(None, "table1", vec!["column1".to_string()]), + // table2 not exists + make_alter_logical_table_add_column_task(None, "table2", vec!["column2".to_string()]), + ]; + + let mut procedure = AlterLogicalTablesProcedure::new(cluster_id, tasks, phy_id, ddl_context); + let err = procedure.on_prepare().await.unwrap_err(); + assert_matches!(err, TableNotFound { .. }); +} + +#[tokio::test] +async fn test_on_prepare() { + let cluster_id = 1; + let datanode_manager = Arc::new(MockDatanodeManager::new(())); + let ddl_context = new_ddl_context(datanode_manager); + + // Creates physical table + let phy_id = create_physical_table(ddl_context.clone(), cluster_id, "phy").await; + // Creates 3 logical tables + create_logical_table(ddl_context.clone(), cluster_id, phy_id, "table1").await; + create_logical_table(ddl_context.clone(), cluster_id, phy_id, "table2").await; + create_logical_table(ddl_context.clone(), cluster_id, phy_id, "table3").await; + + let tasks = vec![ + make_alter_logical_table_add_column_task(None, "table1", vec!["column1".to_string()]), + make_alter_logical_table_add_column_task(None, "table2", vec!["column2".to_string()]), + make_alter_logical_table_add_column_task(None, "table3", vec!["column3".to_string()]), + ]; + + let mut procedure = AlterLogicalTablesProcedure::new(cluster_id, tasks, phy_id, ddl_context); + let result = procedure.on_prepare().await; + assert_matches!(result, Ok(Status::Executing { persist: true })); +} + +#[tokio::test] +async fn test_on_update_metadata() { + let cluster_id = 1; + let datanode_manager = Arc::new(MockDatanodeManager::new(NaiveDatanodeHandler)); + let ddl_context = new_ddl_context(datanode_manager); + + // Creates physical table + let phy_id = create_physical_table(ddl_context.clone(), cluster_id, "phy").await; + // Creates 3 logical tables + create_logical_table(ddl_context.clone(), cluster_id, phy_id, "table1").await; + create_logical_table(ddl_context.clone(), cluster_id, phy_id, "table2").await; + create_logical_table(ddl_context.clone(), cluster_id, phy_id, "table3").await; + create_logical_table(ddl_context.clone(), cluster_id, phy_id, "table4").await; + create_logical_table(ddl_context.clone(), cluster_id, phy_id, "table5").await; + + let tasks = vec![ + make_alter_logical_table_add_column_task(None, "table1", vec!["new_col".to_string()]), + make_alter_logical_table_add_column_task(None, "table2", vec!["mew_col".to_string()]), + make_alter_logical_table_add_column_task(None, "table3", vec!["new_col".to_string()]), + ]; + + let mut procedure = AlterLogicalTablesProcedure::new(cluster_id, tasks, phy_id, ddl_context); + let mut status = procedure.on_prepare().await.unwrap(); + assert_matches!(status, Status::Executing { persist: true }); + + let ctx = common_procedure::Context { + procedure_id: ProcedureId::random(), + provider: Arc::new(MockContextProvider::default()), + }; + // on_submit_alter_region_requests + status = procedure.execute(&ctx).await.unwrap(); + assert_matches!(status, Status::Executing { persist: true }); + // on_update_metadata + status = procedure.execute(&ctx).await.unwrap(); + assert_matches!(status, Status::Executing { persist: true }); +} + +#[tokio::test] +async fn test_on_part_duplicate_alter_request() { + let cluster_id = 1; + let datanode_manager = Arc::new(MockDatanodeManager::new(NaiveDatanodeHandler)); + let ddl_context = new_ddl_context(datanode_manager); + + // Creates physical table + let phy_id = create_physical_table(ddl_context.clone(), cluster_id, "phy").await; + // Creates 3 logical tables + create_logical_table(ddl_context.clone(), cluster_id, phy_id, "table1").await; + create_logical_table(ddl_context.clone(), cluster_id, phy_id, "table2").await; + + let tasks = vec![ + make_alter_logical_table_add_column_task(None, "table1", vec!["col_0".to_string()]), + make_alter_logical_table_add_column_task(None, "table2", vec!["col_0".to_string()]), + ]; + + let mut procedure = + AlterLogicalTablesProcedure::new(cluster_id, tasks, phy_id, ddl_context.clone()); + let mut status = procedure.on_prepare().await.unwrap(); + assert_matches!(status, Status::Executing { persist: true }); + + let ctx = common_procedure::Context { + procedure_id: ProcedureId::random(), + provider: Arc::new(MockContextProvider::default()), + }; + // on_submit_alter_region_requests + status = procedure.execute(&ctx).await.unwrap(); + assert_matches!(status, Status::Executing { persist: true }); + // on_update_metadata + status = procedure.execute(&ctx).await.unwrap(); + assert_matches!(status, Status::Executing { persist: true }); + + // re-alter + let tasks = vec![ + make_alter_logical_table_add_column_task( + None, + "table1", + vec!["col_0".to_string(), "new_col_1".to_string()], + ), + make_alter_logical_table_add_column_task( + None, + "table2", + vec![ + "col_0".to_string(), + "new_col_2".to_string(), + "new_col_1".to_string(), + ], + ), + ]; + + let mut procedure = + AlterLogicalTablesProcedure::new(cluster_id, tasks, phy_id, ddl_context.clone()); + let mut status = procedure.on_prepare().await.unwrap(); + assert_matches!(status, Status::Executing { persist: true }); + + let ctx = common_procedure::Context { + procedure_id: ProcedureId::random(), + provider: Arc::new(MockContextProvider::default()), + }; + // on_submit_alter_region_requests + status = procedure.execute(&ctx).await.unwrap(); + assert_matches!(status, Status::Executing { persist: true }); + // on_update_metadata + status = procedure.execute(&ctx).await.unwrap(); + assert_matches!(status, Status::Executing { persist: true }); + + let table_name_keys = vec![ + TableNameKey::new(DEFAULT_CATALOG_NAME, DEFAULT_SCHEMA_NAME, "table1"), + TableNameKey::new(DEFAULT_CATALOG_NAME, DEFAULT_SCHEMA_NAME, "table2"), + ]; + let table_ids = ddl_context + .table_metadata_manager + .table_name_manager() + .batch_get(table_name_keys) + .await + .unwrap() + .into_iter() + .map(|x| x.unwrap().table_id()) + .collect::>(); + let tables = ddl_context + .table_metadata_manager + .table_info_manager() + .batch_get(&table_ids) + .await + .unwrap(); + + let table1 = tables.get(&table_ids[0]).unwrap(); + let table2 = tables.get(&table_ids[1]).unwrap(); + assert_eq!(table1.table_info.name, "table1"); + assert_eq!(table2.table_info.name, "table2"); + + let table1_cols = table1 + .table_info + .meta + .schema + .column_schemas + .iter() + .map(|x| x.name.clone()) + .collect::>(); + assert_eq!( + table1_cols, + vec![ + "col_0".to_string(), + "cpu".to_string(), + "host".to_string(), + "new_col_1".to_string(), + "ts".to_string() + ] + ); + + let table2_cols = table2 + .table_info + .meta + .schema + .column_schemas + .iter() + .map(|x| x.name.clone()) + .collect::>(); + assert_eq!( + table2_cols, + vec![ + "col_0".to_string(), + "cpu".to_string(), + "host".to_string(), + "new_col_1".to_string(), + "new_col_2".to_string(), + "ts".to_string() + ] + ); +} diff --git a/src/common/meta/src/ddl/tests/create_logical_tables.rs b/src/common/meta/src/ddl/tests/create_logical_tables.rs index 7f82d372ca05..7223c2e43458 100644 --- a/src/common/meta/src/ddl/tests/create_logical_tables.rs +++ b/src/common/meta/src/ddl/tests/create_logical_tables.rs @@ -30,8 +30,10 @@ use table::metadata::RawTableInfo; use crate::datanode_manager::HandleResponse; use crate::ddl::create_logical_tables::CreateLogicalTablesProcedure; -use crate::ddl::test_util::create_table::build_raw_table_info_from_expr; -use crate::ddl::test_util::{TestColumnDefBuilder, TestCreateTableExprBuilder}; +use crate::ddl::test_util::columns::TestColumnDefBuilder; +use crate::ddl::test_util::create_table::{ + build_raw_table_info_from_expr, TestCreateTableExprBuilder, +}; use crate::ddl::{DdlContext, TableMetadata, TableMetadataAllocatorContext}; use crate::error::{Error, Result}; use crate::key::table_route::TableRouteValue; @@ -41,7 +43,7 @@ use crate::test_util::{new_ddl_context, MockDatanodeHandler, MockDatanodeManager // Note: this code may be duplicated with others. // However, it's by design, ensures the tests are easy to be modified or added. -fn test_create_logical_table_task(name: &str) -> CreateTableTask { +pub(crate) fn test_create_logical_table_task(name: &str) -> CreateTableTask { let create_table = TestCreateTableExprBuilder::default() .column_defs([ TestColumnDefBuilder::default() @@ -86,7 +88,7 @@ fn test_create_logical_table_task(name: &str) -> CreateTableTask { // Note: this code may be duplicated with others. // However, it's by design, ensures the tests are easy to be modified or added. -fn test_create_physical_table_task(name: &str) -> CreateTableTask { +pub(crate) fn test_create_physical_table_task(name: &str) -> CreateTableTask { let create_table = TestCreateTableExprBuilder::default() .column_defs([ TestColumnDefBuilder::default() @@ -135,7 +137,7 @@ async fn test_on_prepare_physical_table_not_found() { assert_matches!(err, Error::TableRouteNotFound { .. }); } -async fn create_physical_table_metadata( +pub(crate) async fn create_physical_table_metadata( ddl_context: &DdlContext, table_info: RawTableInfo, table_route: TableRouteValue, diff --git a/src/common/meta/src/ddl/tests/create_table.rs b/src/common/meta/src/ddl/tests/create_table.rs index 3040ae6d2f25..2ba289488dea 100644 --- a/src/common/meta/src/ddl/tests/create_table.rs +++ b/src/common/meta/src/ddl/tests/create_table.rs @@ -28,8 +28,10 @@ use common_telemetry::debug; use crate::datanode_manager::HandleResponse; use crate::ddl::create_table::CreateTableProcedure; -use crate::ddl::test_util::create_table::build_raw_table_info_from_expr; -use crate::ddl::test_util::{TestColumnDefBuilder, TestCreateTableExprBuilder}; +use crate::ddl::test_util::columns::TestColumnDefBuilder; +use crate::ddl::test_util::create_table::{ + build_raw_table_info_from_expr, TestCreateTableExprBuilder, +}; use crate::error; use crate::error::{Error, Result}; use crate::key::table_route::TableRouteValue; diff --git a/src/common/meta/src/rpc/ddl.rs b/src/common/meta/src/rpc/ddl.rs index ce7cfefaf57a..f6e5aab9a8f9 100644 --- a/src/common/meta/src/rpc/ddl.rs +++ b/src/common/meta/src/rpc/ddl.rs @@ -14,13 +14,7 @@ use std::result; -use base64::Engine as _; -use base64::engine::general_purpose; -use prost::Message; -use serde::{Deserialize, Serialize}; -use snafu::{OptionExt, ResultExt}; - -use api::v1::{AlterExpr, CreateTableExpr, DropTableExpr, TruncateTableExpr}; +use api::v1::meta::ddl_task_request::Task; use api::v1::meta::{ AlterTableTask as PbAlterTableTask, AlterTableTasks as PbAlterTableTasks, CreateTableTask as PbCreateTableTask, CreateTableTasks as PbCreateTableTasks, @@ -28,7 +22,12 @@ use api::v1::meta::{ DropTableTask as PbDropTableTask, DropTableTasks as PbDropTableTasks, Partition, ProcedureId, TruncateTableTask as PbTruncateTableTask, }; -use api::v1::meta::ddl_task_request::Task; +use api::v1::{AlterExpr, CreateTableExpr, DropTableExpr, TruncateTableExpr}; +use base64::engine::general_purpose; +use base64::Engine as _; +use prost::Message; +use serde::{Deserialize, Serialize}; +use snafu::{OptionExt, ResultExt}; use table::metadata::{RawTableInfo, TableId}; use table::table_reference::TableReference; diff --git a/src/meta-srv/src/procedure/tests.rs b/src/meta-srv/src/procedure/tests.rs index cba896f1df58..f3fb701af95e 100644 --- a/src/meta-srv/src/procedure/tests.rs +++ b/src/meta-srv/src/procedure/tests.rs @@ -32,8 +32,10 @@ use common_meta::ddl::create_logical_tables::{CreateLogicalTablesProcedure, Crea use common_meta::ddl::create_table::*; use common_meta::ddl::drop_table::executor::DropTableExecutor; use common_meta::ddl::drop_table::DropTableProcedure; -use common_meta::ddl::test_util::create_table::build_raw_table_info_from_expr; -use common_meta::ddl::test_util::{TestColumnDefBuilder, TestCreateTableExprBuilder}; +use common_meta::ddl::test_util::columns::TestColumnDefBuilder; +use common_meta::ddl::test_util::create_table::{ + build_raw_table_info_from_expr, TestCreateTableExprBuilder, +}; use common_meta::key::table_info::TableInfoValue; use common_meta::key::table_route::TableRouteValue; use common_meta::key::DeserializedValueWithBytes;