diff --git a/src/operator/src/error.rs b/src/operator/src/error.rs index f026654795..1eccbe081c 100644 --- a/src/operator/src/error.rs +++ b/src/operator/src/error.rs @@ -22,6 +22,7 @@ use common_macro::stack_trace_debug; use datafusion::parquet; use datatypes::arrow::error::ArrowError; use snafu::{Location, Snafu}; +use table::metadata::TableType; #[derive(Snafu)] #[snafu(visibility(pub))] @@ -697,6 +698,18 @@ pub enum Error { location: Location, source: substrait::error::Error, }, + + #[snafu(display( + "Show create table only for base table. {} is {}", + table_name, + table_type + ))] + ShowCreateTableBaseOnly { + table_name: String, + table_type: TableType, + #[snafu(implicit)] + location: Location, + }, } pub type Result = std::result::Result; @@ -734,7 +747,9 @@ impl ErrorExt for Error { StatusCode::TableAlreadyExists } - Error::NotSupported { .. } => StatusCode::Unsupported, + Error::NotSupported { .. } | Error::ShowCreateTableBaseOnly { .. } => { + StatusCode::Unsupported + } Error::TableMetadataManager { source, .. } => source.status_code(), diff --git a/src/operator/src/statement.rs b/src/operator/src/statement.rs index 52c1d3b7b7..bbfe34d91e 100644 --- a/src/operator/src/statement.rs +++ b/src/operator/src/statement.rs @@ -190,7 +190,7 @@ impl StatementExecutor { let (catalog, schema, table) = table_idents_to_full_name(table_name_stmt, &query_ctx) .map_err(BoxedError::new) - .context(error::ExternalSnafu)?; + .context(ExternalSnafu)?; table_names.push(TableName::new(catalog, schema, table)); } self.drop_tables(&table_names[..], stmt.drop_if_exists(), query_ctx.clone()) @@ -209,7 +209,7 @@ impl StatementExecutor { let (catalog, schema, table) = table_idents_to_full_name(stmt.table_name(), &query_ctx) .map_err(BoxedError::new) - .context(error::ExternalSnafu)?; + .context(ExternalSnafu)?; let table_name = TableName::new(catalog, schema, table); self.truncate_table(table_name, query_ctx).await } @@ -226,14 +226,14 @@ impl StatementExecutor { let (catalog, schema, table) = table_idents_to_full_name(&show.table_name, &query_ctx) .map_err(BoxedError::new) - .context(error::ExternalSnafu)?; + .context(ExternalSnafu)?; let table_ref = self .catalog_manager .table(&catalog, &schema, &table) .await - .context(error::CatalogSnafu)? - .context(error::TableNotFoundSnafu { table_name: &table })?; + .context(CatalogSnafu)? + .context(TableNotFoundSnafu { table_name: &table })?; let table_name = TableName::new(catalog, schema, table); self.show_create_table(table_name, table_ref, query_ctx) diff --git a/src/operator/src/statement/show.rs b/src/operator/src/statement/show.rs index a89df59852..818734754b 100644 --- a/src/operator/src/statement/show.rs +++ b/src/operator/src/statement/show.rs @@ -23,6 +23,7 @@ use sql::statements::create::Partitions; use sql::statements::show::{ ShowColumns, ShowDatabases, ShowIndex, ShowKind, ShowTables, ShowVariables, }; +use table::metadata::TableType; use table::table_name::TableName; use table::TableRef; @@ -81,6 +82,15 @@ impl StatementExecutor { table: TableRef, query_ctx: QueryContextRef, ) -> Result { + let table_info = table.table_info(); + if table_info.table_type != TableType::Base { + return error::ShowCreateTableBaseOnlySnafu { + table_name: table_name.to_string(), + table_type: table_info.table_type, + } + .fail(); + } + let partitions = self .partition_manager .find_table_partitions(table.table_info().table_id()) diff --git a/tests/cases/standalone/common/show/show_create.result b/tests/cases/standalone/common/show/show_create.result index 6071b5cf9a..02830c7751 100644 --- a/tests/cases/standalone/common/show/show_create.result +++ b/tests/cases/standalone/common/show/show_create.result @@ -192,3 +192,11 @@ drop table phy; Affected Rows: 0 +show create table numbers; + +Error: 1001(Unsupported), Show create table only for base table. greptime.public.numbers is TEMPORARY + +show create table information_schema.columns; + +Error: 1001(Unsupported), Show create table only for base table. greptime.information_schema.columns is TEMPORARY + diff --git a/tests/cases/standalone/common/show/show_create.sql b/tests/cases/standalone/common/show/show_create.sql index f59b72971a..9a45136ed4 100644 --- a/tests/cases/standalone/common/show/show_create.sql +++ b/tests/cases/standalone/common/show/show_create.sql @@ -79,3 +79,7 @@ WITH( show create table phy; drop table phy; + +show create table numbers; + +show create table information_schema.columns;