Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support like syntax in show tables statement #331

Merged
merged 42 commits into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
82d5ca4
Show tables statement support like syntax
QuintinTao Oct 21, 2022
5e546e0
Merge branch 'main' into sql-suporting
QuintinTao Oct 21, 2022
c21b904
add supporting for show tables
QuintinTao Oct 21, 2022
7b942ab
Merge branch 'sql-suporting' of https://github.com/QuintinTao/ceresdb…
QuintinTao Oct 21, 2022
ad3bf17
Merge branch 'main' into sql-suporting
QuintinTao Oct 21, 2022
9dc3d7c
modify fmt
QuintinTao Oct 21, 2022
90b7a32
Merge branch 'CeresDB:main' into sql-suporting
QuintinTao Oct 21, 2022
abf7f9d
Merge branch 'sql-suporting' of https://github.com/QuintinTao/ceresdb…
QuintinTao Oct 21, 2022
2065728
Merge branch 'CeresDB:main' into sql-suporting
QuintinTao Oct 22, 2022
7a0c2f7
code fmt modify
QuintinTao Oct 22, 2022
5c9d13e
code fmt modify
QuintinTao Oct 22, 2022
4bb01cb
Merge branch 'CeresDB:main' into sql-suporting
QuintinTao Oct 24, 2022
be74294
Merge branch 'CeresDB:main' into sql-suporting
QuintinTao Oct 24, 2022
bd12a04
reduce show tables param
QuintinTao Oct 24, 2022
314695d
add integration test and regex dependency
QuintinTao Oct 24, 2022
48ad5de
modify test case
QuintinTao Oct 24, 2022
222a0e3
modify test case
QuintinTao Oct 24, 2022
83c6261
modify test case fmt
QuintinTao Oct 25, 2022
cff208f
modify test case fmt
QuintinTao Oct 25, 2022
2c16051
modify test case
QuintinTao Oct 25, 2022
083cd52
modify test case
QuintinTao Oct 25, 2022
2d61f95
modify param name
QuintinTao Oct 26, 2022
65f1a07
modify test case
QuintinTao Oct 26, 2022
b809369
modify test case
QuintinTao Oct 26, 2022
faa45e6
Merge branch 'CeresDB:main' into sql-suporting
QuintinTao Oct 28, 2022
ff18d1b
test result update
QuintinTao Oct 28, 2022
a2854ea
Merge branch 'sql-suporting' of https://github.com/QuintinTao/ceresdb…
QuintinTao Oct 28, 2022
b0686d3
add cargo.lock
QuintinTao Oct 28, 2022
a4381cc
update cargo.lock
QuintinTao Oct 28, 2022
03bdecc
update cargo.lock
QuintinTao Oct 28, 2022
3c55ef3
modify test case result
QuintinTao Oct 28, 2022
054752f
Merge branch 'CeresDB:main' into sql-suporting
QuintinTao Oct 31, 2022
845e3cd
modify test result
QuintinTao Oct 31, 2022
7d3614a
Merge branch 'CeresDB:main' into sql-suporting
QuintinTao Nov 1, 2022
0dac07a
modify test reuslt
QuintinTao Nov 1, 2022
b583abf
Merge branch 'CeresDB:main' into sql-suporting
QuintinTao Nov 2, 2022
52bfa59
modify is_table_matched method and test result
QuintinTao Nov 3, 2022
250abbb
Merge branch 'CeresDB:main' into sql-suporting
QuintinTao Nov 4, 2022
5de3b02
modify is_table_matched and test cases
QuintinTao Nov 4, 2022
b744274
remove type conversion
QuintinTao Nov 8, 2022
e80f843
rollback
QuintinTao Nov 8, 2022
a271371
remove whitespace
QuintinTao Nov 8, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 21 additions & 11 deletions interpreters/src/show.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use sql::{
ast::ShowCreateObject,
plan::{ShowCreatePlan, ShowPlan},
};
use sql::plan::ShowTablesPlan;

use crate::{
context::Context,
Expand Down Expand Up @@ -94,16 +95,25 @@ impl ShowInterpreter {
show_create.execute_show_create()
}

fn show_tables(ctx: Context, catalog_manager: ManagerRef) -> Result<Output> {
fn show_tables(ctx: Context, catalog_manager: ManagerRef,plan: ShowTablesPlan) -> Result<Output> {
let schema = get_default_schema(&ctx, &catalog_manager)?;

let tables_names = schema
.all_tables()
.context(FetchTables)?
.iter()
.map(|t| t.name().to_string())
.collect::<Vec<_>>();

let tables_names = match plan.if_fuzzy {
true => schema
.all_tables()
.context(FetchTables)?
.iter()
.filter(|t| t.name().contains::<&str>(plan.fuzzy_target.as_ref().unwrap().as_ref()))
QuintinTao marked this conversation as resolved.
Show resolved Hide resolved
.map(|t| t.name().to_string())
.collect::<Vec<_>>(),
false =>
schema
.all_tables()
.context(FetchTables)?
.iter()
.map(|t| t.name().to_string())
.collect::<Vec<_>>(),
};
let schema = DataSchema::new(vec![Field::new(
SHOW_TABLES_COLUMN_SCHEMA,
DataType::Utf8,
Expand All @@ -113,7 +123,7 @@ impl ShowInterpreter {
Arc::new(schema),
vec![Arc::new(StringArray::from(tables_names))],
)
.context(CreateRecordBatch)?;
.context(CreateRecordBatch)?;

let record_batch = record_batch.try_into().context(ToCommonRecordType)?;

Expand Down Expand Up @@ -151,8 +161,8 @@ impl Interpreter for ShowInterpreter {
async fn execute(self: Box<Self>) -> InterpreterResult<Output> {
match self.plan {
ShowPlan::ShowCreatePlan(t) => Self::show_create(t).context(ShowCreateTable),
ShowPlan::ShowTables => {
Self::show_tables(self.ctx, self.catalog_manager).context(ShowTables)
ShowPlan::ShowTablesPlan(t) => {
Self::show_tables(self.ctx, self.catalog_manager, t).context(ShowTables)
}
ShowPlan::ShowDatabase => {
Self::show_databases(self.ctx, self.catalog_manager).context(ShowDatabases)
Expand Down
8 changes: 7 additions & 1 deletion sql/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub enum Statement {
/// SHOW CREATE TABLE
ShowCreate(ShowCreate),
ShowDatabases,
ShowTables,
ShowTables(ShowTables),
Exists(ExistsTable),
}

Expand Down Expand Up @@ -96,6 +96,12 @@ pub struct AlterAddColumn {
pub columns: Vec<ColumnDef>,
}

#[derive(Debug, PartialEq, Eq)]
pub struct ShowTables {
pub if_fuzzy: bool,
QuintinTao marked this conversation as resolved.
Show resolved Hide resolved
pub fuzzy_target: Option<String>,
QuintinTao marked this conversation as resolved.
Show resolved Hide resolved
}

#[derive(Debug, PartialEq, Eq)]
pub struct ShowCreate {
pub obj_type: ShowCreateObject,
Expand Down
20 changes: 18 additions & 2 deletions sql/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use table_engine::ANALYTIC_ENGINE_TYPE;

use crate::ast::{
AlterAddColumn, AlterModifySetting, CreateTable, DescribeTable, DropTable, ExistsTable,
ShowCreate, ShowCreateObject, Statement,
ShowCreate, ShowCreateObject, Statement, ShowTables,
};

define_result!(ParserError);
Expand Down Expand Up @@ -223,7 +223,7 @@ impl<'a> Parser<'a> {

pub fn parse_show(&mut self) -> Result<Statement> {
if self.consume_token("TABLES") {
Ok(Statement::ShowTables)
Ok(self.parse_show_tables()?)
} else if self.consume_token("DATABASES") {
Ok(Statement::ShowDatabases)
} else if self.consume_token("CREATE") {
Expand All @@ -233,6 +233,22 @@ impl<'a> Parser<'a> {
}
}

fn parse_show_tables(&mut self) -> Result<Statement> {
let (if_fuzzy, fuzzy_target)= match self.parser.next_token() {
Token::Word(w) =>
match w.keyword {
Keyword::LIKE => (true, Some(self.parser.next_token().to_string())),
_ => (false, None)
},

_ => (false, None),
};
Ok(Statement::ShowTables(ShowTables{
if_fuzzy,
fuzzy_target,
}))
}

fn parse_show_create(&mut self) -> Result<Statement> {
let obj_type = match self.parser.expect_one_of_keywords(&[Keyword::TABLE])? {
Keyword::TABLE => Ok(ShowCreateObject::Table),
Expand Down
8 changes: 7 additions & 1 deletion sql/src/plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,18 @@ pub struct ShowCreatePlan {
pub obj_type: ShowCreateObject,
}

#[derive(Debug, PartialEq, Eq)]
pub struct ShowTablesPlan {
pub if_fuzzy: bool,
pub fuzzy_target: Option<String>,
}

#[derive(Debug)]
pub enum ShowPlan {
/// show create table
ShowCreatePlan(ShowCreatePlan),
/// show tables
ShowTables,
ShowTablesPlan(ShowTablesPlan),
/// show database
ShowDatabase,
}
Expand Down
14 changes: 9 additions & 5 deletions sql/src/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ use table_engine::table::TableRef;
use crate::{
ast::{
AlterAddColumn, AlterModifySetting, CreateTable, DescribeTable, DropTable, ExistsTable,
ShowCreate, Statement, TableName,
ShowCreate, Statement, TableName, ShowTables
},
container::TableReference,
parser,
plan::{
AlterTableOperation, AlterTablePlan, CreateTablePlan, DescribeTablePlan, DropTablePlan,
ExistsTablePlan, InsertPlan, Plan, QueryPlan, ShowCreatePlan, ShowPlan,
ExistsTablePlan, InsertPlan, Plan, QueryPlan, ShowCreatePlan, ShowPlan, ShowTablesPlan,
},
promql::{ColumnNames, Expr as PromExpr},
provider::{ContextProviderAdapter, MetaProvider},
Expand Down Expand Up @@ -246,7 +246,7 @@ impl<'a, P: MetaProvider> Planner<'a, P> {
Statement::AlterModifySetting(s) => planner.alter_modify_setting_to_plan(s),
Statement::AlterAddColumn(s) => planner.alter_add_column_to_plan(s),
Statement::ShowCreate(s) => planner.show_create_to_plan(s),
Statement::ShowTables => planner.show_tables_to_plan(),
Statement::ShowTables(s) => planner.show_tables_to_plan(s),
Statement::ShowDatabases => planner.show_databases_to_plan(),
Statement::Exists(s) => planner.exists_table_to_plan(s),
}
Expand Down Expand Up @@ -598,8 +598,12 @@ impl<'a, P: MetaProvider> PlannerDelegate<'a, P> {
Ok(Plan::Show(ShowPlan::ShowCreatePlan(plan)))
}

fn show_tables_to_plan(&self) -> Result<Plan> {
Ok(Plan::Show(ShowPlan::ShowTables))
fn show_tables_to_plan(&self,show_tables: ShowTables) -> Result<Plan> {
let plan = ShowTablesPlan {
if_fuzzy : show_tables.if_fuzzy,
fuzzy_target: show_tables.fuzzy_target,
};
Ok(Plan::Show(ShowPlan::ShowTablesPlan(plan)))
}

fn show_databases_to_plan(&self) -> Result<Plan> {
Expand Down