From 952c5d4cb9af5572dd9c7ed799ff3c44b529344b Mon Sep 17 00:00:00 2001 From: taichong Date: Wed, 6 Apr 2022 16:34:26 +0800 Subject: [PATCH] add sys view information_schema.schemata --- .../information_schema_database.rs | 2 + query/src/storages/information_schema/mod.rs | 2 + .../information_schema/schemata_table.rs | 62 +++++++++++++++++++ .../tests/it/storages/system/tables_table.rs | 2 + 4 files changed, 68 insertions(+) create mode 100644 query/src/storages/information_schema/schemata_table.rs diff --git a/query/src/databases/information_schema/information_schema_database.rs b/query/src/databases/information_schema/information_schema_database.rs index 370a45b31f28..96ee003eb100 100644 --- a/query/src/databases/information_schema/information_schema_database.rs +++ b/query/src/databases/information_schema/information_schema_database.rs @@ -21,6 +21,7 @@ use crate::catalogs::InMemoryMetas; use crate::databases::Database; use crate::storages::information_schema::ColumnsTable; use crate::storages::information_schema::KeywordsTable; +use crate::storages::information_schema::SchemataTable; use crate::storages::information_schema::TablesTable; use crate::storages::information_schema::ViewsTable; use crate::storages::Table; @@ -37,6 +38,7 @@ impl InformationSchemaDatabase { TablesTable::create(sys_db_meta.next_table_id()), KeywordsTable::create(sys_db_meta.next_table_id()), ViewsTable::create(sys_db_meta.next_table_id()), + SchemataTable::create(sys_db_meta.next_table_id()), ]; let db = if UPPER { diff --git a/query/src/storages/information_schema/mod.rs b/query/src/storages/information_schema/mod.rs index a6d1ddd4b23c..869056f7ffb7 100644 --- a/query/src/storages/information_schema/mod.rs +++ b/query/src/storages/information_schema/mod.rs @@ -14,10 +14,12 @@ mod columns_table; mod keywords_table; +mod schemata_table; mod tables_table; mod views_table; pub use columns_table::ColumnsTable; pub use keywords_table::KeywordsTable; +pub use schemata_table::SchemataTable; pub use tables_table::TablesTable; pub use views_table::ViewsTable; diff --git a/query/src/storages/information_schema/schemata_table.rs b/query/src/storages/information_schema/schemata_table.rs new file mode 100644 index 000000000000..baf0b4e310bd --- /dev/null +++ b/query/src/storages/information_schema/schemata_table.rs @@ -0,0 +1,62 @@ +// Copyright 2022 Datafuse Labs. +// +// 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::collections::HashMap; +use std::sync::Arc; + +use common_meta_types::TableIdent; +use common_meta_types::TableInfo; +use common_meta_types::TableMeta; + +use crate::storages::view::view_table::QUERY; +use crate::storages::view::ViewTable; +use crate::storages::Table; + +pub struct SchemataTable {} + +impl SchemataTable { + pub fn create(table_id: u64) -> Arc { + let query = "SELECT + name AS catalog_name, + name AS schema_name, + 'default' AS schema_owner, + NULL AS default_character_set_catalog, + NULL AS default_character_set_schema, + NULL AS default_character_set_name, + NULL AS sql_path, + name AS CATALOG_NAME, + name AS SCHEMA_NAME, + 'default' AS SCHEMA_OWNER, + NULL AS DEFAULT_CHARACTER_SET_CATALOG, + NULL AS DEFAULT_CHARACTER_SET_SCHEMA, + NULL AS DEFAULT_CHARACTER_SET_NAME, + NULL AS SQL_PATH + FROM system.databases;"; + + let mut options = HashMap::new(); + options.insert(QUERY.to_string(), query.to_string()); + let table_info = TableInfo { + desc: "'information_schema'.'SCHEMATA'".to_string(), + name: "SCHEMATA".to_string(), + ident: TableIdent::new(table_id, 0), + meta: TableMeta { + options, + engine: "VIEW".to_string(), + ..Default::default() + }, + }; + + ViewTable::create(table_info) + } +} diff --git a/query/tests/it/storages/system/tables_table.rs b/query/tests/it/storages/system/tables_table.rs index bd5ba81b252f..5e7562821084 100644 --- a/query/tests/it/storages/system/tables_table.rs +++ b/query/tests/it/storages/system/tables_table.rs @@ -55,10 +55,12 @@ async fn test_tables_table() -> Result<()> { r"\| information_schema \| COLUMNS \| VIEW \| \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3} [\+-]\d{4} \|", r"\| information_schema \| KEYWORDS \| VIEW \| \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3} [\+-]\d{4} \|", r"\| information_schema \| VIEWS \| VIEW \| \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3} [\+-]\d{4} \|", + r"\| information_schema \| SCHEMATA \| VIEW \| \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3} [\+-]\d{4} \|", r"\| INFORMATION_SCHEMA \| VIEWS \| VIEW \| \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3} [\+-]\d{4} \|", r"\| INFORMATION_SCHEMA \| KEYWORDS \| VIEW \| \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3} [\+-]\d{4} \|", r"\| INFORMATION_SCHEMA \| COLUMNS \| VIEW \| \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3} [\+-]\d{4} \|", r"\| INFORMATION_SCHEMA \| TABLES \| VIEW \| \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3} [\+-]\d{4} \|", + r"\| INFORMATION_SCHEMA \| SCHEMATA \| VIEW \| \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3} [\+-]\d{4} \|", r"\+--------------------\+--------------\+--------------------\+-------------------------------\+", ]; common_datablocks::assert_blocks_sorted_eq_with_regex(expected, result.as_slice());