-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add 'show tables' functionality in SQL executor (#61)
* feat: Add 'show tables' functionality in SQL executor This commit introduces 'show tables' feature, allowing users to display table names in the database. Necessary changes were made in the execution module, database, binder, and storage to facilitate this feature. This includes addition of `ShowTables` struct and implementing the `Executor` trait for it, modifications in `Binder` to create a logical plan for 'show tables' commands, and adding `show_tables` function in storage to return a list of existing table names. Additionally, a 'ShowTablesOperator' was added in operator module to support operation, and new test cases were added to validate the modifications. * Remove hardcoded table insertions in table_codec.rs * feat(executor): add column count to `show_tables` function Functions `show_tables` in the Storage trait and its implementations in Kip and Memory now return a tuple containing table name and column count. The functions `encode_root_table` and `decode_root_table` in table_codec have been updated for the new format. These changes improve utility of `show_tables` by providing more detailed information.
- Loading branch information
Showing
13 changed files
with
223 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use crate::binder::{Binder, BindError}; | ||
use crate::planner::LogicalPlan; | ||
use crate::planner::operator::Operator; | ||
use crate::planner::operator::show::ShowTablesOperator; | ||
use crate::storage::Storage; | ||
|
||
impl<S: Storage> Binder<S> { | ||
pub(crate) fn bind_show_tables( | ||
&mut self, | ||
) -> Result<LogicalPlan, BindError> { | ||
let plan = LogicalPlan { | ||
operator: Operator::Show( | ||
ShowTablesOperator {} | ||
), | ||
childrens: vec![], | ||
}; | ||
Ok(plan) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
pub(crate) mod show_table; | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use futures_async_stream::try_stream; | ||
use crate::execution::executor::{BoxedExecutor, Executor}; | ||
use crate::execution::ExecutorError; | ||
use crate::planner::operator::show::ShowTablesOperator; | ||
use crate::storage::Storage; | ||
use crate::types::tuple::Tuple; | ||
use crate::catalog::ColumnCatalog; | ||
use crate::catalog::ColumnRef; | ||
use std::sync::Arc; | ||
use crate::types::value::{DataValue, ValueRef}; | ||
|
||
pub struct ShowTables { | ||
op: ShowTablesOperator, | ||
} | ||
|
||
impl From<ShowTablesOperator> for ShowTables { | ||
fn from(op: ShowTablesOperator) -> Self { | ||
ShowTables { | ||
op | ||
} | ||
} | ||
} | ||
|
||
impl<S: Storage> Executor<S> for ShowTables { | ||
fn execute(self, storage: &S) -> BoxedExecutor { | ||
self._execute(storage.clone()) | ||
} | ||
} | ||
|
||
impl ShowTables { | ||
#[try_stream(boxed, ok = Tuple, error = ExecutorError)] | ||
pub async fn _execute<S: Storage>(self, storage: S) { | ||
if let Some(tables) = storage.show_tables().await { | ||
for (table,column_count) in tables { | ||
let columns: Vec<ColumnRef> = vec![ | ||
Arc::new(ColumnCatalog::new_dummy("TABLES".to_string())), | ||
Arc::new(ColumnCatalog::new_dummy("COLUMN_COUNT".to_string())), | ||
]; | ||
let values: Vec<ValueRef> = vec![ | ||
Arc::new(DataValue::Utf8(Some(table))), | ||
Arc::new(DataValue::UInt32(Some(column_count as u32))), | ||
]; | ||
|
||
yield Tuple { | ||
id: None, | ||
columns, | ||
values, | ||
}; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#[derive(Debug, PartialEq, Clone)] | ||
pub struct ShowTablesOperator {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters