Skip to content

Commit

Permalink
Merge pull request #10164 from xinlifoobar/users/xinli1/hide_options
Browse files Browse the repository at this point in the history
feat(query): not show SNAPSHOT_LOCATION when show create table
  • Loading branch information
BohuTANG authored Feb 23, 2023
2 parents b30926f + ab190d9 commit 14377c2
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 11 deletions.
27 changes: 17 additions & 10 deletions src/query/service/src/interpreters/interpreter_table_show_create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,23 @@ impl Interpreter for ShowCreateTableInterpreter {
table_create_sql.push_str(format!(" CLUSTER BY {}", cluster_keys_str).as_str());
}

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 settings = self.ctx.get_settings();
let hide_options_in_show_create_table = settings
.get_hide_options_in_show_create_table()
.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" | "20000" | "20000" | "SESSION" | "The threshold of keys to open two-level aggregation, default value: 20000." | "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
16 changes: 16 additions & 0 deletions src/query/settings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,16 @@ impl Settings {
desc: "How many hours will the COPY file metadata expired in the metasrv, default value: 24*7=7days",
possible_values: None,
},
SettingValue {
default_value: UserSettingValue::UInt64(1),
user_setting: UserSetting::create(
"hide_options_in_show_create_table",
UserSettingValue::UInt64(1),
),
level: ScopeLevel::Session,
desc: "Ignore options while rendering the result of show create table.",
possible_values: None,
},
SettingValue {
default_value: UserSettingValue::String("".to_string()),
user_setting: UserSetting::create(
Expand Down Expand Up @@ -839,6 +849,12 @@ impl Settings {
.and_then(|v| v.user_setting.value.as_string())
}

pub fn get_hide_options_in_show_create_table(&self) -> Result<bool> {
let key = "hide_options_in_show_create_table";
let v = self.try_get_u64(key)?;
Ok(v != 0)
}

pub fn get_enable_query_result_cache(&self) -> Result<bool> {
let key = "enable_query_result_cache";
self.try_get_u64(key).map(|v| v != 0)
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ String
t2
Table Create Table
String String
t2 CREATE TABLE `t2` (\n `a` INT\n) ENGINE=FUSE COMPRESSION=\'zstd\' STORAGE_FORMAT=\'parquet\'
t2 CREATE TABLE `t2` (\n `a` INT\n) ENGINE=FUSE
Field Type Null Default Extra
String String String String String
a INT NO 0
Expand Down

1 comment on commit 14377c2

@vercel
Copy link

@vercel vercel bot commented on 14377c2 Feb 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

databend – ./

databend-databend.vercel.app
databend.vercel.app
databend-git-main-databend.vercel.app
databend.rs

Please sign in to comment.