diff --git a/interpreters/src/create.rs b/interpreters/src/create.rs index b015a48308..42528d379d 100644 --- a/interpreters/src/create.rs +++ b/interpreters/src/create.rs @@ -3,45 +3,21 @@ //! Interpreter for create statements use async_trait::async_trait; -use snafu::{Backtrace, ResultExt, Snafu}; +use snafu::{ResultExt, Snafu}; use sql::plan::CreateTablePlan; use table_engine::engine::TableEngineRef; use crate::{ context::Context, interpreter::{Create, Interpreter, InterpreterPtr, Output, Result as InterpreterResult}, - table_creator::TableCreatorRef, + table_manipulator::{self, TableManipulatorRef}, }; #[derive(Debug, Snafu)] #[snafu(visibility(pub(crate)))] pub enum Error { - #[snafu(display("Failed to find catalog, name:{}, err:{}", name, source))] - FindCatalog { - name: String, - source: catalog::manager::Error, - }, - - #[snafu(display("Catalog not exists, name:{}.\nBacktrace:\n{}", name, backtrace))] - CatalogNotExists { name: String, backtrace: Backtrace }, - - #[snafu(display("Failed to find schema, name:{}, err:{}", name, source))] - FindSchema { - name: String, - source: catalog::Error, - }, - - #[snafu(display("Schema not exists, name:{}.\nBacktrace:\n{}", name, backtrace))] - SchemaNotExists { name: String, backtrace: Backtrace }, - - #[snafu(display("Failed to create table, name:{}, err:{}", table, source))] - SchemaCreateTable { - table: String, - source: catalog::schema::Error, - }, - - #[snafu(display("Failed to allocate table id, err:{}", source))] - AllocTableId { source: catalog::schema::Error }, + #[snafu(display("Failed to create table by table manipulator, err:{}", source))] + ManipulateTable { source: table_manipulator::Error }, } define_result!(Error); @@ -51,7 +27,7 @@ pub struct CreateInterpreter { ctx: Context, plan: CreateTablePlan, table_engine: TableEngineRef, - table_creator: TableCreatorRef, + table_manipulator: TableManipulatorRef, } impl CreateInterpreter { @@ -59,22 +35,23 @@ impl CreateInterpreter { ctx: Context, plan: CreateTablePlan, table_engine: TableEngineRef, - table_creator: TableCreatorRef, + table_manipulator: TableManipulatorRef, ) -> InterpreterPtr { Box::new(Self { ctx, plan, table_engine, - table_creator, + table_manipulator, }) } } impl CreateInterpreter { async fn execute_create(self: Box) -> Result { - self.table_creator + self.table_manipulator .create_table(self.ctx, self.plan, self.table_engine) .await + .context(ManipulateTable) } } diff --git a/interpreters/src/drop.rs b/interpreters/src/drop.rs index d5848e13c2..7a84c213b3 100644 --- a/interpreters/src/drop.rs +++ b/interpreters/src/drop.rs @@ -3,48 +3,21 @@ //! Interpreter for drop statements use async_trait::async_trait; -use snafu::{Backtrace, ResultExt, Snafu}; +use snafu::{ResultExt, Snafu}; use sql::plan::DropTablePlan; use table_engine::engine::TableEngineRef; use crate::{ context::Context, interpreter::{Drop, Interpreter, InterpreterPtr, Output, Result as InterpreterResult}, - table_dropper::TableDropperRef, + table_manipulator::{self, TableManipulatorRef}, }; #[derive(Debug, Snafu)] #[snafu(visibility(pub(crate)))] pub enum Error { - #[snafu(display("Failed to find catalog, name:{}, err:{}", name, source))] - FindCatalog { - name: String, - source: catalog::manager::Error, - }, - - #[snafu(display("Catalog not exists, name:{}.\nBacktrace:\n{}", name, backtrace))] - CatalogNotExists { name: String, backtrace: Backtrace }, - - #[snafu(display("Failed to find schema, name:{}, err:{}", name, source))] - FindSchema { - name: String, - source: catalog::Error, - }, - - #[snafu(display("Schema not exists, name:{}.\nBacktrace:\n{}", name, backtrace))] - SchemaNotExists { name: String, backtrace: Backtrace }, - - #[snafu(display("Failed to drop table in schema, name:{}, err:{}", table, source))] - SchemaDropTable { - table: String, - source: catalog::schema::Error, - }, - - #[snafu(display("Failed to drop table, name:{}, err:{}", table, source))] - DropTable { - table: String, - source: table_engine::engine::Error, - }, + #[snafu(display("Failed to drop table by table manipulator, err:{}", source))] + ManipulateTable { source: table_manipulator::Error }, } define_result!(Error); @@ -54,7 +27,7 @@ pub struct DropInterpreter { ctx: Context, plan: DropTablePlan, table_engine: TableEngineRef, - table_dropper: TableDropperRef, + table_manipulator: TableManipulatorRef, } impl DropInterpreter { @@ -62,22 +35,23 @@ impl DropInterpreter { ctx: Context, plan: DropTablePlan, table_engine: TableEngineRef, - table_dropper: TableDropperRef, + table_manipulator: TableManipulatorRef, ) -> InterpreterPtr { Box::new(Self { ctx, plan, table_engine, - table_dropper, + table_manipulator, }) } } impl DropInterpreter { async fn execute_drop(self: Box) -> Result { - self.table_dropper + self.table_manipulator .drop_table(self.ctx, self.plan, self.table_engine) .await + .context(ManipulateTable) } } diff --git a/interpreters/src/factory.rs b/interpreters/src/factory.rs index 42f2c1a8bb..8551b89e07 100644 --- a/interpreters/src/factory.rs +++ b/interpreters/src/factory.rs @@ -11,7 +11,7 @@ use crate::{ alter_table::AlterTableInterpreter, context::Context, create::CreateInterpreter, describe::DescribeInterpreter, drop::DropInterpreter, exists::ExistsInterpreter, insert::InsertInterpreter, interpreter::InterpreterPtr, select::SelectInterpreter, - show::ShowInterpreter, table_creator::TableCreatorRef, table_dropper::TableDropperRef, + show::ShowInterpreter, table_manipulator::TableManipulatorRef, }; /// A factory to create interpreters @@ -19,8 +19,7 @@ pub struct Factory { query_executor: Q, catalog_manager: ManagerRef, table_engine: TableEngineRef, - table_creator: TableCreatorRef, - table_dropper: TableDropperRef, + table_manipulator: TableManipulatorRef, } impl Factory { @@ -28,15 +27,13 @@ impl Factory { query_executor: Q, catalog_manager: ManagerRef, table_engine: TableEngineRef, - table_creator: TableCreatorRef, - table_dropper: TableDropperRef, + table_manipulator: TableManipulatorRef, ) -> Self { Self { query_executor, catalog_manager, table_engine, - table_creator, - table_dropper, + table_manipulator, } } @@ -45,9 +42,11 @@ impl Factory { Plan::Query(p) => SelectInterpreter::create(ctx, p, self.query_executor), Plan::Insert(p) => InsertInterpreter::create(ctx, p), Plan::Create(p) => { - CreateInterpreter::create(ctx, p, self.table_engine, self.table_creator) + CreateInterpreter::create(ctx, p, self.table_engine, self.table_manipulator) + } + Plan::Drop(p) => { + DropInterpreter::create(ctx, p, self.table_engine, self.table_manipulator) } - Plan::Drop(p) => DropInterpreter::create(ctx, p, self.table_engine, self.table_dropper), Plan::Describe(p) => DescribeInterpreter::create(p), Plan::AlterTable(p) => AlterTableInterpreter::create(p), Plan::Show(p) => ShowInterpreter::create(ctx, p, self.catalog_manager), diff --git a/interpreters/src/lib.rs b/interpreters/src/lib.rs index 450be8532a..73306041da 100644 --- a/interpreters/src/lib.rs +++ b/interpreters/src/lib.rs @@ -18,8 +18,7 @@ pub mod insert; pub mod interpreter; pub mod select; pub mod show; -pub mod table_creator; -pub mod table_dropper; +pub mod table_manipulator; mod show_create; diff --git a/interpreters/src/show.rs b/interpreters/src/show.rs index da0426f7da..2eca0520ab 100644 --- a/interpreters/src/show.rs +++ b/interpreters/src/show.rs @@ -17,7 +17,6 @@ use sql::{ use crate::{ context::Context, - create::{CatalogNotExists, FindCatalog, FindSchema, SchemaNotExists}, interpreter::{ Interpreter, InterpreterPtr, Output, Result as InterpreterResult, ShowCreateTable, ShowDatabases, ShowTables, @@ -32,7 +31,7 @@ const SHOW_DATABASES_COLUMN_SCHEMA: &str = "Schemas"; #[snafu(visibility(pub(crate)))] pub enum Error { #[snafu(display( - "Unsupported show create type, type: {:?}, err:{}", + "Unsupported show create type, type:{:?}.\nBacktrace:{}", obj_type, backtrace ))] @@ -58,29 +57,21 @@ pub enum Error { #[snafu(display("Failed to fetch databases, err:{}", source))] FetchDatabases { source: catalog::Error }, + #[snafu(display("Catalog does not exist, catalog:{}.\nBacktrace\n:{}", name, backtrace))] + CatalogNotExists { name: String, backtrace: Backtrace }, + + #[snafu(display("Schema does not exist, schema:{}.\nBacktrace\n:{}", name, backtrace))] + SchemaNotExists { name: String, backtrace: Backtrace }, + #[snafu(display("Failed to fetch catalog, err:{}", source))] - FetchCatalog { source: crate::create::Error }, + FetchCatalog { source: catalog::manager::Error }, #[snafu(display("Failed to fetch schema, err:{}", source))] - FetchSchema { source: crate::create::Error }, - - #[snafu(display("From create::Error, err:{}", source))] - FromCreateError { source: crate::create::Error }, + FetchSchema { source: catalog::Error }, } define_result!(Error); -impl From for Error { - fn from(error: crate::create::Error) -> Self { - use crate::create::Error::*; - match error { - FindCatalog { .. } | CatalogNotExists { .. } => Error::FetchCatalog { source: error }, - FindSchema { .. } | SchemaNotExists { .. } => Error::FetchSchema { source: error }, - other => Error::FromCreateError { source: other }, - } - } -} - pub struct ShowInterpreter { ctx: Context, plan: ShowPlan, @@ -175,15 +166,12 @@ fn get_default_catalog( catalog_manager: &ManagerRef, ) -> Result> { let default_catalog = ctx.default_catalog(); - let catalog = catalog_manager + catalog_manager .catalog_by_name(default_catalog) - .context(FindCatalog { - name: default_catalog, - })? + .context(FetchCatalog)? .context(CatalogNotExists { name: default_catalog, - })?; - Ok(catalog) + }) } fn get_default_schema( @@ -193,13 +181,10 @@ fn get_default_schema( let catalog = get_default_catalog(ctx, catalog_manager)?; let default_schema = ctx.default_schema(); - let schema = catalog + catalog .schema_by_name(default_schema) - .context(FindSchema { - name: default_schema, - })? + .context(FetchSchema)? .context(SchemaNotExists { name: default_schema, - })?; - Ok(schema) + }) } diff --git a/interpreters/src/table_creator/meta_based.rs b/interpreters/src/table_creator/meta_based.rs deleted file mode 100644 index 5fae1fbe41..0000000000 --- a/interpreters/src/table_creator/meta_based.rs +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2022 CeresDB Project Authors. Licensed under Apache-2.0. - -use async_trait::async_trait; -use sql::plan::CreateTablePlan; -use table_engine::engine::TableEngineRef; - -use crate::{context::Context, create::Result, interpreter::Output, table_creator::TableCreator}; - -pub struct TableCreatorImpl {} - -#[async_trait] -impl TableCreator for TableCreatorImpl { - async fn create_table( - &self, - _ctx: Context, - _plan: CreateTablePlan, - _table_engine: TableEngineRef, - ) -> Result { - todo!() - } -} diff --git a/interpreters/src/table_creator/mod.rs b/interpreters/src/table_creator/mod.rs deleted file mode 100644 index eb9a676c38..0000000000 --- a/interpreters/src/table_creator/mod.rs +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright 2022 CeresDB Project Authors. Licensed under Apache-2.0. - -use std::sync::Arc; - -use async_trait::async_trait; -use sql::plan::CreateTablePlan; -use table_engine::engine::TableEngineRef; - -use crate::{context::Context, create::Result, interpreter::Output}; - -pub mod catalog_based; -pub mod meta_based; - -pub type TableCreatorRef = Arc; - -#[async_trait] -pub trait TableCreator { - async fn create_table( - &self, - ctx: Context, - plan: CreateTablePlan, - table_engine: TableEngineRef, - ) -> Result; -} diff --git a/interpreters/src/table_dropper/catalog_based.rs b/interpreters/src/table_dropper/catalog_based.rs deleted file mode 100644 index a9e3349619..0000000000 --- a/interpreters/src/table_dropper/catalog_based.rs +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright 2022 CeresDB Project Authors. Licensed under Apache-2.0. - -use async_trait::async_trait; -use catalog::{ - manager::ManagerRef, - schema::{DropOptions, DropTableRequest}, -}; -use log::warn; -use snafu::{OptionExt, ResultExt}; -use sql::plan::DropTablePlan; -use table_engine::engine::TableEngineRef; - -use crate::{ - context::Context, - drop::{CatalogNotExists, FindCatalog, FindSchema, Result, SchemaDropTable, SchemaNotExists}, - interpreter::Output, - table_dropper::TableDropper, -}; - -pub struct TableDropperImpl { - catalog_manager: ManagerRef, -} - -impl TableDropperImpl { - pub fn new(catalog_manager: ManagerRef) -> Self { - Self { catalog_manager } - } -} - -#[async_trait] -impl TableDropper for TableDropperImpl { - async fn drop_table( - &self, - ctx: Context, - plan: DropTablePlan, - table_engine: TableEngineRef, - ) -> Result { - let default_catalog = ctx.default_catalog(); - let catalog = self - .catalog_manager - .catalog_by_name(default_catalog) - .context(FindCatalog { - name: default_catalog, - })? - .context(CatalogNotExists { - name: default_catalog, - })?; - - let default_schema = ctx.default_schema(); - let schema = catalog - .schema_by_name(default_schema) - .context(FindSchema { - name: default_schema, - })? - .context(SchemaNotExists { - name: default_schema, - })?; - - let table = plan.table; - let request = DropTableRequest { - catalog_name: catalog.name().to_string(), - schema_name: schema.name().to_string(), - schema_id: schema.id(), - table_name: table.clone(), - engine: plan.engine, - }; - - let opts = DropOptions { table_engine }; - - if schema - .drop_table(request, opts) - .await - .context(SchemaDropTable { table: &table })? - { - warn!("Table {} has been dropped already", &table); - } - - Ok(Output::AffectedRows(0)) - } -} diff --git a/interpreters/src/table_dropper/meta_based.rs b/interpreters/src/table_dropper/meta_based.rs deleted file mode 100644 index c535b5a3d9..0000000000 --- a/interpreters/src/table_dropper/meta_based.rs +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2022 CeresDB Project Authors. Licensed under Apache-2.0. - -use async_trait::async_trait; -use sql::plan::DropTablePlan; -use table_engine::engine::TableEngineRef; - -use crate::{context::Context, drop::Result, interpreter::Output, table_dropper::TableDropper}; - -pub struct TableDropperImpl {} - -#[async_trait] -impl TableDropper for TableDropperImpl { - async fn drop_table( - &self, - _ctx: Context, - _plan: DropTablePlan, - _table_engine: TableEngineRef, - ) -> Result { - todo!() - } -} diff --git a/interpreters/src/table_dropper/mod.rs b/interpreters/src/table_dropper/mod.rs deleted file mode 100644 index a560b0ad02..0000000000 --- a/interpreters/src/table_dropper/mod.rs +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright 2022 CeresDB Project Authors. Licensed under Apache-2.0. - -use std::sync::Arc; - -use async_trait::async_trait; -use sql::plan::DropTablePlan; -use table_engine::engine::TableEngineRef; - -use crate::{context::Context, drop::Result, interpreter::Output}; - -pub mod catalog_based; -pub mod meta_based; - -pub type TableDropperRef = Arc; - -#[async_trait] -pub trait TableDropper { - async fn drop_table( - &self, - ctx: Context, - plan: DropTablePlan, - table_engine: TableEngineRef, - ) -> Result; -} diff --git a/interpreters/src/table_creator/catalog_based.rs b/interpreters/src/table_manipulator/catalog_based.rs similarity index 54% rename from interpreters/src/table_creator/catalog_based.rs rename to interpreters/src/table_manipulator/catalog_based.rs index d24e9005c5..95e950999a 100644 --- a/interpreters/src/table_creator/catalog_based.rs +++ b/interpreters/src/table_manipulator/catalog_based.rs @@ -3,33 +3,34 @@ use async_trait::async_trait; use catalog::{ manager::ManagerRef, - schema::{CreateOptions, CreateTableRequest}, + schema::{CreateOptions, CreateTableRequest, DropOptions, DropTableRequest}, }; +use log::warn; use snafu::{OptionExt, ResultExt}; -use sql::plan::CreateTablePlan; +use sql::plan::{CreateTablePlan, DropTablePlan}; use table_engine::engine::{TableEngineRef, TableState}; use crate::{ context::Context, - create::{ - CatalogNotExists, FindCatalog, FindSchema, Result, SchemaCreateTable, SchemaNotExists, - }, interpreter::Output, - table_creator::TableCreator, + table_manipulator::{ + CatalogNotExists, FindCatalog, FindSchema, Result, SchemaCreateTable, SchemaDropTable, + SchemaNotExists, TableManipulator, + }, }; -pub struct TableCreatorImpl { +pub struct TableManipulatorImpl { catalog_manager: ManagerRef, } -impl TableCreatorImpl { +impl TableManipulatorImpl { pub fn new(catalog_manager: ManagerRef) -> Self { Self { catalog_manager } } } #[async_trait] -impl TableCreator for TableCreatorImpl { +impl TableManipulator for TableManipulatorImpl { async fn create_table( &self, ctx: Context, @@ -88,4 +89,53 @@ impl TableCreator for TableCreatorImpl { Ok(Output::AffectedRows(0)) } + + async fn drop_table( + &self, + ctx: Context, + plan: DropTablePlan, + table_engine: TableEngineRef, + ) -> Result { + let default_catalog = ctx.default_catalog(); + let catalog = self + .catalog_manager + .catalog_by_name(default_catalog) + .context(FindCatalog { + name: default_catalog, + })? + .context(CatalogNotExists { + name: default_catalog, + })?; + + let default_schema = ctx.default_schema(); + let schema = catalog + .schema_by_name(default_schema) + .context(FindSchema { + name: default_schema, + })? + .context(SchemaNotExists { + name: default_schema, + })?; + + let table = plan.table; + let request = DropTableRequest { + catalog_name: catalog.name().to_string(), + schema_name: schema.name().to_string(), + schema_id: schema.id(), + table_name: table.clone(), + engine: plan.engine, + }; + + let opts = DropOptions { table_engine }; + + if schema + .drop_table(request, opts) + .await + .context(SchemaDropTable { table: &table })? + { + warn!("Table {} has been dropped already", &table); + } + + Ok(Output::AffectedRows(0)) + } } diff --git a/interpreters/src/table_manipulator/meta_based.rs b/interpreters/src/table_manipulator/meta_based.rs new file mode 100644 index 0000000000..780b68a37b --- /dev/null +++ b/interpreters/src/table_manipulator/meta_based.rs @@ -0,0 +1,34 @@ +// Copyright 2022 CeresDB Project Authors. Licensed under Apache-2.0. + +use async_trait::async_trait; +use sql::plan::{CreateTablePlan, DropTablePlan}; +use table_engine::engine::TableEngineRef; + +use crate::{ + context::Context, + interpreter::Output, + table_manipulator::{Result, TableManipulator}, +}; + +pub struct TableManipulatorImpl {} + +#[async_trait] +impl TableManipulator for TableManipulatorImpl { + async fn create_table( + &self, + _ctx: Context, + _plan: CreateTablePlan, + _table_engine: TableEngineRef, + ) -> Result { + todo!() + } + + async fn drop_table( + &self, + _ctx: Context, + _plan: DropTablePlan, + _table_engine: TableEngineRef, + ) -> Result { + todo!() + } +} diff --git a/interpreters/src/table_manipulator/mod.rs b/interpreters/src/table_manipulator/mod.rs new file mode 100644 index 0000000000..2e30f99f96 --- /dev/null +++ b/interpreters/src/table_manipulator/mod.rs @@ -0,0 +1,74 @@ +// Copyright 2022 CeresDB Project Authors. Licensed under Apache-2.0. + +use std::sync::Arc; + +use async_trait::async_trait; +use snafu::{Backtrace, Snafu}; +use sql::plan::{CreateTablePlan, DropTablePlan}; +use table_engine::engine::TableEngineRef; + +use crate::{context::Context, interpreter::Output}; + +pub mod catalog_based; +pub mod meta_based; + +pub type TableManipulatorRef = Arc; + +#[derive(Debug, Snafu)] +#[snafu(visibility(pub(crate)))] +pub enum Error { + #[snafu(display("Failed to find catalog, name:{}, err:{}", name, source))] + FindCatalog { + name: String, + source: catalog::manager::Error, + }, + + #[snafu(display("Catalog not exists, name:{}.\nBacktrace:\n{}", name, backtrace))] + CatalogNotExists { name: String, backtrace: Backtrace }, + + #[snafu(display("Failed to find schema, name:{}, err:{}", name, source))] + FindSchema { + name: String, + source: catalog::Error, + }, + + #[snafu(display("Schema not exists, name:{}.\nBacktrace:\n{}", name, backtrace))] + SchemaNotExists { name: String, backtrace: Backtrace }, + + #[snafu(display("Failed to create table, name:{}, err:{}", table, source))] + SchemaCreateTable { + table: String, + source: catalog::schema::Error, + }, + + #[snafu(display("Failed to drop table in schema, name:{}, err:{}", table, source))] + SchemaDropTable { + table: String, + source: catalog::schema::Error, + }, + + #[snafu(display("Failed to drop table, name:{}, err:{}", table, source))] + DropTable { + table: String, + source: table_engine::engine::Error, + }, +} + +define_result!(Error); + +#[async_trait] +pub trait TableManipulator { + async fn create_table( + &self, + ctx: Context, + plan: CreateTablePlan, + table_engine: TableEngineRef, + ) -> Result; + + async fn drop_table( + &self, + ctx: Context, + plan: DropTablePlan, + table_engine: TableEngineRef, + ) -> Result; +} diff --git a/interpreters/src/tests.rs b/interpreters/src/tests.rs index 33b0de67ce..636b310753 100644 --- a/interpreters/src/tests.rs +++ b/interpreters/src/tests.rs @@ -19,8 +19,7 @@ use crate::{ context::Context, factory::Factory, interpreter::{Output, Result}, - table_creator::catalog_based::TableCreatorImpl, - table_dropper::catalog_based::TableDropperImpl, + table_manipulator::catalog_based::TableManipulatorImpl, }; async fn build_catalog_manager(analytic: TableEngineRef) -> TableBasedManager { @@ -60,14 +59,12 @@ where { async fn build_factory(&self) -> Factory { let catalog_manager = Arc::new(build_catalog_manager(self.engine()).await); - let table_creator = Arc::new(TableCreatorImpl::new(catalog_manager.clone())); - let table_dropper = Arc::new(TableDropperImpl::new(catalog_manager.clone())); + let table_manipulator = Arc::new(TableManipulatorImpl::new(catalog_manager.clone())); Factory::new( ExecutorImpl::new(query_engine::Config::default()), catalog_manager, self.engine(), - table_creator, - table_dropper, + table_manipulator, ) } @@ -139,14 +136,12 @@ where let ctx = Context::builder(RequestId::next_id()) .default_catalog_and_schema(DEFAULT_CATALOG.to_string(), DEFAULT_SCHEMA.to_string()) .build(); - let table_creator = Arc::new(TableCreatorImpl::new(catalog_manager.clone())); - let table_dropper = Arc::new(TableDropperImpl::new(catalog_manager.clone())); + let table_manipulator = Arc::new(TableManipulatorImpl::new(catalog_manager.clone())); let insert_factory = Factory::new( ExecutorImpl::new(QueryConfig::default()), catalog_manager.clone(), self.engine(), - table_creator.clone(), - table_dropper.clone(), + table_manipulator.clone(), ); let insert_sql = "INSERT INTO test_missing_columns_table(key1, key2, field4) VALUES('tagk', 1638428434000, 1), ('tagk2', 1638428434000, 10);"; @@ -165,8 +160,7 @@ where ExecutorImpl::new(QueryConfig::default()), catalog_manager, self.engine(), - table_creator, - table_dropper, + table_manipulator, ); let ctx = Context::builder(RequestId::next_id()) .default_catalog_and_schema(DEFAULT_CATALOG.to_string(), DEFAULT_SCHEMA.to_string()) diff --git a/server/src/grpc/prom_query.rs b/server/src/grpc/prom_query.rs index 32a1cce82c..12a7908609 100644 --- a/server/src/grpc/prom_query.rs +++ b/server/src/grpc/prom_query.rs @@ -107,8 +107,7 @@ where instance.query_executor.clone(), instance.catalog_manager.clone(), instance.table_engine.clone(), - instance.table_creator.clone(), - instance.table_dropper.clone(), + instance.table_manipulator.clone(), ); let interpreter = interpreter_factory.create(interpreter_ctx, plan); diff --git a/server/src/grpc/query.rs b/server/src/grpc/query.rs index 26c1c29f19..e57a912f0d 100644 --- a/server/src/grpc/query.rs +++ b/server/src/grpc/query.rs @@ -143,8 +143,7 @@ pub async fn fetch_query_output( instance.query_executor.clone(), instance.catalog_manager.clone(), instance.table_engine.clone(), - instance.table_creator.clone(), - instance.table_dropper.clone(), + instance.table_manipulator.clone(), ); let interpreter = interpreter_factory.create(interpreter_ctx, plan); diff --git a/server/src/grpc/write.rs b/server/src/grpc/write.rs index 56d8001ad3..e4d2f6941b 100644 --- a/server/src/grpc/write.rs +++ b/server/src/grpc/write.rs @@ -71,8 +71,7 @@ pub(crate) async fn handle_write( instance.query_executor.clone(), instance.catalog_manager.clone(), instance.table_engine.clone(), - instance.table_creator.clone(), - instance.table_dropper.clone(), + instance.table_manipulator.clone(), ); let interpreter = interpreter_factory.create(interpreter_ctx, plan); @@ -223,8 +222,7 @@ async fn create_table( instance.query_executor.clone(), instance.catalog_manager.clone(), instance.table_engine.clone(), - instance.table_creator.clone(), - instance.table_dropper.clone(), + instance.table_manipulator.clone(), ); let interpreter = interpreter_factory.create(interpreter_ctx, plan); diff --git a/server/src/handlers/sql.rs b/server/src/handlers/sql.rs index 560b21ecff..e0105dbbcb 100644 --- a/server/src/handlers/sql.rs +++ b/server/src/handlers/sql.rs @@ -166,8 +166,7 @@ pub async fn handle_sql( instance.query_executor.clone(), instance.catalog_manager.clone(), instance.table_engine.clone(), - instance.table_creator.clone(), - instance.table_dropper.clone(), + instance.table_manipulator.clone(), ); let interpreter = interpreter_factory.create(interpreter_ctx, plan); diff --git a/server/src/instance.rs b/server/src/instance.rs index 810c09ce1e..5044a29e0b 100644 --- a/server/src/instance.rs +++ b/server/src/instance.rs @@ -6,7 +6,7 @@ use std::sync::Arc; use catalog::manager::ManagerRef; use df_operator::registry::FunctionRegistryRef; -use interpreters::{table_creator::TableCreatorRef, table_dropper::TableDropperRef}; +use interpreters::table_manipulator::TableManipulatorRef; use table_engine::engine::TableEngineRef; use crate::limiter::Limiter; @@ -21,8 +21,7 @@ pub struct Instance { // User defined functions registry. pub function_registry: FunctionRegistryRef, pub limiter: Limiter, - pub table_creator: TableCreatorRef, - pub table_dropper: TableDropperRef, + pub table_manipulator: TableManipulatorRef, } /// A reference counted instance pointer diff --git a/server/src/server.rs b/server/src/server.rs index 268d2b7075..fa5653fd01 100644 --- a/server/src/server.rs +++ b/server/src/server.rs @@ -7,7 +7,7 @@ use std::sync::Arc; use catalog::manager::ManagerRef; use cluster::ClusterRef; use df_operator::registry::FunctionRegistryRef; -use interpreters::{table_creator, table_dropper}; +use interpreters::table_manipulator::catalog_based; use log::warn; use query_engine::executor::Executor as QueryExecutor; use snafu::{Backtrace, OptionExt, ResultExt, Snafu}; @@ -221,10 +221,7 @@ impl Builder { let function_registry = self.function_registry.context(MissingFunctionRegistry)?; let instance = { - let creator = Arc::new(table_creator::catalog_based::TableCreatorImpl::new( - catalog_manager.clone(), - )); - let dropper = Arc::new(table_dropper::catalog_based::TableDropperImpl::new( + let table_manipulator = Arc::new(catalog_based::TableManipulatorImpl::new( catalog_manager.clone(), )); let instance = Instance { @@ -233,8 +230,7 @@ impl Builder { table_engine, function_registry, limiter: self.limiter, - table_creator: creator, - table_dropper: dropper, + table_manipulator, }; InstanceRef::new(instance) };