Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: error on show databases in non-default catalog #4316

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading