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

minor code refinement: if_exists name change, wildcard field for logical plan, etc. #1951

Merged
merged 1 commit into from
Mar 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 4 additions & 2 deletions datafusion/src/execution/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,11 @@ impl ExecutionContext {
Ok(Arc::new(DataFrameImpl::new(self.state.clone(), &plan)))
}

LogicalPlan::DropTable(DropTable { name, if_exist, .. }) => {
LogicalPlan::DropTable(DropTable {
name, if_exists, ..
}) => {
let returned = self.deregister_table(name.as_str())?;
if !if_exist && returned.is_none() {
if !if_exists && returned.is_none() {
Err(DataFusionError::Execution(format!(
"Memory table {:?} doesn't exist.",
name
Expand Down
8 changes: 5 additions & 3 deletions datafusion/src/logical_plan/plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ pub struct DropTable {
/// The table name
pub name: String,
/// If the table exists
pub if_exist: bool,
pub if_exists: bool,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consistent with Statement::Drop

/// Dummy schema
pub schema: DFSchemaRef,
}
Expand Down Expand Up @@ -1002,8 +1002,10 @@ impl LogicalPlan {
}) => {
write!(f, "CreateMemoryTable: {:?}", name)
}
LogicalPlan::DropTable(DropTable { name, if_exist, .. }) => {
write!(f, "DropTable: {:?} if not exist:={}", name, if_exist)
LogicalPlan::DropTable(DropTable {
name, if_exists, ..
}) => {
write!(f, "DropTable: {:?} if not exist:={}", name, if_exists)
}
LogicalPlan::Explain { .. } => write!(f, "Explain"),
LogicalPlan::Analyze { .. } => write!(f, "Analyze"),
Expand Down
22 changes: 5 additions & 17 deletions datafusion/src/sql/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,9 @@ use arrow::datatypes::*;
use hashbrown::HashMap;
use sqlparser::ast::{
BinaryOperator, DataType as SQLDataType, DateTimeField, Expr as SQLExpr, FunctionArg,
FunctionArgExpr, HiveDistributionStyle, Ident, Join, JoinConstraint, JoinOperator,
ObjectName, Query, Select, SelectItem, SetExpr, SetOperator, ShowStatementFilter,
TableFactor, TableWithJoins, TrimWhereField, UnaryOperator, Value,
Values as SQLValues,
FunctionArgExpr, Ident, Join, JoinConstraint, JoinOperator, ObjectName, Query,
Select, SelectItem, SetExpr, SetOperator, ShowStatementFilter, TableFactor,
TableWithJoins, TrimWhereField, UnaryOperator, Value, Values as SQLValues,
};
use sqlparser::ast::{ColumnDef as SQLColumnDef, ColumnOption};
use sqlparser::ast::{ObjectType, OrderByExpr, Statement};
Expand Down Expand Up @@ -150,22 +149,11 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
Statement::CreateTable {
query: Some(query),
name,
or_replace: false,
columns,
constraints,
hive_distribution: HiveDistributionStyle::NONE,
hive_formats: _hive_formats,
table_properties,
with_options,
file_format: None,
location: None,
like: None,
temporary: _temporary,
external: false,
if_not_exists: false,
without_rowid: _without_row_id,
engine: _engine,
default_charset: _default_charset,
..
} if columns.is_empty()
&& constraints.is_empty()
&& table_properties.is_empty()
Expand Down Expand Up @@ -194,7 +182,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
{
Ok(LogicalPlan::DropTable(DropTable {
name: names.get(0).unwrap().to_string(),
if_exist: *if_exists,
if_exists: *if_exists,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

schema: DFSchemaRef::new(DFSchema::empty()),
}))
}
Expand Down