Skip to content

Commit 66574ac

Browse files
authored
service: Read only mode add show statements (#40)
* Add support for read only mode show statements * Add support for read only mode show statements test fix
1 parent fc5bd72 commit 66574ac

2 files changed

Lines changed: 39 additions & 1 deletion

File tree

crates/executor/src/query.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,15 @@ impl UserQuery {
288288
Statement::Use(entity) => {
289289
return self.execute_use_statement(entity).await;
290290
}
291+
Statement::ShowDatabases { .. }
292+
| Statement::ShowSchemas { .. }
293+
| Statement::ShowTables { .. }
294+
| Statement::ShowColumns { .. }
295+
| Statement::ShowViews { .. }
296+
| Statement::ShowFunctions { .. }
297+
| Statement::ShowObjects { .. }
298+
| Statement::ShowVariables { .. }
299+
| Statement::ShowVariable { .. } => return Box::pin(self.show_query(*s)).await,
291300
other => {
292301
return ex_error::NotSupportedStatementInReadOnlyModeSnafu {
293302
statement: other.to_string(),
@@ -297,7 +306,17 @@ impl UserQuery {
297306
},
298307
DFStatement::Explain(explain) => match *explain.statement {
299308
DFStatement::Statement(s) => match *s {
300-
Statement::Query(..) | Statement::Use(..) => {
309+
Statement::Query(..)
310+
| Statement::Use(..)
311+
| Statement::ShowDatabases { .. }
312+
| Statement::ShowSchemas { .. }
313+
| Statement::ShowTables { .. }
314+
| Statement::ShowColumns { .. }
315+
| Statement::ShowViews { .. }
316+
| Statement::ShowFunctions { .. }
317+
| Statement::ShowObjects { .. }
318+
| Statement::ShowVariables { .. }
319+
| Statement::ShowVariable { .. } => {
301320
return self.execute_sql(&self.query).await;
302321
}
303322
other => {

crates/executor/src/tests/service.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,4 +562,23 @@ async fn test_execute_read_only_mode() {
562562
)
563563
.await
564564
.expect("Failed to execute query in read only mode");
565+
566+
execution_svc
567+
.query("test_session_id", "SHOW TABLES;", QueryContext::default())
568+
.await
569+
.expect("Failed to execute query in read only mode");
570+
571+
execution_svc
572+
.query("test_session_id", "SHOW SCHEMAS;", QueryContext::default())
573+
.await
574+
.expect("Failed to execute query in read only mode");
575+
576+
execution_svc
577+
.query(
578+
"test_session_id",
579+
"SHOW DATABASES;",
580+
QueryContext::default(),
581+
)
582+
.await
583+
.expect("Failed to execute query in read only mode");
565584
}

0 commit comments

Comments
 (0)