From 4c33457b198b4b9824b333fd9023543f2f59cd44 Mon Sep 17 00:00:00 2001 From: Ning Sun Date: Mon, 8 Jul 2024 18:05:54 +0800 Subject: [PATCH] fix: error on show databases in non-default catalog --- .../src/information_schema/schemata.rs | 13 +++---- tests-integration/src/tests/instance_test.rs | 39 ++++++++++++++++++- 2 files changed, 43 insertions(+), 9 deletions(-) diff --git a/src/catalog/src/information_schema/schemata.rs b/src/catalog/src/information_schema/schemata.rs index d4151e827916..e33efea89dc6 100644 --- a/src/catalog/src/information_schema/schemata.rs +++ b/src/catalog/src/information_schema/schemata.rs @@ -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}; @@ -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 }; diff --git a/tests-integration/src/tests/instance_test.rs b/tests-integration/src/tests/instance_test.rs index b40ed6113b06..b0bc7f4c881f 100644 --- a/tests-integration/src/tests/instance_test.rs +++ b/tests-integration/src/tests/instance_test.rs @@ -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; @@ -1879,6 +1879,43 @@ async fn test_information_schema_dot_tables(instance: Arc) { check_output_stream(output, expected).await; } +#[apply(both_instances_cases)] +async fn test_show_databases(instance: Arc) { + 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) { common_telemetry::init_default_ut_logging();