Skip to content

Commit

Permalink
fix: error on show databases in non-default catalog (#4316)
Browse files Browse the repository at this point in the history
  • Loading branch information
sunng87 authored Jul 8, 2024
1 parent aa4d10e commit 81308b9
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 9 deletions.
13 changes: 5 additions & 8 deletions src/catalog/src/information_schema/schemata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use store_api::storage::{ScanRequest, TableId};

use super::SCHEMATA;
use crate::error::{
CreateRecordBatchSnafu, InternalSnafu, Result, SchemaNotFoundSnafu, TableMetadataManagerSnafu,
CreateRecordBatchSnafu, InternalSnafu, Result, TableMetadataManagerSnafu,
UpgradeWeakCatalogManagerRefSnafu,
};
use crate::information_schema::{utils, InformationTable, Predicates};
Expand Down Expand Up @@ -172,17 +172,14 @@ impl InformationSchemaSchemataBuilder {

for schema_name in catalog_manager.schema_names(&catalog_name).await? {
let opts = if let Some(table_metadata_manager) = &table_metadata_manager {
let schema_opts = table_metadata_manager
table_metadata_manager
.schema_manager()
.get(SchemaNameKey::new(&catalog_name, &schema_name))
.await
.context(TableMetadataManagerSnafu)?
.context(SchemaNotFoundSnafu {
catalog: &catalog_name,
schema: &schema_name,
})?;

Some(format!("{schema_opts}"))
// information_schema is not available from this
// table_metadata_manager and we return None
.map(|schema_opts| format!("{schema_opts}"))
} else {
None
};
Expand Down
39 changes: 38 additions & 1 deletion tests-integration/src/tests/instance_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use std::assert_matches::assert_matches;
use std::env;
use std::sync::Arc;

use client::OutputData;
use client::{OutputData, DEFAULT_SCHEMA_NAME};
use common_catalog::consts::DEFAULT_CATALOG_NAME;
use common_query::Output;
use common_recordbatch::util;
Expand Down Expand Up @@ -1879,6 +1879,43 @@ async fn test_information_schema_dot_tables(instance: Arc<dyn MockInstance>) {
check_output_stream(output, expected).await;
}

#[apply(both_instances_cases)]
async fn test_show_databases(instance: Arc<dyn MockInstance>) {
common_telemetry::init_default_ut_logging();
let instance = instance.frontend();

let sql = "show databases";

let query_ctx = Arc::new(QueryContext::with(
DEFAULT_CATALOG_NAME,
DEFAULT_SCHEMA_NAME,
));
let output = execute_sql_with(&instance, sql, query_ctx.clone())
.await
.data;
let expected = "\
+--------------------+
| Database |
+--------------------+
| greptime_private |
| information_schema |
| public |
+--------------------+";
check_output_stream(output, expected).await;

let query_ctx = Arc::new(QueryContext::with("random_catalog", DEFAULT_SCHEMA_NAME));
let output = execute_sql_with(&instance, sql, query_ctx.clone())
.await
.data;
let expected = "\
+--------------------+
| Database |
+--------------------+
| information_schema |
+--------------------+";
check_output_stream(output, expected).await;
}

#[apply(both_instances_cases)]
async fn test_information_schema_dot_columns(instance: Arc<dyn MockInstance>) {
common_telemetry::init_default_ut_logging();
Expand Down

0 comments on commit 81308b9

Please sign in to comment.