Skip to content

Commit

Permalink
feat: show create table only for base table (#4099)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
tisonkun committed Jun 4, 2024
1 parent dd06e10 commit 1850fe2
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 6 deletions.
17 changes: 16 additions & 1 deletion src/operator/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
Expand Down Expand Up @@ -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>;
Expand Down Expand Up @@ -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(),

Expand Down
10 changes: 5 additions & 5 deletions src/operator/src/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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
}
Expand All @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions src/operator/src/statement/show.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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())
Expand Down
8 changes: 8 additions & 0 deletions tests/cases/standalone/common/show/show_create.result
Original file line number Diff line number Diff line change
Expand Up @@ -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

4 changes: 4 additions & 0 deletions tests/cases/standalone/common/show/show_create.sql
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,7 @@ WITH(
show create table phy;

drop table phy;

show create table numbers;

show create table information_schema.columns;

0 comments on commit 1850fe2

Please sign in to comment.