Skip to content

Commit 3840805

Browse files
authored
fix: check compression options when binding CREATE TABLE statement (#18261)
* check create table compression options when create `Plan`
1 parent 702664f commit 3840805

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

โ€Žsrc/query/sql/src/planner/binder/ddl/table.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ use databend_common_storage::init_operator;
8888
use databend_common_storages_view::view_table::QUERY;
8989
use databend_common_storages_view::view_table::VIEW_ENGINE;
9090
use databend_storages_common_table_meta::table::is_reserved_opt_key;
91+
use databend_storages_common_table_meta::table::TableCompression;
9192
use databend_storages_common_table_meta::table::OPT_KEY_CLUSTER_TYPE;
9293
use databend_storages_common_table_meta::table::OPT_KEY_DATABASE_ID;
9394
use databend_storages_common_table_meta::table::OPT_KEY_ENGINE_META;
@@ -742,6 +743,15 @@ impl Binder {
742743
OPT_KEY_TABLE_COMPRESSION.to_owned(),
743744
default_compression.to_owned(),
744745
);
746+
} else {
747+
// validate the compression type
748+
let _: TableCompression = options
749+
.get(OPT_KEY_TABLE_COMPRESSION)
750+
.ok_or_else(|| {
751+
ErrorCode::BadArguments("Table compression type is not specified")
752+
})?
753+
.as_str()
754+
.try_into()?;
745755
}
746756
} else if table_indexes.is_some() {
747757
return Err(ErrorCode::UnsupportedIndex(format!(

โ€Žsrc/query/storages/common/table_meta/src/table/table_compression.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl TryFrom<&str> for TableCompression {
4040
"zstd" => Ok(TableCompression::Zstd),
4141
"lz4" => Ok(TableCompression::LZ4),
4242
"snappy" => Ok(TableCompression::Snappy),
43-
other => Err(ErrorCode::UnknownFormat(format!(
43+
other => Err(ErrorCode::UnknownCompressionType(format!(
4444
"unsupported table compression: {}",
4545
other
4646
))),

โ€Žtests/sqllogictests/suites/base/05_ddl/05_0000_ddl_create_tables.test

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,3 +681,6 @@ query
681681
select '\'0\'' = a from t
682682
----
683683
1
684+
685+
statement error 1075
686+
create or replace table t(id int) compression='xxxx';

0 commit comments

Comments
ย (0)