-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Add drop table support #1266
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
Add drop table support #1266
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -212,6 +212,15 @@ pub enum LogicalPlan { | |
| /// The logical plan | ||
| input: Arc<LogicalPlan>, | ||
| }, | ||
| /// Drops a table. | ||
| DropTable { | ||
| /// 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::DropTable { schema, .. } => schema, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could return an empty schema here instead of keeping it the plan node.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried creating an empty schema before, but
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, that is unfortunate but I think the comments in the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm. Another solution could be having / referencing a static object for an empty schema, but I'm ok with the current situation. |
||
| } | ||
| } | ||
|
|
||
|
|
@@ -320,6 +330,7 @@ impl LogicalPlan { | |
| | LogicalPlan::Sort { input, .. } | ||
| | LogicalPlan::CreateMemoryTable { input, .. } | ||
| | LogicalPlan::Filter { input, .. } => input.all_schemas(), | ||
| LogicalPlan::DropTable { .. } => vec![], | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -366,6 +377,7 @@ impl LogicalPlan { | |
| | LogicalPlan::Limit { .. } | ||
| | LogicalPlan::CreateExternalTable { .. } | ||
| | LogicalPlan::CreateMemoryTable { .. } | ||
| | LogicalPlan::DropTable { .. } | ||
| | LogicalPlan::CrossJoin { .. } | ||
| | LogicalPlan::Analyze { .. } | ||
| | LogicalPlan::Explain { .. } | ||
|
|
@@ -397,7 +409,8 @@ impl LogicalPlan { | |
| LogicalPlan::TableScan { .. } | ||
| | LogicalPlan::EmptyRelation { .. } | ||
| | LogicalPlan::Values { .. } | ||
| | LogicalPlan::CreateExternalTable { .. } => vec![], | ||
| | LogicalPlan::CreateExternalTable { .. } | ||
| | LogicalPlan::DropTable { .. } => vec![], | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -545,7 +558,8 @@ impl LogicalPlan { | |
| LogicalPlan::TableScan { .. } | ||
| | LogicalPlan::EmptyRelation { .. } | ||
| | LogicalPlan::Values { .. } | ||
| | LogicalPlan::CreateExternalTable { .. } => true, | ||
| | LogicalPlan::CreateExternalTable { .. } | ||
| | LogicalPlan::DropTable { .. } => true, | ||
| }; | ||
| if !recurse { | ||
| return Ok(false); | ||
|
|
@@ -863,6 +877,11 @@ impl LogicalPlan { | |
| LogicalPlan::CreateMemoryTable { ref name, .. } => { | ||
| write!(f, "CreateMemoryTable: {:?}", 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"), | ||
| LogicalPlan::Union { .. } => write!(f, "Union"), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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::{ | ||
|
|
@@ -163,6 +163,22 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> { | |
| }) | ||
| } | ||
|
|
||
| Statement::Drop { | ||
| object_type: ObjectType::Table, | ||
| if_exists, | ||
| names, | ||
| cascade: _, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it possible to add cascade and purge to the statement to the logical plan, or otherwise have a warning here saying that they do not take any effect
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've just added a comment here, is it okay? |
||
| purge: _, | ||
| } => | ||
| // 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, | ||
| full, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i wonder if it's valuable to actually just attach the fetched table schema
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
otherwise you can just remove this placeholder
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need a schema for dropping the table?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea, seems an empty schema is better here.