Skip to content

Commit

Permalink
add sys view information_schema.schemata
Browse files Browse the repository at this point in the history
  • Loading branch information
TCeason committed Apr 6, 2022
1 parent 0f20d46 commit 952c5d4
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -37,6 +38,7 @@ impl<const UPPER: bool> InformationSchemaDatabase<UPPER> {
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 {
Expand Down
2 changes: 2 additions & 0 deletions query/src/storages/information_schema/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
62 changes: 62 additions & 0 deletions query/src/storages/information_schema/schemata_table.rs
Original file line number Diff line number Diff line change
@@ -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<dyn Table> {
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)
}
}
2 changes: 2 additions & 0 deletions query/tests/it/storages/system/tables_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 952c5d4

Please sign in to comment.