Skip to content

Commit

Permalink
feat: adds build_info table (#2969)
Browse files Browse the repository at this point in the history
  • Loading branch information
killme2008 authored Dec 21, 2023
1 parent ff8c10e commit 054bca3
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 35 deletions.
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

0 comments on commit 054bca3

Please sign in to comment.