Skip to content

Commit

Permalink
minor: refine code (#1951)
Browse files Browse the repository at this point in the history
  • Loading branch information
xudong963 authored Mar 9, 2022
1 parent 11edd3c commit 06bda75
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 22 deletions.
6 changes: 4 additions & 2 deletions datafusion/src/execution/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,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,
/// 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,
schema: DFSchemaRef::new(DFSchema::empty()),
}))
}
Expand Down

0 comments on commit 06bda75

Please sign in to comment.