feat: show create table only for base table (#4099)

* feat: show create table only for base table

Signed-off-by: tison <wander4096@gmail.com>

* add new cases

Signed-off-by: tison <wander4096@gmail.com>

---------

Signed-off-by: tison <wander4096@gmail.com>
This commit is contained in:
tison
2024-06-05 05:29:07 +08:00
committed by GitHub
parent dd06e107f9
commit 1850fe2956
5 changed files with 43 additions and 6 deletions

View File

@@ -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<T> = std::result::Result<T, Error>;
@@ -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(),

View File

@@ -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)

View File

@@ -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<Output> {
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())

View File

@@ -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

View File

@@ -79,3 +79,7 @@ WITH(
show create table phy;
drop table phy;
show create table numbers;
show create table information_schema.columns;