From af13eeaad321277de95c6bf362a3b2ae7e4d8ac7 Mon Sep 17 00:00:00 2001 From: dennis zhuang Date: Thu, 28 Dec 2023 12:01:42 +0800 Subject: [PATCH] feat: adds character_sets, collations and events etc. (#3017) feat: adds character_sets, collations and events etc. to information_schema --- src/catalog/src/information_schema.rs | 14 +- .../information_schema/memory_table/tables.rs | 104 +++++++++- .../src/information_schema/table_names.rs | 5 + src/common/catalog/src/consts.rs | 10 + .../common/show/show_databases_tables.result | 25 ++- .../common/system/information_schema.result | 187 +++++++++++++----- .../common/system/information_schema.sql | 10 + 7 files changed, 293 insertions(+), 62 deletions(-) diff --git a/src/catalog/src/information_schema.rs b/src/catalog/src/information_schema.rs index 0ed20844bf30..5bbfb1c6d88f 100644 --- a/src/catalog/src/information_schema.rs +++ b/src/catalog/src/information_schema.rs @@ -51,6 +51,11 @@ lazy_static! { COLUMN_PRIVILEGES, COLUMN_STATISTICS, BUILD_INFO, + CHARACTER_SETS, + COLLATIONS, + COLLATION_CHARACTER_SET_APPLICABILITY, + CHECK_CONSTRAINTS, + EVENTS, ]; } @@ -125,7 +130,7 @@ impl InformationSchemaProvider { // Add memory tables for name in MEMORY_TABLES.iter() { - tables.insert((*name).to_string(), self.build_table(name).unwrap()); + tables.insert((*name).to_string(), self.build_table(name).expect(name)); } self.tables = tables; @@ -156,6 +161,13 @@ impl InformationSchemaProvider { COLUMN_PRIVILEGES => setup_memory_table!(COLUMN_PRIVILEGES), COLUMN_STATISTICS => setup_memory_table!(COLUMN_STATISTICS), BUILD_INFO => setup_memory_table!(BUILD_INFO), + CHARACTER_SETS => setup_memory_table!(CHARACTER_SETS), + COLLATIONS => setup_memory_table!(COLLATIONS), + COLLATION_CHARACTER_SET_APPLICABILITY => { + setup_memory_table!(COLLATION_CHARACTER_SET_APPLICABILITY) + } + CHECK_CONSTRAINTS => setup_memory_table!(CHECK_CONSTRAINTS), + EVENTS => setup_memory_table!(EVENTS), _ => None, } } diff --git a/src/catalog/src/information_schema/memory_table/tables.rs b/src/catalog/src/information_schema/memory_table/tables.rs index e19b8d08d1ef..abb719ca1b4b 100644 --- a/src/catalog/src/information_schema/memory_table/tables.rs +++ b/src/catalog/src/information_schema/memory_table/tables.rs @@ -17,7 +17,7 @@ use std::sync::Arc; use common_catalog::consts::MITO_ENGINE; use datatypes::prelude::{ConcreteDataType, VectorRef}; use datatypes::schema::{ColumnSchema, Schema, SchemaRef}; -use datatypes::vectors::StringVector; +use datatypes::vectors::{Int64Vector, StringVector}; use crate::information_schema::table_names::*; @@ -97,6 +97,92 @@ pub fn get_schema_columns(table_name: &str) -> (SchemaRef, Vec) { ], ), + CHARACTER_SETS => ( + vec![ + string_column("CHARACTER_SET_NAME"), + string_column("DEFAULT_COLLATE_NAME"), + string_column("DESCRIPTION"), + bigint_column("MAXLEN"), + ], + vec![ + Arc::new(StringVector::from(vec!["utf8"])), + Arc::new(StringVector::from(vec!["utf8_bin"])), + Arc::new(StringVector::from(vec!["UTF-8 Unicode"])), + Arc::new(Int64Vector::from_slice([4])), + ], + ), + + COLLATIONS => ( + vec![ + string_column("COLLATION_NAME"), + string_column("CHARACTER_SET_NAME"), + bigint_column("ID"), + string_column("IS_DEFAULT"), + string_column("IS_COMPILED"), + bigint_column("SORTLEN"), + ], + vec![ + Arc::new(StringVector::from(vec!["utf8_bin"])), + Arc::new(StringVector::from(vec!["utf8"])), + Arc::new(Int64Vector::from_slice([1])), + Arc::new(StringVector::from(vec!["Yes"])), + Arc::new(StringVector::from(vec!["Yes"])), + Arc::new(Int64Vector::from_slice([1])), + ], + ), + + COLLATION_CHARACTER_SET_APPLICABILITY => ( + vec![ + string_column("COLLATION_NAME"), + string_column("CHARACTER_SET_NAME"), + ], + vec![ + Arc::new(StringVector::from(vec!["utf8_bin"])), + Arc::new(StringVector::from(vec!["utf8"])), + ], + ), + + CHECK_CONSTRAINTS => ( + string_columns(&[ + "CONSTRAINT_CATALOG", + "CONSTRAINT_SCHEMA", + "CONSTRAINT_NAME", + "CHECK_CLAUSE", + ]), + // Not support check constraints yet + vec![], + ), + + EVENTS => ( + vec![ + string_column("EVENT_CATALOG"), + string_column("EVENT_SCHEMA"), + string_column("EVENT_NAME"), + string_column("DEFINER"), + string_column("TIME_ZONE"), + string_column("EVENT_BODY"), + string_column("EVENT_DEFINITION"), + string_column("EVENT_TYPE"), + datetime_column("EXECUTE_AT"), + bigint_column("INTERVAL_VALUE"), + string_column("INTERVAL_FIELD"), + string_column("SQL_MODE"), + datetime_column("STARTS"), + datetime_column("ENDS"), + string_column("STATUS"), + string_column("ON_COMPLETION"), + datetime_column("CREATED"), + datetime_column("LAST_ALTERED"), + datetime_column("LAST_EXECUTED"), + string_column("EVENT_COMMENT"), + bigint_column("ORIGINATOR"), + string_column("CHARACTER_SET_CLIENT"), + string_column("COLLATION_CONNECTION"), + string_column("DATABASE_COLLATION"), + ], + vec![], + ), + _ => unreachable!("Unknown table in information_schema: {}", table_name), }; @@ -115,6 +201,22 @@ fn string_column(name: &str) -> ColumnSchema { ) } +fn bigint_column(name: &str) -> ColumnSchema { + ColumnSchema::new( + str::to_lowercase(name), + ConcreteDataType::int64_datatype(), + false, + ) +} + +fn datetime_column(name: &str) -> ColumnSchema { + ColumnSchema::new( + str::to_lowercase(name), + ConcreteDataType::datetime_datatype(), + false, + ) +} + #[cfg(test)] mod tests { use super::*; diff --git a/src/catalog/src/information_schema/table_names.rs b/src/catalog/src/information_schema/table_names.rs index 1bd0df8a90ce..996a2e035f48 100644 --- a/src/catalog/src/information_schema/table_names.rs +++ b/src/catalog/src/information_schema/table_names.rs @@ -20,3 +20,8 @@ pub const ENGINES: &str = "engines"; pub const COLUMN_PRIVILEGES: &str = "column_privileges"; pub const COLUMN_STATISTICS: &str = "column_statistics"; pub const BUILD_INFO: &str = "build_info"; +pub const CHARACTER_SETS: &str = "character_sets"; +pub const COLLATIONS: &str = "collations"; +pub const COLLATION_CHARACTER_SET_APPLICABILITY: &str = "collation_character_set_applicability"; +pub const CHECK_CONSTRAINTS: &str = "check_constraints"; +pub const EVENTS: &str = "events"; diff --git a/src/common/catalog/src/consts.rs b/src/common/catalog/src/consts.rs index a02b0f87bf3a..d9cb1ba54b50 100644 --- a/src/common/catalog/src/consts.rs +++ b/src/common/catalog/src/consts.rs @@ -44,6 +44,16 @@ pub const INFORMATION_SCHEMA_COLUMN_PRIVILEGES_TABLE_ID: u32 = 6; pub const INFORMATION_SCHEMA_COLUMN_STATISTICS_TABLE_ID: u32 = 7; /// id for information_schema.build_info pub const INFORMATION_SCHEMA_BUILD_INFO_TABLE_ID: u32 = 8; +/// id for information_schema.CHARACTER_SETS +pub const INFORMATION_SCHEMA_CHARACTER_SETS_TABLE_ID: u32 = 9; +/// id for information_schema.COLLATIONS +pub const INFORMATION_SCHEMA_COLLATIONS_TABLE_ID: u32 = 10; +/// id for information_schema.COLLATIONS +pub const INFORMATION_SCHEMA_COLLATION_CHARACTER_SET_APPLICABILITY_TABLE_ID: u32 = 11; +/// id for information_schema.CHECK_CONSTRAINTS +pub const INFORMATION_SCHEMA_CHECK_CONSTRAINTS_TABLE_ID: u32 = 12; +/// id for information_schema.EVENTS +pub const INFORMATION_SCHEMA_EVENTS_TABLE_ID: u32 = 13; /// ----- End of information_schema tables ----- pub const MITO_ENGINE: &str = "mito"; diff --git a/tests/cases/standalone/common/show/show_databases_tables.result b/tests/cases/standalone/common/show/show_databases_tables.result index ca4dc2c5b4aa..0d43286ccc88 100644 --- a/tests/cases/standalone/common/show/show_databases_tables.result +++ b/tests/cases/standalone/common/show/show_databases_tables.result @@ -17,14 +17,19 @@ Affected Rows: 0 show tables; -+-------------------+ -| Tables | -+-------------------+ -| build_info | -| column_privileges | -| column_statistics | -| columns | -| engines | -| tables | -+-------------------+ ++---------------------------------------+ +| Tables | ++---------------------------------------+ +| build_info | +| character_sets | +| check_constraints | +| collation_character_set_applicability | +| collations | +| column_privileges | +| column_statistics | +| columns | +| engines | +| events | +| tables | ++---------------------------------------+ diff --git a/tests/cases/standalone/common/system/information_schema.result b/tests/cases/standalone/common/system/information_schema.result index e05ec496d1a8..c3949ca644ba 100644 --- a/tests/cases/standalone/common/system/information_schema.result +++ b/tests/cases/standalone/common/system/information_schema.result @@ -9,59 +9,104 @@ from information_schema.tables where table_name != 'scripts' order by table_schema, table_name; -+---------------+--------------------+-------------------+-----------------+----------+-------------+ -| table_catalog | table_schema | table_name | table_type | table_id | engine | -+---------------+--------------------+-------------------+-----------------+----------+-------------+ -| greptime | information_schema | build_info | LOCAL TEMPORARY | 8 | | -| greptime | information_schema | column_privileges | LOCAL TEMPORARY | 6 | | -| greptime | information_schema | column_statistics | LOCAL TEMPORARY | 7 | | -| greptime | information_schema | columns | LOCAL TEMPORARY | 4 | | -| greptime | information_schema | engines | LOCAL TEMPORARY | 5 | | -| greptime | information_schema | tables | LOCAL TEMPORARY | 3 | | -| greptime | public | numbers | LOCAL TEMPORARY | 2 | test_engine | -+---------------+--------------------+-------------------+-----------------+----------+-------------+ ++---------------+--------------------+---------------------------------------+-----------------+----------+-------------+ +| table_catalog | table_schema | table_name | table_type | table_id | engine | ++---------------+--------------------+---------------------------------------+-----------------+----------+-------------+ +| greptime | information_schema | build_info | LOCAL TEMPORARY | 8 | | +| greptime | information_schema | character_sets | LOCAL TEMPORARY | 9 | | +| greptime | information_schema | check_constraints | LOCAL TEMPORARY | 12 | | +| greptime | information_schema | collation_character_set_applicability | LOCAL TEMPORARY | 11 | | +| greptime | information_schema | collations | LOCAL TEMPORARY | 10 | | +| greptime | information_schema | column_privileges | LOCAL TEMPORARY | 6 | | +| greptime | information_schema | column_statistics | LOCAL TEMPORARY | 7 | | +| greptime | information_schema | columns | LOCAL TEMPORARY | 4 | | +| greptime | information_schema | engines | LOCAL TEMPORARY | 5 | | +| greptime | information_schema | events | LOCAL TEMPORARY | 13 | | +| greptime | information_schema | tables | LOCAL TEMPORARY | 3 | | +| greptime | public | numbers | LOCAL TEMPORARY | 2 | test_engine | ++---------------+--------------------+---------------------------------------+-----------------+----------+-------------+ select * from information_schema.columns order by table_schema, table_name; -+---------------+--------------------+-------------------+------------------+-----------+---------------+ -| table_catalog | table_schema | table_name | column_name | data_type | semantic_type | -+---------------+--------------------+-------------------+------------------+-----------+---------------+ -| greptime | information_schema | build_info | pkg_version | String | FIELD | -| greptime | information_schema | build_info | git_dirty | String | FIELD | -| greptime | information_schema | build_info | git_commit_short | String | FIELD | -| greptime | information_schema | build_info | git_commit | String | FIELD | -| greptime | information_schema | build_info | git_branch | String | FIELD | -| greptime | information_schema | column_privileges | grantee | String | FIELD | -| greptime | information_schema | column_privileges | is_grantable | String | FIELD | -| greptime | information_schema | column_privileges | privilege_type | String | FIELD | -| greptime | information_schema | column_privileges | column_name | String | FIELD | -| greptime | information_schema | column_privileges | table_name | String | FIELD | -| greptime | information_schema | column_privileges | table_schema | String | FIELD | -| greptime | information_schema | column_privileges | table_catalog | String | FIELD | -| greptime | information_schema | column_statistics | histogram | String | FIELD | -| greptime | information_schema | column_statistics | column_name | String | FIELD | -| greptime | information_schema | column_statistics | table_name | String | FIELD | -| greptime | information_schema | column_statistics | schema_name | String | FIELD | -| greptime | information_schema | columns | table_name | String | FIELD | -| greptime | information_schema | columns | semantic_type | String | FIELD | -| greptime | information_schema | columns | data_type | String | FIELD | -| greptime | information_schema | columns | column_name | String | FIELD | -| greptime | information_schema | columns | table_schema | String | FIELD | -| greptime | information_schema | columns | table_catalog | String | FIELD | -| greptime | information_schema | engines | savepoints | String | FIELD | -| greptime | information_schema | engines | xa | String | FIELD | -| greptime | information_schema | engines | transactions | String | FIELD | -| greptime | information_schema | engines | comment | String | FIELD | -| greptime | information_schema | engines | support | String | FIELD | -| greptime | information_schema | engines | engine | String | FIELD | -| greptime | information_schema | tables | table_schema | String | FIELD | -| greptime | information_schema | tables | table_catalog | String | FIELD | -| greptime | information_schema | tables | engine | String | FIELD | -| greptime | information_schema | tables | table_id | UInt32 | FIELD | -| greptime | information_schema | tables | table_type | String | FIELD | -| greptime | information_schema | tables | table_name | String | FIELD | -| greptime | public | numbers | number | UInt32 | TAG | -+---------------+--------------------+-------------------+------------------+-----------+---------------+ ++---------------+--------------------+---------------------------------------+----------------------+-----------+---------------+ +| table_catalog | table_schema | table_name | column_name | data_type | semantic_type | ++---------------+--------------------+---------------------------------------+----------------------+-----------+---------------+ +| greptime | information_schema | build_info | git_branch | String | FIELD | +| greptime | information_schema | build_info | git_commit | String | FIELD | +| greptime | information_schema | build_info | git_commit_short | String | FIELD | +| greptime | information_schema | build_info | git_dirty | String | FIELD | +| greptime | information_schema | build_info | pkg_version | String | FIELD | +| greptime | information_schema | character_sets | maxlen | Int64 | FIELD | +| greptime | information_schema | character_sets | character_set_name | String | FIELD | +| greptime | information_schema | character_sets | default_collate_name | String | FIELD | +| greptime | information_schema | character_sets | description | String | FIELD | +| greptime | information_schema | check_constraints | check_clause | String | FIELD | +| greptime | information_schema | check_constraints | constraint_name | String | FIELD | +| greptime | information_schema | check_constraints | constraint_schema | String | FIELD | +| greptime | information_schema | check_constraints | constraint_catalog | String | FIELD | +| greptime | information_schema | collation_character_set_applicability | character_set_name | String | FIELD | +| greptime | information_schema | collation_character_set_applicability | collation_name | String | FIELD | +| greptime | information_schema | collations | collation_name | String | FIELD | +| greptime | information_schema | collations | character_set_name | String | FIELD | +| greptime | information_schema | collations | id | Int64 | FIELD | +| greptime | information_schema | collations | is_default | String | FIELD | +| greptime | information_schema | collations | is_compiled | String | FIELD | +| greptime | information_schema | collations | sortlen | Int64 | FIELD | +| greptime | information_schema | column_privileges | table_catalog | String | FIELD | +| greptime | information_schema | column_privileges | grantee | String | FIELD | +| greptime | information_schema | column_privileges | privilege_type | String | FIELD | +| greptime | information_schema | column_privileges | is_grantable | String | FIELD | +| greptime | information_schema | column_privileges | column_name | String | FIELD | +| greptime | information_schema | column_privileges | table_name | String | FIELD | +| greptime | information_schema | column_privileges | table_schema | String | FIELD | +| greptime | information_schema | column_statistics | schema_name | String | FIELD | +| greptime | information_schema | column_statistics | table_name | String | FIELD | +| greptime | information_schema | column_statistics | column_name | String | FIELD | +| greptime | information_schema | column_statistics | histogram | String | FIELD | +| greptime | information_schema | columns | table_catalog | String | FIELD | +| greptime | information_schema | columns | table_schema | String | FIELD | +| greptime | information_schema | columns | semantic_type | String | FIELD | +| greptime | information_schema | columns | data_type | String | FIELD | +| greptime | information_schema | columns | column_name | String | FIELD | +| greptime | information_schema | columns | table_name | String | FIELD | +| greptime | information_schema | engines | savepoints | String | FIELD | +| greptime | information_schema | engines | xa | String | FIELD | +| greptime | information_schema | engines | transactions | String | FIELD | +| greptime | information_schema | engines | comment | String | FIELD | +| greptime | information_schema | engines | support | String | FIELD | +| greptime | information_schema | engines | engine | String | FIELD | +| greptime | information_schema | events | sql_mode | String | FIELD | +| greptime | information_schema | events | interval_value | Int64 | FIELD | +| greptime | information_schema | events | database_collation | String | FIELD | +| greptime | information_schema | events | collation_connection | String | FIELD | +| greptime | information_schema | events | character_set_client | String | FIELD | +| greptime | information_schema | events | originator | Int64 | FIELD | +| greptime | information_schema | events | event_catalog | String | FIELD | +| greptime | information_schema | events | event_schema | String | FIELD | +| greptime | information_schema | events | event_name | String | FIELD | +| greptime | information_schema | events | definer | String | FIELD | +| greptime | information_schema | events | time_zone | String | FIELD | +| greptime | information_schema | events | event_body | String | FIELD | +| greptime | information_schema | events | event_definition | String | FIELD | +| greptime | information_schema | events | event_type | String | FIELD | +| greptime | information_schema | events | execute_at | DateTime | FIELD | +| greptime | information_schema | events | event_comment | String | FIELD | +| greptime | information_schema | events | interval_field | String | FIELD | +| greptime | information_schema | events | last_executed | DateTime | FIELD | +| greptime | information_schema | events | starts | DateTime | FIELD | +| greptime | information_schema | events | ends | DateTime | FIELD | +| greptime | information_schema | events | status | String | FIELD | +| greptime | information_schema | events | on_completion | String | FIELD | +| greptime | information_schema | events | created | DateTime | FIELD | +| greptime | information_schema | events | last_altered | DateTime | FIELD | +| greptime | information_schema | tables | table_catalog | String | FIELD | +| greptime | information_schema | tables | table_schema | String | FIELD | +| greptime | information_schema | tables | table_name | String | FIELD | +| greptime | information_schema | tables | table_type | String | FIELD | +| greptime | information_schema | tables | table_id | UInt32 | FIELD | +| greptime | information_schema | tables | engine | String | FIELD | +| greptime | public | numbers | number | UInt32 | TAG | ++---------------+--------------------+---------------------------------------+----------------------+-----------+---------------+ create database my_db; @@ -197,6 +242,48 @@ select * from COLUMN_STATISTICS; +-------------+------------+-------------+-----------+ +-------------+------------+-------------+-----------+ +select * from CHARACTER_SETS; + ++--------------------+----------------------+---------------+--------+ +| character_set_name | default_collate_name | description | maxlen | ++--------------------+----------------------+---------------+--------+ +| utf8 | utf8_bin | UTF-8 Unicode | 4 | ++--------------------+----------------------+---------------+--------+ + +select * from COLLATIONS; + ++----------------+--------------------+----+------------+-------------+---------+ +| collation_name | character_set_name | id | is_default | is_compiled | sortlen | ++----------------+--------------------+----+------------+-------------+---------+ +| utf8_bin | utf8 | 1 | Yes | Yes | 1 | ++----------------+--------------------+----+------------+-------------+---------+ + +select * from COLLATION_CHARACTER_SET_APPLICABILITY; + ++----------------+--------------------+ +| collation_name | character_set_name | ++----------------+--------------------+ +| utf8_bin | utf8 | ++----------------+--------------------+ + +desc table CHECK_CONSTRAINTS; + ++--------------------+--------+-----+------+---------+---------------+ +| Column | Type | Key | Null | Default | Semantic Type | ++--------------------+--------+-----+------+---------+---------------+ +| constraint_catalog | String | | NO | | FIELD | +| constraint_schema | String | | NO | | FIELD | +| constraint_name | String | | NO | | FIELD | +| check_clause | String | | NO | | FIELD | ++--------------------+--------+-----+------+---------+---------------+ + +select * from CHECK_CONSTRAINTS; + ++--------------------+-------------------+-----------------+--------------+ +| constraint_catalog | constraint_schema | constraint_name | check_clause | ++--------------------+-------------------+-----------------+--------------+ ++--------------------+-------------------+-----------------+--------------+ + use public; Affected Rows: 0 diff --git a/tests/cases/standalone/common/system/information_schema.sql b/tests/cases/standalone/common/system/information_schema.sql index 8916842af42d..34db6c144f4f 100644 --- a/tests/cases/standalone/common/system/information_schema.sql +++ b/tests/cases/standalone/common/system/information_schema.sql @@ -60,4 +60,14 @@ desc table COLUMN_STATISTICS; select * from COLUMN_STATISTICS; +select * from CHARACTER_SETS; + +select * from COLLATIONS; + +select * from COLLATION_CHARACTER_SET_APPLICABILITY; + +desc table CHECK_CONSTRAINTS; + +select * from CHECK_CONSTRAINTS; + use public;