Skip to content

Commit

Permalink
test: support distribute and standalone have different output
Browse files Browse the repository at this point in the history
  • Loading branch information
haohuaijin committed Apr 18, 2023
1 parent e1452de commit 7d730b1
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 16 deletions.
61 changes: 45 additions & 16 deletions src/frontend/src/tests/instance_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,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>) {
let is_distributed_mode = instance.is_distributed_mode();
let instance = instance.frontend();

let sql = "create table another_table(i bigint time index)";
Expand All @@ -913,27 +914,55 @@ async fn test_information_schema(instance: Arc<dyn MockInstance>) {

// User can only see information schema under current catalog.
// A necessary requirement to GreptimeCloud.
let sql = "select table_catalog, table_schema, table_name, table_type, engine from information_schema.tables where table_type != 'SYSTEM VIEW' order by table_name";
let sql = "select table_catalog, table_schema, table_name, table_type, table_id, engine from information_schema.tables where table_type != 'SYSTEM VIEW' order by table_name";

let output = execute_sql(&instance, sql).await;
let expected = "\
+---------------+--------------------+------------+------------+-------------+
| table_catalog | table_schema | table_name | table_type | engine |
+---------------+--------------------+------------+------------+-------------+
| greptime | public | numbers | BASE TABLE | test_engine |
| greptime | public | scripts | BASE TABLE | mito |
| greptime | information_schema | tables | VIEW | |
+---------------+--------------------+------------+------------+-------------+";
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 | | |
+---------------+--------------------+------------+------------+----------+-------------+"
}
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 | | |
+---------------+--------------------+------------+------------+----------+-------------+"
}
};

check_output_stream(output, expected).await;

let output = execute_sql_with(&instance, sql, query_ctx).await;
let expected = "\
+-----------------+--------------------+---------------+------------+--------+
| table_catalog | table_schema | table_name | table_type | engine |
+-----------------+--------------------+---------------+------------+--------+
| another_catalog | another_schema | another_table | BASE TABLE | mito |
| another_catalog | information_schema | tables | VIEW | |
+-----------------+--------------------+---------------+------------+--------+";
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 | | |
+-----------------+--------------------+---------------+------------+----------+--------+"
}
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 | | |
+-----------------+--------------------+---------------+------------+----------+--------+"
}
};
check_output_stream(output, expected).await;
}

Expand Down
10 changes: 10 additions & 0 deletions src/frontend/src/tests/test_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,28 @@ use crate::tests::{

pub(crate) trait MockInstance {
fn frontend(&self) -> Arc<Instance>;

fn is_distributed_mode(&self) -> bool;
}

impl MockInstance for MockStandaloneInstance {
fn frontend(&self) -> Arc<Instance> {
self.instance.clone()
}

fn is_distributed_mode(&self) -> bool {
false
}
}

impl MockInstance for MockDistributedInstance {
fn frontend(&self) -> Arc<Instance> {
self.frontend.clone()
}

fn is_distributed_mode(&self) -> bool {
true
}
}

pub(crate) async fn standalone() -> Arc<dyn MockInstance> {
Expand Down

0 comments on commit 7d730b1

Please sign in to comment.