Skip to content

Commit

Permalink
Update hide_options_in_show_create_table to boolean value
Browse files Browse the repository at this point in the history
  • Loading branch information
Ubuntu committed Feb 23, 2023
1 parent 8c1fb13 commit 1048e26
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 36 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 14 additions & 27 deletions src/query/service/src/interpreters/interpreter_table_show_create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::collections::HashSet;
use std::sync::Arc;

use common_exception::Result;
Expand Down Expand Up @@ -119,32 +118,20 @@ impl Interpreter for ShowCreateTableInterpreter {
let settings = self.ctx.get_settings();
let hide_options_in_show_create_table = settings
.get_hide_options_in_show_create_table()
.and_then(|raw_list| {
Ok(raw_list
.split(',')
.map(|x| x.to_string().to_uppercase())
.collect::<HashSet<String>>())
})
.unwrap_or(HashSet::new());

debug!(
"Show hide_options_in_show_create_table: {:?}",
hide_options_in_show_create_table
);

table_create_sql.push_str({
let mut opts = table_info.options().iter().collect::<Vec<_>>();
opts.sort_by_key(|(k, _)| *k);
opts.iter()
.filter(|(k, _)| {
!is_internal_opt_key(k)
&& !hide_options_in_show_create_table.contains(k.to_uppercase().as_str())
})
.map(|(k, v)| format!(" {}='{}'", k.to_uppercase(), v))
.collect::<Vec<_>>()
.join("")
.as_str()
});
.unwrap_or(false);

if !hide_options_in_show_create_table {
table_create_sql.push_str({
let mut opts = table_info.options().iter().collect::<Vec<_>>();
opts.sort_by_key(|(k, _)| *k);
opts.iter()
.filter(|(k, _)| !is_internal_opt_key(k))
.map(|(k, v)| format!(" {}='{}'", k.to_uppercase(), v))
.collect::<Vec<_>>()
.join("")
.as_str()
});
}

let block = DataBlock::new(
vec![
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ DB.Table: 'system'.'settings', Table: settings-table_id:1, ver:0, Engine: System
| "enable_query_result_cache" | "0" | "0" | "SESSION" | "Enable the cache result of each query. It's disabled by default." | "UInt64" |
| "flight_client_timeout" | "60" | "60" | "SESSION" | "Max duration the flight client request is allowed to take in seconds. By default, it is 60 seconds." | "UInt64" |
| "group_by_two_level_threshold" | "10000" | "10000" | "SESSION" | "The threshold of keys to open two-level aggregation, default value: 10000." | "UInt64" |
| "hide_options_in_show_create_table" | "1" | "1" | "SESSION" | "Ignore options while rendering the result of show create table." | "UInt64" |
| "input_read_buffer_size" | "1048576" | "1048576" | "SESSION" | "The size of buffer in bytes for input with format. By default, it is 1MB." | "UInt64" |
| "load_file_metadata_expire_hours" | "168" | "168" | "SESSION" | "How many hours will the COPY file metadata expired in the metasrv, default value: 24*7=7days" | "UInt64" |
| "max_block_size" | "65536" | "65536" | "SESSION" | "Maximum block size for reading, default value: 65536." | "UInt64" |
Expand Down
1 change: 0 additions & 1 deletion src/query/settings/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ common-exception = { path = "../../common/exception" }
common-meta-app = { path = "../../meta/app" }
common-meta-types = { path = "../../meta/types" }
common-users = { path = "../users" }
storages-common-table-meta = { path = "../storages/common/table-meta" }

dashmap = "5.4"
futures = "0.3.24"
Expand Down
13 changes: 6 additions & 7 deletions src/query/settings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ use common_meta_types::MatchSeq;
use common_users::UserApiProvider;
use dashmap::DashMap;
use itertools::Itertools;
use storages_common_table_meta::table::OPT_KEY_SNAPSHOT_LOCATION;

#[derive(Clone)]
pub enum ScopeLevel {
Expand Down Expand Up @@ -439,13 +438,13 @@ impl Settings {
possible_values: None,
},
SettingValue {
default_value: UserSettingValue::String(OPT_KEY_SNAPSHOT_LOCATION.to_string()),
default_value: UserSettingValue::UInt64(1),
user_setting: UserSetting::create(
"hide_options_in_show_create_table",
UserSettingValue::String(OPT_KEY_SNAPSHOT_LOCATION.to_string()),
UserSettingValue::UInt64(1),
),
level: ScopeLevel::Session,
desc: "The list of options that needs to be ignored when executing show create table.",
desc: "Ignore options while rendering the result of show create table.",
possible_values: None,
},
SettingValue {
Expand Down Expand Up @@ -840,10 +839,10 @@ impl Settings {
.and_then(|v| v.user_setting.value.as_string())
}

pub fn get_hide_options_in_show_create_table(&self) -> Result<String> {
pub fn get_hide_options_in_show_create_table(&self) -> Result<bool> {
let key = "hide_options_in_show_create_table";
self.check_and_get_setting_value(key)
.and_then(|v| v.user_setting.value.as_string())
let v = self.try_get_u64(key)?;
Ok(v != 0)
}

pub fn get_enable_query_result_cache(&self) -> Result<bool> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ a CREATE TABLE `a` ( `a` BIGINT, `b` INT DEFAULT 3, `c` VARCHAR DEFAULT 'x
statement ok
CREATE TABLE `test`.`b` ( a bigint, b int null default null, c varchar(255), d smallint unsigned null) Engine = Null COMMENT = 'test b'

query TT
SHOW CREATE TABLE `test`.`b`
----
b CREATE TABLE `b` ( `a` BIGINT, `b` INT NULL DEFAULT NULL, `c` VARCHAR, `d` SMALLINT UNSIGNED NULL ) ENGINE=NULL

statement ok
set hide_options_in_show_create_table=0

query TT
SHOW CREATE TABLE `test`.`b`
----
Expand Down

0 comments on commit 1048e26

Please sign in to comment.