From 5532fa6c0d4aa5636cfb7123285a62788f70ae65 Mon Sep 17 00:00:00 2001 From: Liang-Chi Hsieh Date: Sun, 7 Nov 2021 20:31:02 -0800 Subject: [PATCH 1/5] Add drop table support. --- datafusion/src/execution/context.rs | 13 ++++++++++++ datafusion/src/logical_plan/plan.rs | 21 +++++++++++++++++-- .../src/optimizer/common_subexpr_eliminate.rs | 1 + datafusion/src/optimizer/constant_folding.rs | 1 + .../src/optimizer/projection_push_down.rs | 1 + datafusion/src/optimizer/utils.rs | 7 +++++++ datafusion/src/physical_plan/planner.rs | 4 ++-- datafusion/src/sql/planner.rs | 19 ++++++++++++++--- datafusion/tests/sql.rs | 17 +++++++++++++++ 9 files changed, 77 insertions(+), 7 deletions(-) diff --git a/datafusion/src/execution/context.rs b/datafusion/src/execution/context.rs index 6295184208ff..059bd71246b5 100644 --- a/datafusion/src/execution/context.rs +++ b/datafusion/src/execution/context.rs @@ -255,6 +255,19 @@ impl ExecutionContext { Ok(Arc::new(DataFrameImpl::new(self.state.clone(), &plan))) } + LogicalPlan::DropMemoryTable { name, if_exist, .. } => { + let returned = self.deregister_table(name.as_str())?; + if !if_exist && returned.is_none() { + Err(DataFusionError::Execution(format!( + "Memory table {:?} doesn't exist.", + name + ))) + } else { + let plan = LogicalPlanBuilder::empty(false).build()?; + Ok(Arc::new(DataFrameImpl::new(self.state.clone(), &plan))) + } + } + plan => Ok(Arc::new(DataFrameImpl::new( self.state.clone(), &self.optimize(&plan)?, diff --git a/datafusion/src/logical_plan/plan.rs b/datafusion/src/logical_plan/plan.rs index 6faac01d7360..7ca2f82c2a55 100644 --- a/datafusion/src/logical_plan/plan.rs +++ b/datafusion/src/logical_plan/plan.rs @@ -212,6 +212,15 @@ pub enum LogicalPlan { /// The logical plan input: Arc, }, + /// Drops an in memory table. + DropMemoryTable { + /// The table name + name: String, + /// If the table exists + if_exist: bool, + /// Dummy schema + schema: DFSchemaRef, + }, /// Values expression. See /// [Postgres VALUES](https://www.postgresql.org/docs/current/queries-values.html) /// documentation for more details. @@ -274,6 +283,7 @@ impl LogicalPlan { LogicalPlan::Extension { node } => node.schema(), LogicalPlan::Union { schema, .. } => schema, LogicalPlan::CreateMemoryTable { input, .. } => input.schema(), + LogicalPlan::DropMemoryTable { schema, .. } => schema, } } @@ -320,6 +330,7 @@ impl LogicalPlan { | LogicalPlan::Sort { input, .. } | LogicalPlan::CreateMemoryTable { input, .. } | LogicalPlan::Filter { input, .. } => input.all_schemas(), + LogicalPlan::DropMemoryTable { .. } => vec![], } } @@ -366,6 +377,7 @@ impl LogicalPlan { | LogicalPlan::Limit { .. } | LogicalPlan::CreateExternalTable { .. } | LogicalPlan::CreateMemoryTable { .. } + | LogicalPlan::DropMemoryTable { .. } | LogicalPlan::CrossJoin { .. } | LogicalPlan::Analyze { .. } | LogicalPlan::Explain { .. } @@ -397,7 +409,8 @@ impl LogicalPlan { LogicalPlan::TableScan { .. } | LogicalPlan::EmptyRelation { .. } | LogicalPlan::Values { .. } - | LogicalPlan::CreateExternalTable { .. } => vec![], + | LogicalPlan::CreateExternalTable { .. } + | LogicalPlan::DropMemoryTable { .. } => vec![], } } @@ -545,7 +558,8 @@ impl LogicalPlan { LogicalPlan::TableScan { .. } | LogicalPlan::EmptyRelation { .. } | LogicalPlan::Values { .. } - | LogicalPlan::CreateExternalTable { .. } => true, + | LogicalPlan::CreateExternalTable { .. } + | LogicalPlan::DropMemoryTable { .. } => true, }; if !recurse { return Ok(false); @@ -863,6 +877,9 @@ impl LogicalPlan { LogicalPlan::CreateMemoryTable { ref name, .. } => { write!(f, "CreateMemoryTable: {:?}", name) } + LogicalPlan::DropMemoryTable { ref name, .. } => { + write!(f, "DropMemoryTable: {:?}", name) + } LogicalPlan::Explain { .. } => write!(f, "Explain"), LogicalPlan::Analyze { .. } => write!(f, "Analyze"), LogicalPlan::Union { .. } => write!(f, "Union"), diff --git a/datafusion/src/optimizer/common_subexpr_eliminate.rs b/datafusion/src/optimizer/common_subexpr_eliminate.rs index 9f2f2afea6a4..d05072e6c67a 100644 --- a/datafusion/src/optimizer/common_subexpr_eliminate.rs +++ b/datafusion/src/optimizer/common_subexpr_eliminate.rs @@ -206,6 +206,7 @@ fn optimize(plan: &LogicalPlan, execution_props: &ExecutionProps) -> Result { // apply the optimization to all inputs of the plan let expr = plan.expressions(); diff --git a/datafusion/src/optimizer/constant_folding.rs b/datafusion/src/optimizer/constant_folding.rs index 5299b9a219ef..5cf3e7b5597b 100644 --- a/datafusion/src/optimizer/constant_folding.rs +++ b/datafusion/src/optimizer/constant_folding.rs @@ -71,6 +71,7 @@ impl OptimizerRule for ConstantFolding { | LogicalPlan::Repartition { .. } | LogicalPlan::CreateExternalTable { .. } | LogicalPlan::CreateMemoryTable { .. } + | LogicalPlan::DropMemoryTable { .. } | LogicalPlan::Values { .. } | LogicalPlan::Extension { .. } | LogicalPlan::Sort { .. } diff --git a/datafusion/src/optimizer/projection_push_down.rs b/datafusion/src/optimizer/projection_push_down.rs index a30523d21deb..0f4bde45122d 100644 --- a/datafusion/src/optimizer/projection_push_down.rs +++ b/datafusion/src/optimizer/projection_push_down.rs @@ -437,6 +437,7 @@ fn optimize_plan( | LogicalPlan::Sort { .. } | LogicalPlan::CreateExternalTable { .. } | LogicalPlan::CreateMemoryTable { .. } + | LogicalPlan::DropMemoryTable { .. } | LogicalPlan::CrossJoin { .. } | LogicalPlan::Extension { .. } => { let expr = plan.expressions(); diff --git a/datafusion/src/optimizer/utils.rs b/datafusion/src/optimizer/utils.rs index c94d48c8defb..ce890506314a 100644 --- a/datafusion/src/optimizer/utils.rs +++ b/datafusion/src/optimizer/utils.rs @@ -228,6 +228,13 @@ pub fn from_plan( name: name.clone(), }) } + LogicalPlan::DropMemoryTable { name, if_exist, .. } => { + Ok(LogicalPlan::DropMemoryTable { + if_exist: if_exist.clone(), + name: name.clone(), + schema: DFSchemaRef::new(DFSchema::empty()), + }) + } LogicalPlan::Extension { node } => Ok(LogicalPlan::Extension { node: node.from_template(expr, inputs), }), diff --git a/datafusion/src/physical_plan/planner.rs b/datafusion/src/physical_plan/planner.rs index e1170ed891b1..74e480f8ca6c 100644 --- a/datafusion/src/physical_plan/planner.rs +++ b/datafusion/src/physical_plan/planner.rs @@ -802,7 +802,7 @@ impl DefaultPhysicalPlanner { Ok(Arc::new(GlobalLimitExec::new(input, limit))) } - LogicalPlan::CreateExternalTable { .. }=> { + LogicalPlan::CreateExternalTable { .. } => { // There is no default plan for "CREATE EXTERNAL // TABLE" -- it must be handled at a higher level (so // that the appropriate table can be registered with @@ -811,7 +811,7 @@ impl DefaultPhysicalPlanner { "Unsupported logical plan: CreateExternalTable".to_string(), )) } - | LogicalPlan::CreateMemoryTable {..} => { + | LogicalPlan::CreateMemoryTable {..} | LogicalPlan::DropMemoryTable {..} => { // Create a dummy exec. Ok(Arc::new(EmptyExec::new( false, diff --git a/datafusion/src/sql/planner.rs b/datafusion/src/sql/planner.rs index 50875a8f3779..3ae0654f17c1 100644 --- a/datafusion/src/sql/planner.rs +++ b/datafusion/src/sql/planner.rs @@ -29,8 +29,8 @@ use crate::logical_plan::window_frames::{WindowFrame, WindowFrameUnits}; use crate::logical_plan::Expr::Alias; use crate::logical_plan::{ and, builder::expand_wildcard, col, lit, normalize_col, union_with_alias, Column, - DFSchema, Expr, LogicalPlan, LogicalPlanBuilder, Operator, PlanType, ToDFSchema, - ToStringifiedPlan, + DFSchema, DFSchemaRef, Expr, LogicalPlan, LogicalPlanBuilder, Operator, PlanType, + ToDFSchema, ToStringifiedPlan, }; use crate::optimizer::utils::exprlist_to_columns; use crate::prelude::JoinType; @@ -53,7 +53,7 @@ use sqlparser::ast::{ TableWithJoins, TrimWhereField, UnaryOperator, Value, Values as SQLValues, }; use sqlparser::ast::{ColumnDef as SQLColumnDef, ColumnOption}; -use sqlparser::ast::{OrderByExpr, Statement}; +use sqlparser::ast::{ObjectType, OrderByExpr, Statement}; use sqlparser::parser::ParserError::ParserError; use super::{ @@ -65,6 +65,7 @@ use super::{ }, }; use crate::logical_plan::builder::project_with_alias; +use regex::internal::Input; /// The ContextProvider trait allows the query planner to obtain meta-data about tables and /// functions referenced in SQL statements @@ -163,6 +164,18 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> { }) } + Statement::Drop { + object_type: ObjectType::Table, + if_exists, + names, + cascade: _, + purge: _, + } => Ok(LogicalPlan::DropMemoryTable { + name: names.get(0).unwrap().to_string(), + if_exist: if_exists.clone(), + schema: DFSchemaRef::new(DFSchema::empty()), + }), + Statement::ShowColumns { extended, full, diff --git a/datafusion/tests/sql.rs b/datafusion/tests/sql.rs index e6064afe7142..784f0f745fbf 100644 --- a/datafusion/tests/sql.rs +++ b/datafusion/tests/sql.rs @@ -711,6 +711,23 @@ async fn create_table_as() -> Result<()> { Ok(()) } +#[tokio::test] +async fn drop_table() -> Result<()> { + let mut ctx = ExecutionContext::new(); + register_aggregate_simple_csv(&mut ctx).await?; + + let sql = "CREATE TABLE my_table AS SELECT * FROM aggregate_simple"; + ctx.sql(sql).await.unwrap(); + + let sql = "DROP TABLE my_table"; + ctx.sql(sql).await.unwrap(); + + let result = ctx.table("my_table"); + assert!(result.is_err(), "drop table should deregister table."); + + Ok(()) +} + #[tokio::test] async fn select_distinct() -> Result<()> { let mut ctx = ExecutionContext::new(); From 64fcca2580608f1ae05a8f195f807ae831f234ba Mon Sep 17 00:00:00 2001 From: Liang-Chi Hsieh Date: Mon, 8 Nov 2021 00:08:35 -0800 Subject: [PATCH 2/5] Rename to DropTable. --- .../core/src/serde/logical_plan/to_proto.rs | 3 +++ datafusion/src/execution/context.rs | 2 +- datafusion/src/logical_plan/plan.rs | 18 +++++++++--------- .../src/optimizer/common_subexpr_eliminate.rs | 2 +- datafusion/src/optimizer/constant_folding.rs | 2 +- .../src/optimizer/projection_push_down.rs | 2 +- datafusion/src/optimizer/utils.rs | 10 ++-------- datafusion/src/physical_plan/planner.rs | 2 +- datafusion/src/sql/planner.rs | 2 +- 9 files changed, 20 insertions(+), 23 deletions(-) diff --git a/ballista/rust/core/src/serde/logical_plan/to_proto.rs b/ballista/rust/core/src/serde/logical_plan/to_proto.rs index ca83ffdaf437..9ade6cea060c 100644 --- a/ballista/rust/core/src/serde/logical_plan/to_proto.rs +++ b/ballista/rust/core/src/serde/logical_plan/to_proto.rs @@ -1011,6 +1011,9 @@ impl TryInto for &LogicalPlan { LogicalPlan::CreateMemoryTable { .. } => Err(proto_error( "Error converting CreateMemoryTable. Not yet supported in Ballista", )), + LogicalPlan::DropTable { .. } => Err(proto_error( + "Error converting DropMemoryTable. Not yet supported in Ballista", + )), } } } diff --git a/datafusion/src/execution/context.rs b/datafusion/src/execution/context.rs index 059bd71246b5..ca160d52e74b 100644 --- a/datafusion/src/execution/context.rs +++ b/datafusion/src/execution/context.rs @@ -255,7 +255,7 @@ impl ExecutionContext { Ok(Arc::new(DataFrameImpl::new(self.state.clone(), &plan))) } - LogicalPlan::DropMemoryTable { name, if_exist, .. } => { + LogicalPlan::DropTable { name, if_exist, .. } => { let returned = self.deregister_table(name.as_str())?; if !if_exist && returned.is_none() { Err(DataFusionError::Execution(format!( diff --git a/datafusion/src/logical_plan/plan.rs b/datafusion/src/logical_plan/plan.rs index 7ca2f82c2a55..3e1b95429ba9 100644 --- a/datafusion/src/logical_plan/plan.rs +++ b/datafusion/src/logical_plan/plan.rs @@ -212,8 +212,8 @@ pub enum LogicalPlan { /// The logical plan input: Arc, }, - /// Drops an in memory table. - DropMemoryTable { + /// Drops a table. + DropTable { /// The table name name: String, /// If the table exists @@ -283,7 +283,7 @@ impl LogicalPlan { LogicalPlan::Extension { node } => node.schema(), LogicalPlan::Union { schema, .. } => schema, LogicalPlan::CreateMemoryTable { input, .. } => input.schema(), - LogicalPlan::DropMemoryTable { schema, .. } => schema, + LogicalPlan::DropTable { schema, .. } => schema, } } @@ -330,7 +330,7 @@ impl LogicalPlan { | LogicalPlan::Sort { input, .. } | LogicalPlan::CreateMemoryTable { input, .. } | LogicalPlan::Filter { input, .. } => input.all_schemas(), - LogicalPlan::DropMemoryTable { .. } => vec![], + LogicalPlan::DropTable { .. } => vec![], } } @@ -377,7 +377,7 @@ impl LogicalPlan { | LogicalPlan::Limit { .. } | LogicalPlan::CreateExternalTable { .. } | LogicalPlan::CreateMemoryTable { .. } - | LogicalPlan::DropMemoryTable { .. } + | LogicalPlan::DropTable { .. } | LogicalPlan::CrossJoin { .. } | LogicalPlan::Analyze { .. } | LogicalPlan::Explain { .. } @@ -410,7 +410,7 @@ impl LogicalPlan { | LogicalPlan::EmptyRelation { .. } | LogicalPlan::Values { .. } | LogicalPlan::CreateExternalTable { .. } - | LogicalPlan::DropMemoryTable { .. } => vec![], + | LogicalPlan::DropTable { .. } => vec![], } } @@ -559,7 +559,7 @@ impl LogicalPlan { | LogicalPlan::EmptyRelation { .. } | LogicalPlan::Values { .. } | LogicalPlan::CreateExternalTable { .. } - | LogicalPlan::DropMemoryTable { .. } => true, + | LogicalPlan::DropTable { .. } => true, }; if !recurse { return Ok(false); @@ -877,8 +877,8 @@ impl LogicalPlan { LogicalPlan::CreateMemoryTable { ref name, .. } => { write!(f, "CreateMemoryTable: {:?}", name) } - LogicalPlan::DropMemoryTable { ref name, .. } => { - write!(f, "DropMemoryTable: {:?}", name) + LogicalPlan::DropTable { ref name, .. } => { + write!(f, "DropTable: {:?}", name) } LogicalPlan::Explain { .. } => write!(f, "Explain"), LogicalPlan::Analyze { .. } => write!(f, "Analyze"), diff --git a/datafusion/src/optimizer/common_subexpr_eliminate.rs b/datafusion/src/optimizer/common_subexpr_eliminate.rs index d05072e6c67a..c88032e38b2e 100644 --- a/datafusion/src/optimizer/common_subexpr_eliminate.rs +++ b/datafusion/src/optimizer/common_subexpr_eliminate.rs @@ -206,7 +206,7 @@ fn optimize(plan: &LogicalPlan, execution_props: &ExecutionProps) -> Result { // apply the optimization to all inputs of the plan let expr = plan.expressions(); diff --git a/datafusion/src/optimizer/constant_folding.rs b/datafusion/src/optimizer/constant_folding.rs index 5cf3e7b5597b..a0bc04a0caf5 100644 --- a/datafusion/src/optimizer/constant_folding.rs +++ b/datafusion/src/optimizer/constant_folding.rs @@ -71,7 +71,7 @@ impl OptimizerRule for ConstantFolding { | LogicalPlan::Repartition { .. } | LogicalPlan::CreateExternalTable { .. } | LogicalPlan::CreateMemoryTable { .. } - | LogicalPlan::DropMemoryTable { .. } + | LogicalPlan::DropTable { .. } | LogicalPlan::Values { .. } | LogicalPlan::Extension { .. } | LogicalPlan::Sort { .. } diff --git a/datafusion/src/optimizer/projection_push_down.rs b/datafusion/src/optimizer/projection_push_down.rs index 0f4bde45122d..7c087a17a986 100644 --- a/datafusion/src/optimizer/projection_push_down.rs +++ b/datafusion/src/optimizer/projection_push_down.rs @@ -437,7 +437,7 @@ fn optimize_plan( | LogicalPlan::Sort { .. } | LogicalPlan::CreateExternalTable { .. } | LogicalPlan::CreateMemoryTable { .. } - | LogicalPlan::DropMemoryTable { .. } + | LogicalPlan::DropTable { .. } | LogicalPlan::CrossJoin { .. } | LogicalPlan::Extension { .. } => { let expr = plan.expressions(); diff --git a/datafusion/src/optimizer/utils.rs b/datafusion/src/optimizer/utils.rs index ce890506314a..52beb695529c 100644 --- a/datafusion/src/optimizer/utils.rs +++ b/datafusion/src/optimizer/utils.rs @@ -228,13 +228,6 @@ pub fn from_plan( name: name.clone(), }) } - LogicalPlan::DropMemoryTable { name, if_exist, .. } => { - Ok(LogicalPlan::DropMemoryTable { - if_exist: if_exist.clone(), - name: name.clone(), - schema: DFSchemaRef::new(DFSchema::empty()), - }) - } LogicalPlan::Extension { node } => Ok(LogicalPlan::Extension { node: node.from_template(expr, inputs), }), @@ -270,7 +263,8 @@ pub fn from_plan( } LogicalPlan::EmptyRelation { .. } | LogicalPlan::TableScan { .. } - | LogicalPlan::CreateExternalTable { .. } => { + | LogicalPlan::CreateExternalTable { .. } + | LogicalPlan::DropTable { .. } => { // All of these plan types have no inputs / exprs so should not be called assert!(expr.is_empty(), "{:?} should have no exprs", plan); assert!(inputs.is_empty(), "{:?} should have no inputs", plan); diff --git a/datafusion/src/physical_plan/planner.rs b/datafusion/src/physical_plan/planner.rs index 74e480f8ca6c..402f119e8ea0 100644 --- a/datafusion/src/physical_plan/planner.rs +++ b/datafusion/src/physical_plan/planner.rs @@ -811,7 +811,7 @@ impl DefaultPhysicalPlanner { "Unsupported logical plan: CreateExternalTable".to_string(), )) } - | LogicalPlan::CreateMemoryTable {..} | LogicalPlan::DropMemoryTable {..} => { + | LogicalPlan::CreateMemoryTable {..} | LogicalPlan::DropTable {..} => { // Create a dummy exec. Ok(Arc::new(EmptyExec::new( false, diff --git a/datafusion/src/sql/planner.rs b/datafusion/src/sql/planner.rs index 3ae0654f17c1..4a86c21e69cc 100644 --- a/datafusion/src/sql/planner.rs +++ b/datafusion/src/sql/planner.rs @@ -170,7 +170,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> { names, cascade: _, purge: _, - } => Ok(LogicalPlan::DropMemoryTable { + } => Ok(LogicalPlan::DropTable { name: names.get(0).unwrap().to_string(), if_exist: if_exists.clone(), schema: DFSchemaRef::new(DFSchema::empty()), From 5dc12df107cfa4a30dcdf16841fb8191c489978e Mon Sep 17 00:00:00 2001 From: Liang-Chi Hsieh Date: Mon, 8 Nov 2021 00:18:46 -0800 Subject: [PATCH 3/5] Remove undeclared crate. --- datafusion/src/sql/planner.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/datafusion/src/sql/planner.rs b/datafusion/src/sql/planner.rs index 4a86c21e69cc..9000500e3779 100644 --- a/datafusion/src/sql/planner.rs +++ b/datafusion/src/sql/planner.rs @@ -65,7 +65,6 @@ use super::{ }, }; use crate::logical_plan::builder::project_with_alias; -use regex::internal::Input; /// The ContextProvider trait allows the query planner to obtain meta-data about tables and /// functions referenced in SQL statements From 8f8bd280cd1e9997ba2db9e996d694833e79add6 Mon Sep 17 00:00:00 2001 From: Liang-Chi Hsieh Date: Mon, 8 Nov 2021 00:45:21 -0800 Subject: [PATCH 4/5] Fix clippy error. --- datafusion/src/sql/planner.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datafusion/src/sql/planner.rs b/datafusion/src/sql/planner.rs index 9000500e3779..974337892432 100644 --- a/datafusion/src/sql/planner.rs +++ b/datafusion/src/sql/planner.rs @@ -171,7 +171,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> { purge: _, } => Ok(LogicalPlan::DropTable { name: names.get(0).unwrap().to_string(), - if_exist: if_exists.clone(), + if_exist: *if_exists, schema: DFSchemaRef::new(DFSchema::empty()), }), From 18ce1d23e7e05679fe30ffff95b87e039c3ac536 Mon Sep 17 00:00:00 2001 From: Liang-Chi Hsieh Date: Mon, 8 Nov 2021 11:45:13 -0800 Subject: [PATCH 5/5] For review comments. --- .../rust/core/src/serde/logical_plan/to_proto.rs | 2 +- datafusion/src/logical_plan/plan.rs | 6 ++++-- datafusion/src/sql/planner.rs | 14 +++++++++----- datafusion/tests/sql.rs | 3 +++ 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/ballista/rust/core/src/serde/logical_plan/to_proto.rs b/ballista/rust/core/src/serde/logical_plan/to_proto.rs index 9ade6cea060c..e4c7656cc8a1 100644 --- a/ballista/rust/core/src/serde/logical_plan/to_proto.rs +++ b/ballista/rust/core/src/serde/logical_plan/to_proto.rs @@ -1012,7 +1012,7 @@ impl TryInto for &LogicalPlan { "Error converting CreateMemoryTable. Not yet supported in Ballista", )), LogicalPlan::DropTable { .. } => Err(proto_error( - "Error converting DropMemoryTable. Not yet supported in Ballista", + "Error converting DropTable. Not yet supported in Ballista", )), } } diff --git a/datafusion/src/logical_plan/plan.rs b/datafusion/src/logical_plan/plan.rs index 3e1b95429ba9..d1e1678b6617 100644 --- a/datafusion/src/logical_plan/plan.rs +++ b/datafusion/src/logical_plan/plan.rs @@ -877,8 +877,10 @@ impl LogicalPlan { LogicalPlan::CreateMemoryTable { ref name, .. } => { write!(f, "CreateMemoryTable: {:?}", name) } - LogicalPlan::DropTable { ref name, .. } => { - write!(f, "DropTable: {:?}", name) + LogicalPlan::DropTable { + ref name, if_exist, .. + } => { + write!(f, "DropTable: {:?} if not exist:={}", name, if_exist) } LogicalPlan::Explain { .. } => write!(f, "Explain"), LogicalPlan::Analyze { .. } => write!(f, "Analyze"), diff --git a/datafusion/src/sql/planner.rs b/datafusion/src/sql/planner.rs index 974337892432..1731c905d779 100644 --- a/datafusion/src/sql/planner.rs +++ b/datafusion/src/sql/planner.rs @@ -169,11 +169,15 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> { names, cascade: _, purge: _, - } => Ok(LogicalPlan::DropTable { - name: names.get(0).unwrap().to_string(), - if_exist: *if_exists, - schema: DFSchemaRef::new(DFSchema::empty()), - }), + } => + // We don't support cascade and purge for now. + { + Ok(LogicalPlan::DropTable { + name: names.get(0).unwrap().to_string(), + if_exist: *if_exists, + schema: DFSchemaRef::new(DFSchema::empty()), + }) + } Statement::ShowColumns { extended, diff --git a/datafusion/tests/sql.rs b/datafusion/tests/sql.rs index 784f0f745fbf..ad5c31bd13c5 100644 --- a/datafusion/tests/sql.rs +++ b/datafusion/tests/sql.rs @@ -725,6 +725,9 @@ async fn drop_table() -> Result<()> { let result = ctx.table("my_table"); assert!(result.is_err(), "drop table should deregister table."); + let sql = "DROP TABLE IF EXISTS my_table"; + ctx.sql(sql).await.unwrap(); + Ok(()) }