Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adds build_info table #2969

Merged
merged 1 commit into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/catalog/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ arc-swap = "1.0"
arrow-schema.workspace = true
async-stream.workspace = true
async-trait = "0.1"
build-data = "0.1"
common-catalog.workspace = true
common-error.workspace = true
common-grpc.workspace = true
Expand Down
4 changes: 3 additions & 1 deletion src/catalog/src/information_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ lazy_static! {
static ref MEMORY_TABLES: &'static [&'static str] = &[
ENGINES,
COLUMN_PRIVILEGES,
COLUMN_STATISTICS
COLUMN_STATISTICS,
BUILD_INFO,
];
}

Expand Down Expand Up @@ -154,6 +155,7 @@ impl InformationSchemaProvider {
ENGINES => setup_memory_table!(ENGINES),
COLUMN_PRIVILEGES => setup_memory_table!(COLUMN_PRIVILEGES),
COLUMN_STATISTICS => setup_memory_table!(COLUMN_STATISTICS),
BUILD_INFO => setup_memory_table!(BUILD_INFO),
_ => None,
}
}
Expand Down
27 changes: 27 additions & 0 deletions src/catalog/src/information_schema/memory_table/tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ use datatypes::vectors::StringVector;

use crate::information_schema::table_names::*;

const UNKNOWN: &str = "unknown";

/// Find the schema and columns by the table_name, only valid for memory tables.
/// Safety: the user MUST ensure the table schema exists, panic otherwise.
pub fn get_schema_columns(table_name: &str) -> (SchemaRef, Vec<VectorRef>) {
Expand Down Expand Up @@ -70,6 +72,31 @@ pub fn get_schema_columns(table_name: &str) -> (SchemaRef, Vec<VectorRef>) {
],
),

BUILD_INFO => (
string_columns(&[
"GIT_BRANCH",
"GIT_COMMIT",
"GIT_COMMIT_SHORT",
"GIT_DIRTY",
"PKG_VERSION",
]),
vec![
Arc::new(StringVector::from(vec![
build_data::get_git_branch().unwrap_or_else(|_| UNKNOWN.to_string())
])),
Arc::new(StringVector::from(vec![
build_data::get_git_commit().unwrap_or_else(|_| UNKNOWN.to_string())
])),
Arc::new(StringVector::from(vec![
build_data::get_git_commit_short().unwrap_or_else(|_| UNKNOWN.to_string())
])),
Arc::new(StringVector::from(vec![
build_data::get_git_dirty().map_or(UNKNOWN.to_string(), |v| v.to_string())
])),
Arc::new(StringVector::from(vec![option_env!("CARGO_PKG_VERSION")])),
],
),

_ => unreachable!("Unknown table in information_schema: {}", table_name),
};

Expand Down
1 change: 1 addition & 0 deletions src/catalog/src/information_schema/table_names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ pub const COLUMNS: &str = "columns";
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";
2 changes: 2 additions & 0 deletions src/common/catalog/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ pub const INFORMATION_SCHEMA_ENGINES_TABLE_ID: u32 = 5;
pub const INFORMATION_SCHEMA_COLUMN_PRIVILEGES_TABLE_ID: u32 = 6;
/// id for information_schema.column_statistics
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;
/// ----- End of information_schema tables -----

pub const MITO_ENGINE: &str = "mito";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ show tables;
+-------------------+
| Tables |
+-------------------+
| build_info |
| column_privileges |
| column_statistics |
| columns |
Expand Down
94 changes: 60 additions & 34 deletions tests/cases/standalone/common/system/information_schema.result
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ 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 | |
Expand All @@ -17,40 +18,45 @@ order by table_schema, table_name;

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 | 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_catalog | 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 | columns | table_schema | String | FIELD |
| greptime | information_schema | engines | engine | String | FIELD |
| greptime | information_schema | engines | support | String | FIELD |
| greptime | information_schema | engines | comment | String | FIELD |
| greptime | information_schema | engines | transactions | String | FIELD |
| greptime | information_schema | engines | xa | String | FIELD |
| greptime | information_schema | engines | savepoints | 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 | information_schema | tables | table_schema | 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 | 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_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 | columns | table_catalog | String | FIELD |
| greptime | information_schema | engines | xa | String | FIELD |
| greptime | information_schema | engines | savepoints | 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_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 | information_schema | tables | table_schema | String | FIELD |
| greptime | public | numbers | number | UInt32 | TAG |
+---------------+--------------------+-------------------+------------------+-----------+---------------+

create
database my_db;
Expand Down Expand Up @@ -126,6 +132,26 @@ select * from engines;
| mito | DEFAULT | Storage engine for time-series data | NO | NO | NO |
+--------+---------+-------------------------------------+--------------+----+------------+

desc table build_info;

+------------------+--------+-----+------+---------+---------------+
| Column | Type | Key | Null | Default | Semantic Type |
+------------------+--------+-----+------+---------+---------------+
| git_branch | String | | NO | | FIELD |
| git_commit | String | | NO | | FIELD |
| git_commit_short | String | | NO | | FIELD |
| git_dirty | String | | NO | | FIELD |
| pkg_version | String | | NO | | FIELD |
+------------------+--------+-----+------+---------+---------------+

select count(*) from build_info;

+----------+
| COUNT(*) |
+----------+
| 1 |
+----------+

-- tables not implemented
desc table COLUMN_PRIVILEGES;

Expand Down
4 changes: 4 additions & 0 deletions tests/cases/standalone/common/system/information_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ use information_schema;
-- test engines
select * from engines;

desc table build_info;

select count(*) from build_info;

-- tables not implemented
desc table COLUMN_PRIVILEGES;

Expand Down
Loading