Skip to content

Commit 7be2263

Browse files
clean imports and qualified imports
1 parent a47e58c commit 7be2263

File tree

1 file changed

+24
-26
lines changed

1 file changed

+24
-26
lines changed

datafusion/sql/src/statement.rs

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,19 @@ use datafusion_expr::{
4646
cast, col, Analyze, CreateCatalog, CreateCatalogSchema,
4747
CreateExternalTable as PlanCreateExternalTable, CreateFunction, CreateFunctionBody,
4848
CreateMemoryTable, CreateView, DescribeTable, DmlStatement, DropCatalogSchema,
49-
DropFunction, DropTable, DropView, EmptyRelation, Explain, ExprSchemable, Filter,
50-
LogicalPlan, LogicalPlanBuilder, OperateFunctionArg, PlanType, Prepare, SetVariable,
51-
Statement as PlanStatement, ToStringifiedPlan, TransactionAccessMode,
49+
DropFunction, DropTable, DropView, EmptyRelation, Explain, Expr, ExprSchemable,
50+
Filter, LogicalPlan, LogicalPlanBuilder, OperateFunctionArg, PlanType, Prepare,
51+
SetVariable, Statement as PlanStatement, ToStringifiedPlan, TransactionAccessMode,
5252
TransactionConclusion, TransactionEnd, TransactionIsolationLevel, TransactionStart,
5353
Volatility, WriteOp,
5454
};
55-
use sqlparser::ast::{self, AssignmentTarget, CreateTable};
55+
use sqlparser::ast;
5656
use sqlparser::ast::{
57-
Assignment, ColumnDef, CreateTableOptions, Delete, DescribeAlias, Expr as SQLExpr,
58-
Expr, FromTable, Ident, Insert, ObjectName, ObjectType, OneOrManyWithParens, Query,
59-
SchemaName, SetExpr, ShowCreateObject, ShowStatementFilter, Statement,
60-
TableConstraint, TableFactor, TableWithJoins, TransactionMode, UnaryOperator, Value,
57+
Assignment, AssignmentTarget, ColumnDef, CreateTable, CreateTableOptions, Delete,
58+
DescribeAlias, Expr as SQLExpr, FromTable, Ident, Insert, ObjectName, ObjectType,
59+
OneOrManyWithParens, Query, SchemaName, SetExpr, ShowCreateObject,
60+
ShowStatementFilter, Statement, TableConstraint, TableFactor, TableWithJoins,
61+
TransactionMode, UnaryOperator, Value,
6162
};
6263
use sqlparser::parser::ParserError::ParserError;
6364

@@ -954,7 +955,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
954955
order_exprs: Vec<LexOrdering>,
955956
schema: &DFSchemaRef,
956957
planner_context: &mut PlannerContext,
957-
) -> Result<Vec<Vec<datafusion_expr::Expr>>> {
958+
) -> Result<Vec<Vec<Expr>>> {
958959
// Ask user to provide a schema if schema is empty.
959960
if !order_exprs.is_empty() && schema.fields().is_empty() {
960961
return plan_err!(
@@ -1159,7 +1160,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
11591160
local: bool,
11601161
hivevar: bool,
11611162
variables: &OneOrManyWithParens<ObjectName>,
1162-
value: Vec<Expr>,
1163+
value: Vec<SQLExpr>,
11631164
) -> Result<LogicalPlan> {
11641165
if local {
11651166
return not_impl_err!("LOCAL is not supported");
@@ -1218,7 +1219,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
12181219
fn delete_to_plan(
12191220
&self,
12201221
table_name: ObjectName,
1221-
predicate_expr: Option<Expr>,
1222+
predicate_expr: Option<SQLExpr>,
12221223
) -> Result<LogicalPlan> {
12231224
// Do a table lookup to verify the table exists
12241225
let table_ref = self.object_name_to_table_reference(table_name.clone())?;
@@ -1264,7 +1265,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
12641265
table: TableWithJoins,
12651266
assignments: Vec<Assignment>,
12661267
from: Option<TableWithJoins>,
1267-
predicate_expr: Option<Expr>,
1268+
predicate_expr: Option<SQLExpr>,
12681269
) -> Result<LogicalPlan> {
12691270
let (table_name, table_alias) = match &table.relation {
12701271
TableFactor::Table { name, alias, .. } => (name.clone(), alias.clone()),
@@ -1297,7 +1298,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
12971298
table_schema.field_with_unqualified_name(&col_name.value)?;
12981299
Ok((col_name.value.clone(), assign.value.clone()))
12991300
})
1300-
.collect::<Result<HashMap<String, Expr>>>()?;
1301+
.collect::<Result<HashMap<String, SQLExpr>>>()?;
13011302

13021303
// Build scan, join with from table if it exists.
13031304
let mut input_tables = vec![table];
@@ -1336,8 +1337,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
13361337
&mut planner_context,
13371338
)?;
13381339
// Update placeholder's datatype to the type of the target column
1339-
if let datafusion_expr::Expr::Placeholder(placeholder) = &mut expr
1340-
{
1340+
if let Expr::Placeholder(placeholder) = &mut expr {
13411341
placeholder.data_type = placeholder
13421342
.data_type
13431343
.take()
@@ -1349,14 +1349,12 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
13491349
None => {
13501350
// If the target table has an alias, use it to qualify the column name
13511351
if let Some(alias) = &table_alias {
1352-
datafusion_expr::Expr::Column(Column::new(
1352+
Expr::Column(Column::new(
13531353
Some(self.normalizer.normalize(alias.name.clone())),
13541354
field.name(),
13551355
))
13561356
} else {
1357-
datafusion_expr::Expr::Column(Column::from((
1358-
qualifier, field,
1359-
)))
1357+
Expr::Column(Column::from((qualifier, field)))
13601358
}
13611359
}
13621360
};
@@ -1431,7 +1429,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
14311429
if let SetExpr::Values(ast::Values { rows, .. }) = (*source.body).clone() {
14321430
for row in rows.iter() {
14331431
for (idx, val) in row.iter().enumerate() {
1434-
if let ast::Expr::Value(Value::Placeholder(name)) = val {
1432+
if let SQLExpr::Value(Value::Placeholder(name)) = val {
14351433
let name =
14361434
name.replace('$', "").parse::<usize>().map_err(|_| {
14371435
plan_datafusion_err!("Can't parse placeholder: {name}")
@@ -1464,23 +1462,23 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
14641462
.map(|(i, value_index)| {
14651463
let target_field = table_schema.field(i);
14661464
let expr = match value_index {
1467-
Some(v) => datafusion_expr::Expr::Column(Column::from(
1468-
source.schema().qualified_field(v),
1469-
))
1470-
.cast_to(target_field.data_type(), source.schema())?,
1465+
Some(v) => {
1466+
Expr::Column(Column::from(source.schema().qualified_field(v)))
1467+
.cast_to(target_field.data_type(), source.schema())?
1468+
}
14711469
// The value is not specified. Fill in the default value for the column.
14721470
None => table_source
14731471
.get_column_default(target_field.name())
14741472
.cloned()
14751473
.unwrap_or_else(|| {
14761474
// If there is no default for the column, then the default is NULL
1477-
datafusion_expr::Expr::Literal(ScalarValue::Null)
1475+
Expr::Literal(ScalarValue::Null)
14781476
})
14791477
.cast_to(target_field.data_type(), &DFSchema::empty())?,
14801478
};
14811479
Ok(expr.alias(target_field.name()))
14821480
})
1483-
.collect::<Result<Vec<datafusion_expr::Expr>>>()?;
1481+
.collect::<Result<Vec<Expr>>>()?;
14841482
let source = project(source, exprs)?;
14851483

14861484
let op = if overwrite {

0 commit comments

Comments
 (0)