From 75da747a9d8cd619ff10cb17a9ad8f2759321e79 Mon Sep 17 00:00:00 2001 From: Veeupup Date: Mon, 4 Jul 2022 00:44:43 +0800 Subject: [PATCH 1/2] improvement: escape record_delimiter when displaying Signed-off-by: Veeupup --- Cargo.lock | 17 +++++++++++++++++ query/Cargo.toml | 1 + query/src/sessions/session_settings.rs | 2 +- query/src/storages/system/settings_table.rs | 5 +++-- .../tests/it/storages/system/settings_table.rs | 3 +-- 5 files changed, 23 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 08122043f75f..e628d226db14 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2093,6 +2093,7 @@ dependencies = [ "sha1", "sha2 0.10.2", "smallvec", + "snailquote", "sqlparser", "strum", "strum_macros", @@ -6290,6 +6291,16 @@ dependencies = [ "syn", ] +[[package]] +name = "snailquote" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec62a949bda7f15800481a711909f946e1204f2460f89210eaf7f57730f88f86" +dependencies = [ + "thiserror", + "unicode_categories", +] + [[package]] name = "snap" version = "1.0.5" @@ -7199,6 +7210,12 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "957e51f3646910546462e67d5f7599b9e4fb8acdd304b087a6494730f9eebf04" +[[package]] +name = "unicode_categories" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39ec24b3121d976906ece63c9daad25b85969647682eee313cb5779fdd69e14e" + [[package]] name = "untrusted" version = "0.7.1" diff --git a/query/Cargo.toml b/query/Cargo.toml index b40ec4af60ac..d841fedb8391 100644 --- a/query/Cargo.toml +++ b/query/Cargo.toml @@ -114,6 +114,7 @@ serfig = "0.0.2" sha1 = "0.10.1" sha2 = "0.10.2" smallvec = { version = "1.8.0", features = ["write"] } +snailquote = "0.3.1" strum = "0.24.1" strum_macros = "0.24.0" tempfile = { version = "3.3.0", optional = true } diff --git a/query/src/sessions/session_settings.rs b/query/src/sessions/session_settings.rs index 16367ef8346c..fd024267ecc8 100644 --- a/query/src/sessions/session_settings.rs +++ b/query/src/sessions/session_settings.rs @@ -113,7 +113,7 @@ impl Settings { default_value: DataValue::String("\n".as_bytes().to_vec()), user_setting: UserSetting::create("record_delimiter", DataValue::String("\n".as_bytes().to_vec())), level: ScopeLevel::Session, - desc: "Format record_delimiter, default value: \n", + desc: "Format record_delimiter, default value: \"\\n\"", }, SettingValue { default_value: DataValue::String(",".as_bytes().to_vec()), diff --git a/query/src/storages/system/settings_table.rs b/query/src/storages/system/settings_table.rs index 1f97952fe759..8c4ad4c6ca6d 100644 --- a/query/src/storages/system/settings_table.rs +++ b/query/src/storages/system/settings_table.rs @@ -20,6 +20,7 @@ use common_exception::Result; use common_meta_app::schema::TableIdent; use common_meta_app::schema::TableInfo; use common_meta_app::schema::TableMeta; +use snailquote::escape; use crate::sessions::QueryContext; use crate::storages::system::table::SyncOneBlockSystemTable; @@ -51,9 +52,9 @@ impl SyncSystemTable for SettingsTable { // Name. names.push(format!("{:?}", vals[0])); // Value. - values.push(format!("{:?}", vals[1])); + values.push(escape(format!("{:?}", vals[1]).as_str()).to_string()); // Default Value. - defaults.push(format!("{:?}", vals[2])); + defaults.push(escape(format!("{:?}", vals[2]).as_str()).to_string()); // Scope level. levels.push(format!("{:?}", vals[3])); // Desc. diff --git a/query/tests/it/storages/system/settings_table.rs b/query/tests/it/storages/system/settings_table.rs index e4e6a77c1884..aab0b15f6f33 100644 --- a/query/tests/it/storages/system/settings_table.rs +++ b/query/tests/it/storages/system/settings_table.rs @@ -33,7 +33,6 @@ async fn test_settings_table() -> Result<()> { "+--------------------------------+---------+---------+---------+----------------------------------------------------------------------------------------------------+--------+", "| name | value | default | level | description | type |", "+--------------------------------+---------+---------+---------+----------------------------------------------------------------------------------------------------+--------+", - "| | | | | | |", "| enable_async_insert | 0 | 0 | SESSION | Whether the client open async insert mode, default value: 0 | UInt64 |", "| compression | None | None | SESSION | Format compression, default value: None | String |", "| empty_as_default | 1 | 1 | SESSION | Format empty_as_default, default value: 1 | UInt64 |", @@ -44,7 +43,7 @@ async fn test_settings_table() -> Result<()> { "| group_by_two_level_threshold | 10000 | 10000 | SESSION | The threshold of keys to open two-level aggregation, default value: 10000 | UInt64 |", "| max_block_size | 10000 | 10000 | SESSION | Maximum block size for reading | UInt64 |", "| max_threads | 2 | 16 | SESSION | The maximum number of threads to execute the request. By default, it is determined automatically. | UInt64 |", - "| record_delimiter | | | SESSION | Format record_delimiter, default value: | String |", + "| record_delimiter | \"\\n\" | \"\\n\" | SESSION | Format record_delimiter, default value: \"\\n\" | String |", "| skip_header | 0 | 0 | SESSION | Whether to skip the input header, default value: 0 | UInt64 |", "| storage_read_buffer_size | 1048576 | 1048576 | SESSION | The size of buffer in bytes for buffered reader of dal. By default, it is 1MB. | UInt64 |", "| timezone | UTC | UTC | SESSION | Timezone, default value: UTC, | String |", From e833db1fdc0f62704bb387ffd7c9aa96554544cd Mon Sep 17 00:00:00 2001 From: Veeupup Date: Mon, 4 Jul 2022 12:46:29 +0800 Subject: [PATCH 2/2] fix test Signed-off-by: Veeupup --- tests/suites/0_stateless/06_show/06_0003_show_settings.result | 2 +- .../suites/0_stateless/06_show/06_0003_show_settings_v2.result | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/suites/0_stateless/06_show/06_0003_show_settings.result b/tests/suites/0_stateless/06_show/06_0003_show_settings.result index ebc10ea19418..90a24477129f 100644 --- a/tests/suites/0_stateless/06_show/06_0003_show_settings.result +++ b/tests/suites/0_stateless/06_show/06_0003_show_settings.result @@ -8,7 +8,7 @@ flight_client_timeout 60 60 SESSION Max duration the flight client request is al group_by_two_level_threshold 10000 10000 SESSION The threshold of keys to open two-level aggregation, default value: 10000 UInt64 max_block_size 10000 10000 SESSION Maximum block size for reading UInt64 max_threads 11 16 SESSION The maximum number of threads to execute the request. By default, it is determined automatically. UInt64 -record_delimiter \n \n SESSION Format record_delimiter, default value: \n String +record_delimiter "\\n" "\\n" SESSION Format record_delimiter, default value: "\\n" String skip_header 0 0 SESSION Whether to skip the input header, default value: 0 UInt64 storage_read_buffer_size 1048576 1048576 SESSION The size of buffer in bytes for buffered reader of dal. By default, it is 1MB. UInt64 timezone UTC UTC SESSION Timezone, default value: UTC, String diff --git a/tests/suites/0_stateless/06_show/06_0003_show_settings_v2.result b/tests/suites/0_stateless/06_show/06_0003_show_settings_v2.result index 0e4081fdbdfe..97dca5fbbe62 100644 --- a/tests/suites/0_stateless/06_show/06_0003_show_settings_v2.result +++ b/tests/suites/0_stateless/06_show/06_0003_show_settings_v2.result @@ -8,7 +8,7 @@ flight_client_timeout 60 60 SESSION Max duration the flight client request is al group_by_two_level_threshold 10000 10000 SESSION The threshold of keys to open two-level aggregation, default value: 10000 UInt64 max_block_size 10000 10000 SESSION Maximum block size for reading UInt64 max_threads 11 16 SESSION The maximum number of threads to execute the request. By default, it is determined automatically. UInt64 -record_delimiter \n \n SESSION Format record_delimiter, default value: \n String +record_delimiter "\\n" "\\n" SESSION Format record_delimiter, default value: "\\n" String skip_header 0 0 SESSION Whether to skip the input header, default value: 0 UInt64 storage_read_buffer_size 1048576 1048576 SESSION The size of buffer in bytes for buffered reader of dal. By default, it is 1MB. UInt64 timezone UTC UTC SESSION Timezone, default value: UTC, String