Skip to content

Commit

Permalink
fix: show create table doesn't quote option keys which contains dot (#…
Browse files Browse the repository at this point in the history
…5108)

* fix: show create table doesn't quote option keys which contains dot

* fix: compile
  • Loading branch information
killme2008 authored Dec 9, 2024
1 parent c0f498b commit 903da8f
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 87 deletions.
17 changes: 15 additions & 2 deletions src/query/src/sql/show_create_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -301,7 +311,10 @@ CREATE TABLE IF NOT EXISTS "system_metrics" (
INVERTED INDEX ("host")
)
ENGINE=mito
"#,
WITH(
'compaction.type' = 'twcs',
ttl = '30s'
)"#,
sql
);
}
Expand Down
12 changes: 10 additions & 2 deletions src/sql/src/statements/option_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,18 @@ impl OptionMap {
pub fn kv_pairs(&self) -> Vec<String> {
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
}
Expand Down
166 changes: 83 additions & 83 deletions tests/cases/standalone/common/alter/alter_table_options.result
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -206,78 +206,78 @@ 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'='';

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;

Expand Down

0 comments on commit 903da8f

Please sign in to comment.