From 903da8f4cb2908c26af518d2e8aba97b68fd6a1d Mon Sep 17 00:00:00 2001 From: dennis zhuang Date: Mon, 9 Dec 2024 11:27:46 +0800 Subject: [PATCH] fix: show create table doesn't quote option keys which contains dot (#5108) * fix: show create table doesn't quote option keys which contains dot * fix: compile --- src/query/src/sql/show_create_table.rs | 17 +- src/sql/src/statements/option_map.rs | 12 +- .../common/alter/alter_table_options.result | 166 +++++++++--------- 3 files changed, 108 insertions(+), 87 deletions(-) diff --git a/src/query/src/sql/show_create_table.rs b/src/query/src/sql/show_create_table.rs index 17f1dcdd394b..ca69dfc5e69e 100644 --- a/src/query/src/sql/show_create_table.rs +++ b/src/query/src/sql/show_create_table.rs @@ -215,6 +215,7 @@ pub fn create_table_stmt( #[cfg(test)] mod tests { use std::sync::Arc; + use std::time::Duration; use common_time::timestamp::TimeUnit; use datatypes::prelude::ConcreteDataType; @@ -258,13 +259,22 @@ mod tests { let catalog_name = "greptime".to_string(); let regions = vec![0, 1, 2]; + let mut options = table::requests::TableOptions { + ttl: Some(Duration::from_secs(30).into()), + ..Default::default() + }; + + let _ = options + .extra_options + .insert("compaction.type".to_string(), "twcs".to_string()); + let meta = TableMetaBuilder::default() .schema(table_schema) .primary_key_indices(vec![0, 1]) .value_indices(vec![2, 3]) .engine("mito".to_string()) .next_column_id(0) - .options(Default::default()) + .options(options) .created_on(Default::default()) .region_numbers(regions) .build() @@ -301,7 +311,10 @@ CREATE TABLE IF NOT EXISTS "system_metrics" ( INVERTED INDEX ("host") ) ENGINE=mito -"#, +WITH( + 'compaction.type' = 'twcs', + ttl = '30s' +)"#, sql ); } diff --git a/src/sql/src/statements/option_map.rs b/src/sql/src/statements/option_map.rs index 86f186d9b15d..9ff8d94312fd 100644 --- a/src/sql/src/statements/option_map.rs +++ b/src/sql/src/statements/option_map.rs @@ -79,10 +79,18 @@ impl OptionMap { pub fn kv_pairs(&self) -> Vec { let mut result = Vec::with_capacity(self.options.len() + self.secrets.len()); for (k, v) in self.options.iter() { - result.push(format!("{k} = '{}'", v.escape_default())); + if k.contains(".") { + result.push(format!("'{k}' = '{}'", v.escape_default())); + } else { + result.push(format!("{k} = '{}'", v.escape_default())); + } } for (k, _) in self.secrets.iter() { - result.push(format!("{k} = '******'")); + if k.contains(".") { + result.push(format!("'{k}' = '******'")); + } else { + result.push(format!("{k} = '******'")); + } } result } diff --git a/tests/cases/standalone/common/alter/alter_table_options.result b/tests/cases/standalone/common/alter/alter_table_options.result index b38a99d8465e..14849a70d4ff 100644 --- a/tests/cases/standalone/common/alter/alter_table_options.result +++ b/tests/cases/standalone/common/alter/alter_table_options.result @@ -173,28 +173,28 @@ Affected Rows: 0 SHOW CREATE TABLE ato; -+-------+----------------------------------------------------+ -| Table | Create Table | -+-------+----------------------------------------------------+ -| ato | CREATE TABLE IF NOT EXISTS "ato" ( | -| | "i" INT NULL, | -| | "j" TIMESTAMP(3) NOT NULL, | -| | TIME INDEX ("j"), | -| | PRIMARY KEY ("i") | -| | ) | -| | | -| | ENGINE=mito | -| | WITH( | -| | compaction.twcs.max_active_window_files = '2', | -| | compaction.twcs.max_active_window_runs = '6', | -| | compaction.twcs.max_inactive_window_files = '2', | -| | compaction.twcs.max_inactive_window_runs = '6', | -| | compaction.twcs.max_output_file_size = '500MB', | -| | compaction.twcs.time_window = '2h', | -| | compaction.type = 'twcs', | -| | ttl = '1s' | -| | ) | -+-------+----------------------------------------------------+ ++-------+------------------------------------------------------+ +| Table | Create Table | ++-------+------------------------------------------------------+ +| ato | CREATE TABLE IF NOT EXISTS "ato" ( | +| | "i" INT NULL, | +| | "j" TIMESTAMP(3) NOT NULL, | +| | TIME INDEX ("j"), | +| | PRIMARY KEY ("i") | +| | ) | +| | | +| | ENGINE=mito | +| | WITH( | +| | 'compaction.twcs.max_active_window_files' = '2', | +| | 'compaction.twcs.max_active_window_runs' = '6', | +| | 'compaction.twcs.max_inactive_window_files' = '2', | +| | 'compaction.twcs.max_inactive_window_runs' = '6', | +| | 'compaction.twcs.max_output_file_size' = '500MB', | +| | 'compaction.twcs.time_window' = '2h', | +| | 'compaction.type' = 'twcs', | +| | ttl = '1s' | +| | ) | ++-------+------------------------------------------------------+ ALTER TABLE ato UNSET 'compaction.twcs.time_window'; @@ -206,27 +206,27 @@ Error: 1004(InvalidArguments), Invalid unset table option request: Invalid set r SHOW CREATE TABLE ato; -+-------+----------------------------------------------------+ -| Table | Create Table | -+-------+----------------------------------------------------+ -| ato | CREATE TABLE IF NOT EXISTS "ato" ( | -| | "i" INT NULL, | -| | "j" TIMESTAMP(3) NOT NULL, | -| | TIME INDEX ("j"), | -| | PRIMARY KEY ("i") | -| | ) | -| | | -| | ENGINE=mito | -| | WITH( | -| | compaction.twcs.max_active_window_files = '2', | -| | compaction.twcs.max_active_window_runs = '6', | -| | compaction.twcs.max_inactive_window_files = '2', | -| | compaction.twcs.max_inactive_window_runs = '6', | -| | compaction.twcs.max_output_file_size = '500MB', | -| | compaction.type = 'twcs', | -| | ttl = '1s' | -| | ) | -+-------+----------------------------------------------------+ ++-------+------------------------------------------------------+ +| Table | Create Table | ++-------+------------------------------------------------------+ +| ato | CREATE TABLE IF NOT EXISTS "ato" ( | +| | "i" INT NULL, | +| | "j" TIMESTAMP(3) NOT NULL, | +| | TIME INDEX ("j"), | +| | PRIMARY KEY ("i") | +| | ) | +| | | +| | ENGINE=mito | +| | WITH( | +| | 'compaction.twcs.max_active_window_files' = '2', | +| | 'compaction.twcs.max_active_window_runs' = '6', | +| | 'compaction.twcs.max_inactive_window_files' = '2', | +| | 'compaction.twcs.max_inactive_window_runs' = '6', | +| | 'compaction.twcs.max_output_file_size' = '500MB', | +| | 'compaction.type' = 'twcs', | +| | ttl = '1s' | +| | ) | ++-------+------------------------------------------------------+ ALTER TABLE ato SET 'compaction.twcs.max_inactive_window_runs'=''; @@ -234,50 +234,50 @@ Affected Rows: 0 SHOW CREATE TABLE ato; -+-------+----------------------------------------------------+ -| Table | Create Table | -+-------+----------------------------------------------------+ -| ato | CREATE TABLE IF NOT EXISTS "ato" ( | -| | "i" INT NULL, | -| | "j" TIMESTAMP(3) NOT NULL, | -| | TIME INDEX ("j"), | -| | PRIMARY KEY ("i") | -| | ) | -| | | -| | ENGINE=mito | -| | WITH( | -| | compaction.twcs.max_active_window_files = '2', | -| | compaction.twcs.max_active_window_runs = '6', | -| | compaction.twcs.max_inactive_window_files = '2', | -| | compaction.twcs.max_output_file_size = '500MB', | -| | compaction.type = 'twcs', | -| | ttl = '1s' | -| | ) | -+-------+----------------------------------------------------+ ++-------+------------------------------------------------------+ +| Table | Create Table | ++-------+------------------------------------------------------+ +| ato | CREATE TABLE IF NOT EXISTS "ato" ( | +| | "i" INT NULL, | +| | "j" TIMESTAMP(3) NOT NULL, | +| | TIME INDEX ("j"), | +| | PRIMARY KEY ("i") | +| | ) | +| | | +| | ENGINE=mito | +| | WITH( | +| | 'compaction.twcs.max_active_window_files' = '2', | +| | 'compaction.twcs.max_active_window_runs' = '6', | +| | 'compaction.twcs.max_inactive_window_files' = '2', | +| | 'compaction.twcs.max_output_file_size' = '500MB', | +| | 'compaction.type' = 'twcs', | +| | ttl = '1s' | +| | ) | ++-------+------------------------------------------------------+ -- SQLNESS ARG restart=true SHOW CREATE TABLE ato; -+-------+----------------------------------------------------+ -| Table | Create Table | -+-------+----------------------------------------------------+ -| ato | CREATE TABLE IF NOT EXISTS "ato" ( | -| | "i" INT NULL, | -| | "j" TIMESTAMP(3) NOT NULL, | -| | TIME INDEX ("j"), | -| | PRIMARY KEY ("i") | -| | ) | -| | | -| | ENGINE=mito | -| | WITH( | -| | compaction.twcs.max_active_window_files = '2', | -| | compaction.twcs.max_active_window_runs = '6', | -| | compaction.twcs.max_inactive_window_files = '2', | -| | compaction.twcs.max_output_file_size = '500MB', | -| | compaction.type = 'twcs', | -| | ttl = '1s' | -| | ) | -+-------+----------------------------------------------------+ ++-------+------------------------------------------------------+ +| Table | Create Table | ++-------+------------------------------------------------------+ +| ato | CREATE TABLE IF NOT EXISTS "ato" ( | +| | "i" INT NULL, | +| | "j" TIMESTAMP(3) NOT NULL, | +| | TIME INDEX ("j"), | +| | PRIMARY KEY ("i") | +| | ) | +| | | +| | ENGINE=mito | +| | WITH( | +| | 'compaction.twcs.max_active_window_files' = '2', | +| | 'compaction.twcs.max_active_window_runs' = '6', | +| | 'compaction.twcs.max_inactive_window_files' = '2', | +| | 'compaction.twcs.max_output_file_size' = '500MB', | +| | 'compaction.type' = 'twcs', | +| | ttl = '1s' | +| | ) | ++-------+------------------------------------------------------+ DROP TABLE ato;