Skip to content

Commit

Permalink
Merge pull request #6394 from TCeason/ISSUE-6364/support_show_setting…
Browse files Browse the repository at this point in the history
…s_like

feat: show settings support like
  • Loading branch information
leiysky authored Jul 1, 2022
2 parents bff565e + 8279794 commit 51bb970
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 7 deletions.
2 changes: 1 addition & 1 deletion common/ast/src/ast/statements/show.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub enum ShowLimit<'a> {
impl<'a> Display for ShowLimit<'a> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
ShowLimit::Like { pattern } => write!(f, "LIKE {pattern}"),
ShowLimit::Like { pattern } => write!(f, "LIKE '{pattern}'"),
ShowLimit::Where { selection } => write!(f, "WHERE {selection}"),
}
}
Expand Down
11 changes: 9 additions & 2 deletions common/ast/src/ast/statements/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ pub enum Statement<'a> {
Copy(CopyStmt<'a>),
Call(CallStmt),

ShowSettings,
ShowSettings {
like: Option<String>,
},
ShowProcessList,
ShowMetrics,
ShowFunctions {
Expand Down Expand Up @@ -186,7 +188,12 @@ impl<'a> Display for Statement<'a> {
}
}
Statement::Copy(stmt) => write!(f, "{stmt}")?,
Statement::ShowSettings => {}
Statement::ShowSettings { like } => {
write!(f, "SHOW SETTINGS")?;
if like.is_some() {
write!(f, " LIKE '{}'", like.as_ref().unwrap())?;
}
}
Statement::ShowProcessList => write!(f, "SHOW PROCESSLIST")?,
Statement::ShowMetrics => write!(f, "SHOW METRICS")?,
Statement::ShowFunctions { limit } => {
Expand Down
11 changes: 9 additions & 2 deletions common/ast/src/parser/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,14 @@ pub fn statement(i: Input) -> IResult<StatementMsg> {
selection: opt_where_block.map(|(_, selection)| selection),
},
);
let show_settings = value(Statement::ShowSettings, rule! { SHOW ~ SETTINGS });
let show_settings = map(
rule! {
SHOW ~ SETTINGS ~ (LIKE ~ #literal_string)?
},
|(_, _, opt_like)| Statement::ShowSettings {
like: opt_like.map(|(_, like)| like),
},
);
let show_stages = value(Statement::ShowStages, rule! { SHOW ~ STAGES });
let show_process_list = value(Statement::ShowProcessList, rule! { SHOW ~ PROCESSLIST });
let show_metrics = value(Statement::ShowMetrics, rule! { SHOW ~ METRICS });
Expand Down Expand Up @@ -689,7 +696,7 @@ pub fn statement(i: Input) -> IResult<StatementMsg> {
| #explain : "`EXPLAIN [PIPELINE | GRAPH] <statement>`"
| #insert : "`INSERT INTO [TABLE] <table> [(<column>, ...)] (FORMAT <format> | VALUES <values> | <query>)`"
| #delete : "`DELETE FROM <table> [WHERE ...]`"
| #show_settings : "`SHOW SETTINGS`"
| #show_settings : "`SHOW SETTINGS [<show_limit>]`"
| #show_stages : "`SHOW STAGES`"
| #show_process_list : "`SHOW PROCESSLIST`"
| #show_metrics : "`SHOW METRICS`"
Expand Down
2 changes: 2 additions & 0 deletions common/ast/tests/it/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ fn test_statement() {
size_limit=10;"#,
r#"CALL system$test(a)"#,
r#"CALL system$test('a')"#,
r#"show settings like 'enable%'"#,
];

for case in cases {
Expand Down Expand Up @@ -264,6 +265,7 @@ fn test_statement_error() {
r#"COPY INTO mytable FROM @mystage CREDENTIALS = ();"#,
r#"CALL system$test"#,
r#"CALL system$test(a"#,
r#"show settings ilike 'enable%'"#,
];

for case in cases {
Expand Down
10 changes: 10 additions & 0 deletions common/ast/tests/it/testdata/statement-error.txt
Original file line number Diff line number Diff line change
Expand Up @@ -304,3 +304,13 @@ error:
| while parsing `CALL <procedure_name>(<parameter>, ...)`


---------- Input ----------
show settings ilike 'enable%'
---------- Output ---------
error:
--> SQL:1:15
|
1 | show settings ilike 'enable%'
| ^^^^^ expected `LIKE`, `FORMAT`, or `;`


12 changes: 12 additions & 0 deletions common/ast/tests/it/testdata/statement.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4755,3 +4755,15 @@ Call(
)


---------- Input ----------
show settings like 'enable%'
---------- Output ---------
SHOW SETTINGS LIKE 'enable%'
---------- AST ------------
ShowSettings {
like: Some(
"enable%",
),
}


2 changes: 1 addition & 1 deletion query/src/sql/planner/binder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl<'a> Binder {

Statement::ShowMetrics => Plan::ShowMetrics,
Statement::ShowProcessList => Plan::ShowProcessList,
Statement::ShowSettings => Plan::ShowSettings,
Statement::ShowSettings { like } => self.bind_show_settings(bind_context, like).await?,

// Databases
Statement::ShowDatabases(stmt) => self.bind_show_databases(stmt).await?,
Expand Down
19 changes: 18 additions & 1 deletion query/src/sql/planner/binder/show.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::sql::BindContext;
use crate::sql::Binder;

impl<'a> Binder {
pub(super) async fn bind_show_functions(
pub(in crate::sql::planner::binder) async fn bind_show_functions(
&mut self,
bind_context: &BindContext,
limit: &Option<ShowLimit<'a>>,
Expand Down Expand Up @@ -51,4 +51,21 @@ impl<'a> Binder {
let (stmt, _) = parse_sql(&tokens, &backtrace)?;
self.bind_statement(bind_context, &stmt).await
}

pub(in crate::sql::planner::binder) async fn bind_show_settings(
&mut self,
bind_context: &BindContext,
like: &Option<String>,
) -> Result<Plan> {
let sub_query = like
.clone()
.map(|s| format!("WHERE name LIKE '{s}'"))
.unwrap_or_else(|| "".to_string());
let query = format!("SELECT name, value, default, level, description, type FROM system.settings {} ORDER BY name", sub_query);

let tokens = tokenize_sql(query.as_str())?;
let backtrace = Backtrace::new();
let (stmt, _) = parse_sql(&tokens, &backtrace)?;
self.bind_statement(bind_context, &stmt).await
}
}
19 changes: 19 additions & 0 deletions tests/suites/0_stateless/06_show/06_0003_show_settings_v2.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
compression None None SESSION Format compression, default value: None String
empty_as_default 1 1 SESSION Format empty_as_default, default value: 1 UInt64
enable_async_insert 0 0 SESSION Whether the client open async insert mode, default value: 0 UInt64
enable_new_processor_framework 1 1 SESSION Enable new processor framework if value != 0, default value: 1 UInt64
enable_planner_v2 1 0 SESSION Enable planner v2 by setting this variable to 1, default value: 0 UInt64
field_delimiter , , SESSION Format field delimiter, default value: , String
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
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
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
wait_for_async_insert 1 1 SESSION Whether the client wait for the reply of async insert, default value: 1 UInt64
wait_for_async_insert_timeout 100 100 SESSION The timeout in seconds for waiting for processing of async insert, default value: 100 UInt64
enable_async_insert 0 0 SESSION Whether the client open async insert mode, default value: 0 UInt64
enable_new_processor_framework 1 1 SESSION Enable new processor framework if value != 0, default value: 1 UInt64
enable_planner_v2 1 0 SESSION Enable planner v2 by setting this variable to 1, default value: 0 UInt64
6 changes: 6 additions & 0 deletions tests/suites/0_stateless/06_show/06_0003_show_settings_v2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SET enable_planner_v2=1;
SET max_threads=11;
SET unknown_settings=11; -- {ErrorCode 2801}
SHOW SETTINGS;
SHOW SETTINGS LIKE 'enable%';
SET enable_planner_v2=0;

0 comments on commit 51bb970

Please sign in to comment.