mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-06-01 12:50:40 +00:00
feat: add support for information_schema.columns (#1500)
* feat: add support for information_schema.columns * feat: remove information_schema from its view * Update src/catalog/src/information_schema.rs Co-authored-by: LFC <bayinamine@gmail.com> * fix: error on table data type * test: correct sqlness test for information schema * test: add information_schema.columns sqlness tests --------- Co-authored-by: LFC <bayinamine@gmail.com>
This commit is contained in:
@@ -1234,7 +1234,7 @@ async fn test_execute_copy_from_s3(instance: Arc<dyn MockInstance>) {
|
||||
}
|
||||
|
||||
#[apply(both_instances_cases)]
|
||||
async fn test_information_schema(instance: Arc<dyn MockInstance>) {
|
||||
async fn test_information_schema_dot_tables(instance: Arc<dyn MockInstance>) {
|
||||
let is_distributed_mode = instance.is_distributed_mode();
|
||||
let instance = instance.frontend();
|
||||
|
||||
@@ -1251,23 +1251,21 @@ async fn test_information_schema(instance: Arc<dyn MockInstance>) {
|
||||
let expected = match is_distributed_mode {
|
||||
true => {
|
||||
"\
|
||||
+---------------+--------------------+------------+------------+----------+-------------+
|
||||
| table_catalog | table_schema | table_name | table_type | table_id | engine |
|
||||
+---------------+--------------------+------------+------------+----------+-------------+
|
||||
| greptime | public | numbers | BASE TABLE | 1 | test_engine |
|
||||
| greptime | public | scripts | BASE TABLE | 1024 | mito |
|
||||
| greptime | information_schema | tables | VIEW | | |
|
||||
+---------------+--------------------+------------+------------+----------+-------------+"
|
||||
+---------------+--------------+------------+------------+----------+-------------+
|
||||
| table_catalog | table_schema | table_name | table_type | table_id | engine |
|
||||
+---------------+--------------+------------+------------+----------+-------------+
|
||||
| greptime | public | numbers | BASE TABLE | 1 | test_engine |
|
||||
| greptime | public | scripts | BASE TABLE | 1024 | mito |
|
||||
+---------------+--------------+------------+------------+----------+-------------+"
|
||||
}
|
||||
false => {
|
||||
"\
|
||||
+---------------+--------------------+------------+------------+----------+-------------+
|
||||
| table_catalog | table_schema | table_name | table_type | table_id | engine |
|
||||
+---------------+--------------------+------------+------------+----------+-------------+
|
||||
| greptime | public | numbers | BASE TABLE | 1 | test_engine |
|
||||
| greptime | public | scripts | BASE TABLE | 1 | mito |
|
||||
| greptime | information_schema | tables | VIEW | | |
|
||||
+---------------+--------------------+------------+------------+----------+-------------+"
|
||||
+---------------+--------------+------------+------------+----------+-------------+
|
||||
| table_catalog | table_schema | table_name | table_type | table_id | engine |
|
||||
+---------------+--------------+------------+------------+----------+-------------+
|
||||
| greptime | public | numbers | BASE TABLE | 1 | test_engine |
|
||||
| greptime | public | scripts | BASE TABLE | 1 | mito |
|
||||
+---------------+--------------+------------+------------+----------+-------------+"
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1277,26 +1275,65 @@ async fn test_information_schema(instance: Arc<dyn MockInstance>) {
|
||||
let expected = match is_distributed_mode {
|
||||
true => {
|
||||
"\
|
||||
+-----------------+--------------------+---------------+------------+----------+--------+
|
||||
| table_catalog | table_schema | table_name | table_type | table_id | engine |
|
||||
+-----------------+--------------------+---------------+------------+----------+--------+
|
||||
| another_catalog | another_schema | another_table | BASE TABLE | 1025 | mito |
|
||||
| another_catalog | information_schema | tables | VIEW | | |
|
||||
+-----------------+--------------------+---------------+------------+----------+--------+"
|
||||
+-----------------+----------------+---------------+------------+----------+--------+
|
||||
| table_catalog | table_schema | table_name | table_type | table_id | engine |
|
||||
+-----------------+----------------+---------------+------------+----------+--------+
|
||||
| another_catalog | another_schema | another_table | BASE TABLE | 1025 | mito |
|
||||
+-----------------+----------------+---------------+------------+----------+--------+"
|
||||
}
|
||||
false => {
|
||||
"\
|
||||
+-----------------+--------------------+---------------+------------+----------+--------+
|
||||
| table_catalog | table_schema | table_name | table_type | table_id | engine |
|
||||
+-----------------+--------------------+---------------+------------+----------+--------+
|
||||
| another_catalog | another_schema | another_table | BASE TABLE | 1024 | mito |
|
||||
| another_catalog | information_schema | tables | VIEW | | |
|
||||
+-----------------+--------------------+---------------+------------+----------+--------+"
|
||||
+-----------------+----------------+---------------+------------+----------+--------+
|
||||
| table_catalog | table_schema | table_name | table_type | table_id | engine |
|
||||
+-----------------+----------------+---------------+------------+----------+--------+
|
||||
| another_catalog | another_schema | another_table | BASE TABLE | 1024 | mito |
|
||||
+-----------------+----------------+---------------+------------+----------+--------+"
|
||||
}
|
||||
};
|
||||
check_output_stream(output, expected).await;
|
||||
}
|
||||
|
||||
#[apply(both_instances_cases)]
|
||||
async fn test_information_schema_dot_columns(instance: Arc<dyn MockInstance>) {
|
||||
let instance = instance.frontend();
|
||||
|
||||
let sql = "create table another_table(i bigint time index)";
|
||||
let query_ctx = Arc::new(QueryContext::with("another_catalog", "another_schema"));
|
||||
let output = execute_sql_with(&instance, sql, query_ctx.clone()).await;
|
||||
assert!(matches!(output, Output::AffectedRows(0)));
|
||||
|
||||
// User can only see information schema under current catalog.
|
||||
// A necessary requirement to GreptimeCloud.
|
||||
let sql = "select table_catalog, table_schema, table_name, column_name, data_type from information_schema.columns order by table_name";
|
||||
|
||||
let output = execute_sql(&instance, sql).await;
|
||||
let expected = "\
|
||||
+---------------+--------------+------------+--------------+----------------------+
|
||||
| table_catalog | table_schema | table_name | column_name | data_type |
|
||||
+---------------+--------------+------------+--------------+----------------------+
|
||||
| greptime | public | numbers | number | UInt32 |
|
||||
| greptime | public | scripts | schema | String |
|
||||
| greptime | public | scripts | name | String |
|
||||
| greptime | public | scripts | script | String |
|
||||
| greptime | public | scripts | engine | String |
|
||||
| greptime | public | scripts | timestamp | TimestampMillisecond |
|
||||
| greptime | public | scripts | gmt_created | TimestampMillisecond |
|
||||
| greptime | public | scripts | gmt_modified | TimestampMillisecond |
|
||||
+---------------+--------------+------------+--------------+----------------------+";
|
||||
|
||||
check_output_stream(output, expected).await;
|
||||
|
||||
let output = execute_sql_with(&instance, sql, query_ctx).await;
|
||||
let expected = "\
|
||||
+-----------------+----------------+---------------+-------------+-----------+
|
||||
| table_catalog | table_schema | table_name | column_name | data_type |
|
||||
+-----------------+----------------+---------------+-------------+-----------+
|
||||
| another_catalog | another_schema | another_table | i | Int64 |
|
||||
+-----------------+----------------+---------------+-------------+-----------+";
|
||||
|
||||
check_output_stream(output, expected).await;
|
||||
}
|
||||
|
||||
async fn execute_sql(instance: &Arc<Instance>, sql: &str) -> Output {
|
||||
execute_sql_with(instance, sql, QueryContext::arc()).await
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user