From 3ab5d431557fc97cf4839d64732e91cfa5c183e5 Mon Sep 17 00:00:00 2001 From: luofucong Date: Mon, 10 Apr 2023 15:13:55 +0800 Subject: [PATCH] test: add "numbers" table in distributed mode --- src/catalog/src/remote/manager.rs | 10 -- src/catalog/tests/remote_catalog_tests.rs | 10 +- src/frontend/src/catalog.rs | 19 +++- src/frontend/src/tests/instance_test.rs | 50 ++-------- src/frontend/src/tests/test_util.rs | 10 -- tests/cases/distributed/aggregate/sum.result | 40 -------- tests/cases/distributed/aggregate/sum.sql | 15 --- tests/cases/standalone/catalog/schema.result | 97 ------------------- tests/cases/standalone/catalog/schema.sql | 35 ------- .../{ => common}/aggregate/sum.result | 0 .../standalone/{ => common}/aggregate/sum.sql | 0 .../common}/catalog/schema.result | 2 + .../common}/catalog/schema.sql | 0 13 files changed, 26 insertions(+), 262 deletions(-) delete mode 100644 tests/cases/distributed/aggregate/sum.result delete mode 100644 tests/cases/distributed/aggregate/sum.sql delete mode 100644 tests/cases/standalone/catalog/schema.result delete mode 100644 tests/cases/standalone/catalog/schema.sql rename tests/cases/standalone/{ => common}/aggregate/sum.result (100%) rename tests/cases/standalone/{ => common}/aggregate/sum.sql (100%) rename tests/cases/{distributed => standalone/common}/catalog/schema.result (98%) rename tests/cases/{distributed => standalone/common}/catalog/schema.sql (100%) diff --git a/src/catalog/src/remote/manager.rs b/src/catalog/src/remote/manager.rs index 5acb9b87b5f7..85325a7136d0 100644 --- a/src/catalog/src/remote/manager.rs +++ b/src/catalog/src/remote/manager.rs @@ -33,7 +33,6 @@ use table::engine::manager::TableEngineManagerRef; use table::engine::EngineContext; use table::metadata::TableId; use table::requests::{CreateTableRequest, OpenTableRequest}; -use table::table::numbers::NumbersTable; use table::TableRef; use tokio::sync::Mutex; @@ -423,15 +422,6 @@ impl CatalogManager for RemoteCatalogManager { })?; handle_system_table_request(self, engine, &mut system_table_requests).await?; info!("All system table opened"); - - self.catalog(DEFAULT_CATALOG_NAME) - .unwrap() - .unwrap() - .schema(DEFAULT_SCHEMA_NAME) - .unwrap() - .unwrap() - .register_table("numbers".to_string(), Arc::new(NumbersTable::default())) - .unwrap(); Ok(()) } diff --git a/src/catalog/tests/remote_catalog_tests.rs b/src/catalog/tests/remote_catalog_tests.rs index 8f6edcc37aa1..8ce777a3ec2b 100644 --- a/src/catalog/tests/remote_catalog_tests.rs +++ b/src/catalog/tests/remote_catalog_tests.rs @@ -173,7 +173,6 @@ mod tests { .schema(DEFAULT_SCHEMA_NAME) .unwrap() .unwrap(); - assert_eq!(vec!["numbers"], default_schema.table_names().unwrap()); // register a new table with an nonexistent catalog let catalog_name = DEFAULT_CATALOG_NAME.to_string(); @@ -209,14 +208,7 @@ mod tests { table, }; assert!(catalog_manager.register_table(reg_req).await.unwrap()); - assert_eq!( - HashSet::from([table_name, "numbers".to_string()]), - default_schema - .table_names() - .unwrap() - .into_iter() - .collect::>() - ); + assert_eq!(vec![table_name], default_schema.table_names().unwrap()); } #[tokio::test] diff --git a/src/frontend/src/catalog.rs b/src/frontend/src/catalog.rs index af35d1d45967..30cdd0ce405c 100644 --- a/src/frontend/src/catalog.rs +++ b/src/frontend/src/catalog.rs @@ -32,12 +32,14 @@ use catalog::{ RegisterSchemaRequest, RegisterSystemTableRequest, RegisterTableRequest, RenameTableRequest, SchemaProvider, SchemaProviderRef, }; +use common_catalog::consts::{DEFAULT_CATALOG_NAME, DEFAULT_SCHEMA_NAME}; use common_error::prelude::BoxedError; use common_telemetry::error; use futures::StreamExt; use meta_client::rpc::TableName; use partition::manager::PartitionRuleManagerRef; use snafu::prelude::*; +use table::table::numbers::NumbersTable; use table::TableRef; use crate::datanode::DatanodeClients; @@ -373,17 +375,21 @@ impl SchemaProvider for FrontendSchemaProvider { std::thread::spawn(|| { common_runtime::block_on_read(async move { + let mut tables = vec![]; + if catalog_name == DEFAULT_CATALOG_NAME && schema_name == DEFAULT_SCHEMA_NAME { + tables.push("numbers".to_string()); + } + let key = build_table_global_prefix(catalog_name, schema_name); let mut iter = backend.range(key.as_bytes()); - let mut res = HashSet::new(); while let Some(r) = iter.next().await { let Kv(k, _) = r?; let key = TableGlobalKey::parse(String::from_utf8_lossy(&k)) .context(InvalidCatalogValueSnafu)?; - res.insert(key.table_name); + tables.push(key.table_name); } - Ok(res.into_iter().collect()) + Ok(tables) }) }) .join() @@ -391,6 +397,13 @@ impl SchemaProvider for FrontendSchemaProvider { } async fn table(&self, name: &str) -> catalog::error::Result> { + if self.catalog_name == DEFAULT_CATALOG_NAME + && self.schema_name == DEFAULT_SCHEMA_NAME + && name == "numbers" + { + return Ok(Some(Arc::new(NumbersTable::default()))); + } + let table_global_key = TableGlobalKey { catalog_name: self.catalog_name.clone(), schema_name: self.schema_name.clone(), diff --git a/src/frontend/src/tests/instance_test.rs b/src/frontend/src/tests/instance_test.rs index 26e36dad0e94..9cfce9888513 100644 --- a/src/frontend/src/tests/instance_test.rs +++ b/src/frontend/src/tests/instance_test.rs @@ -324,8 +324,6 @@ async fn test_execute_query(instance: Arc) { #[apply(both_instances_cases)] async fn test_execute_show_databases_tables(instance: Arc) { - let is_distributed_mode = instance.is_distributed_mode(); - let instance = instance.frontend(); let output = execute_sql(&instance, "show databases").await; @@ -358,24 +356,14 @@ async fn test_execute_show_databases_tables(instance: Arc) { _ => unreachable!(), } - let expected = if is_distributed_mode { - "\ -+---------+ -| Tables | -+---------+ -| scripts | -+---------+\ -" - } else { - "\ + let expected = "\ +---------+ | Tables | +---------+ | numbers | | scripts | +---------+\ -" - }; +"; let output = execute_sql(&instance, "show tables").await; check_unordered_output_stream(output, expected).await; @@ -385,17 +373,7 @@ async fn test_execute_show_databases_tables(instance: Arc) { ).await; let output = execute_sql(&instance, "show tables").await; - let expected = if is_distributed_mode { - "\ -+---------+ -| Tables | -+---------+ -| demo | -| scripts | -+---------+\ -" - } else { - "\ + let expected = "\ +---------+ | Tables | +---------+ @@ -403,8 +381,7 @@ async fn test_execute_show_databases_tables(instance: Arc) { | numbers | | scripts | +---------+\ -" - }; +"; check_unordered_output_stream(output, expected).await; // show tables like [string] @@ -686,8 +663,7 @@ async fn test_insert_with_default_value(instance: Arc) { test_insert_with_default_value_for_type(instance.frontend(), "bigint").await; } -// should apply to both instance. tracked in #1294 -#[apply(standalone_instance_case)] +#[apply(both_instances_cases)] async fn test_use_database(instance: Arc) { let instance = instance.frontend(); @@ -928,8 +904,6 @@ async fn test_execute_copy_from_s3(instance: Arc) { #[apply(both_instances_cases)] async fn test_information_schema(instance: Arc) { - let is_distributed_mode = instance.is_distributed_mode(); - let instance = instance.frontend(); let sql = "create table another_table(i bigint time index)"; @@ -942,24 +916,14 @@ async fn test_information_schema(instance: Arc) { let sql = "select table_catalog, table_schema, table_name, table_type from information_schema.tables where table_type != 'SYSTEM VIEW' order by table_name"; let output = execute_sql(&instance, sql).await; - let expected = if is_distributed_mode { - "\ -+---------------+--------------------+------------+------------+ -| table_catalog | table_schema | table_name | table_type | -+---------------+--------------------+------------+------------+ -| greptime | public | scripts | BASE TABLE | -| greptime | information_schema | tables | VIEW | -+---------------+--------------------+------------+------------+" - } else { - "\ + let expected = "\ +---------------+--------------------+------------+------------+ | table_catalog | table_schema | table_name | table_type | +---------------+--------------------+------------+------------+ | greptime | public | numbers | BASE TABLE | | greptime | public | scripts | BASE TABLE | | greptime | information_schema | tables | VIEW | -+---------------+--------------------+------------+------------+" - }; ++---------------+--------------------+------------+------------+"; check_output_stream(output, expected).await; let output = execute_sql_with(&instance, sql, query_ctx).await; diff --git a/src/frontend/src/tests/test_util.rs b/src/frontend/src/tests/test_util.rs index c40e2752f241..e2854211b585 100644 --- a/src/frontend/src/tests/test_util.rs +++ b/src/frontend/src/tests/test_util.rs @@ -26,28 +26,18 @@ use crate::tests::{ pub(crate) trait MockInstance { fn frontend(&self) -> Arc; - - fn is_distributed_mode(&self) -> bool; } impl MockInstance for MockStandaloneInstance { fn frontend(&self) -> Arc { self.instance.clone() } - - fn is_distributed_mode(&self) -> bool { - false - } } impl MockInstance for MockDistributedInstance { fn frontend(&self) -> Arc { self.frontend.clone() } - - fn is_distributed_mode(&self) -> bool { - true - } } pub(crate) async fn standalone() -> Arc { diff --git a/tests/cases/distributed/aggregate/sum.result b/tests/cases/distributed/aggregate/sum.result deleted file mode 100644 index 15d3725016dd..000000000000 --- a/tests/cases/distributed/aggregate/sum.result +++ /dev/null @@ -1,40 +0,0 @@ -CREATE TABLE bigints(b BIGINT TIME INDEX); - -Affected Rows: 0 - -INSERT INTO bigints values (4611686018427387904), (4611686018427388904), (1); - -Affected Rows: 3 - -SELECT SUM(b) FROM bigints; - -+----------------------+ -| SUM(bigints.b) | -+----------------------+ -| -9223372036854774807 | -+----------------------+ - -CREATE TABLE doubles(n DOUBLE, ts BIGINT TIME INDEX); - -Affected Rows: 0 - -INSERT INTO doubles (n, ts) VALUES (9007199254740992, 1), (1, 2), (1, 3), (0, 4); - -Affected Rows: 4 - -SELECT sum(n) from doubles; - -+----------------------+ -| SUM(doubles.n) | -+----------------------+ -| 9.007199254740992e15 | -+----------------------+ - -DROP TABLE bigints; - -Affected Rows: 1 - -DROP TABLE doubles; - -Affected Rows: 1 - diff --git a/tests/cases/distributed/aggregate/sum.sql b/tests/cases/distributed/aggregate/sum.sql deleted file mode 100644 index d72905fcbe5a..000000000000 --- a/tests/cases/distributed/aggregate/sum.sql +++ /dev/null @@ -1,15 +0,0 @@ -CREATE TABLE bigints(b BIGINT TIME INDEX); - -INSERT INTO bigints values (4611686018427387904), (4611686018427388904), (1); - -SELECT SUM(b) FROM bigints; - -CREATE TABLE doubles(n DOUBLE, ts BIGINT TIME INDEX); - -INSERT INTO doubles (n, ts) VALUES (9007199254740992, 1), (1, 2), (1, 3), (0, 4); - -SELECT sum(n) from doubles; - -DROP TABLE bigints; - -DROP TABLE doubles; diff --git a/tests/cases/standalone/catalog/schema.result b/tests/cases/standalone/catalog/schema.result deleted file mode 100644 index 6972b5b235cc..000000000000 --- a/tests/cases/standalone/catalog/schema.result +++ /dev/null @@ -1,97 +0,0 @@ -CREATE SCHEMA test_public_schema; - -Affected Rows: 1 - -CREATE SCHEMA test_public_schema; - -Error: 1004(InvalidArguments), Schema test_public_schema already exists - -CREATE SCHEMA IF NOT EXISTS test_public_schema; - -Affected Rows: 1 - -SHOW DATABASES LIKE '%public%'; - -+--------------------+ -| Schemas | -+--------------------+ -| public | -| test_public_schema | -+--------------------+ - -USE test_public_schema; - -++ -++ - -CREATE TABLE hello(i BIGINT TIME INDEX); - -Affected Rows: 0 - -DROP TABLE hello; - -Affected Rows: 1 - -CREATE TABLE hello(i BIGINT TIME INDEX); - -Affected Rows: 0 - -INSERT INTO hello VALUES (2), (3), (4); - -Affected Rows: 3 - -SELECT * FROM hello; - -+---+ -| i | -+---+ -| 2 | -| 3 | -| 4 | -+---+ - -SHOW TABLES; - -+--------+ -| Tables | -+--------+ -| hello | -+--------+ - -DROP TABLE hello; - -Affected Rows: 1 - -DROP TABLE hello; - -Error: 4001(TableNotFound), Table `greptime.test_public_schema.hello` not exist - -SHOW TABLES FROM test_public_schema; - -+--------+ -| Tables | -+--------+ -+--------+ - -SHOW TABLES FROM public; - -+---------+ -| Tables | -+---------+ -| numbers | -| scripts | -+---------+ - -DROP SCHEMA test_public_schema; - -Error: 1001(Unsupported), SQL statement is not supported: DROP SCHEMA test_public_schema;, keyword: SCHEMA - -SELECT * FROM test_public_schema.hello; - -Error: 4001(TableNotFound), Table `greptime.test_public_schema.hello` not exist - -USE public; - -++ -++ - diff --git a/tests/cases/standalone/catalog/schema.sql b/tests/cases/standalone/catalog/schema.sql deleted file mode 100644 index 8fd4e292255d..000000000000 --- a/tests/cases/standalone/catalog/schema.sql +++ /dev/null @@ -1,35 +0,0 @@ -CREATE SCHEMA test_public_schema; - -CREATE SCHEMA test_public_schema; - -CREATE SCHEMA IF NOT EXISTS test_public_schema; - -SHOW DATABASES LIKE '%public%'; - -USE test_public_schema; - -CREATE TABLE hello(i BIGINT TIME INDEX); - -DROP TABLE hello; - -CREATE TABLE hello(i BIGINT TIME INDEX); - -INSERT INTO hello VALUES (2), (3), (4); - -SELECT * FROM hello; - -SHOW TABLES; - -DROP TABLE hello; - -DROP TABLE hello; - -SHOW TABLES FROM test_public_schema; - -SHOW TABLES FROM public; - -DROP SCHEMA test_public_schema; - -SELECT * FROM test_public_schema.hello; - -USE public; diff --git a/tests/cases/standalone/aggregate/sum.result b/tests/cases/standalone/common/aggregate/sum.result similarity index 100% rename from tests/cases/standalone/aggregate/sum.result rename to tests/cases/standalone/common/aggregate/sum.result diff --git a/tests/cases/standalone/aggregate/sum.sql b/tests/cases/standalone/common/aggregate/sum.sql similarity index 100% rename from tests/cases/standalone/aggregate/sum.sql rename to tests/cases/standalone/common/aggregate/sum.sql diff --git a/tests/cases/distributed/catalog/schema.result b/tests/cases/standalone/common/catalog/schema.result similarity index 98% rename from tests/cases/distributed/catalog/schema.result rename to tests/cases/standalone/common/catalog/schema.result index 8e46924d3bab..e886ca5bccc3 100644 --- a/tests/cases/distributed/catalog/schema.result +++ b/tests/cases/standalone/common/catalog/schema.result @@ -49,6 +49,7 @@ SHOW TABLES FROM public; +---------+ | Tables | +---------+ +| numbers | | scripts | +---------+ @@ -94,6 +95,7 @@ SHOW TABLES FROM public; +---------+ | Tables | +---------+ +| numbers | | scripts | +---------+ diff --git a/tests/cases/distributed/catalog/schema.sql b/tests/cases/standalone/common/catalog/schema.sql similarity index 100% rename from tests/cases/distributed/catalog/schema.sql rename to tests/cases/standalone/common/catalog/schema.sql