Skip to content

Commit

Permalink
Revert "clean imports and qualified imports"
Browse files Browse the repository at this point in the history
This reverts commit 7be2263.
  • Loading branch information
MohamedAbdeen21 committed Jul 13, 2024
1 parent 2fb8c3d commit 4fc036a
Showing 1 changed file with 26 additions and 24 deletions.
50 changes: 26 additions & 24 deletions datafusion/sql/src/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,18 @@ use datafusion_expr::{
cast, col, Analyze, CreateCatalog, CreateCatalogSchema,
CreateExternalTable as PlanCreateExternalTable, CreateFunction, CreateFunctionBody,
CreateMemoryTable, CreateView, DescribeTable, DmlStatement, DropCatalogSchema,
DropFunction, DropTable, DropView, EmptyRelation, Explain, Expr, ExprSchemable,
Filter, LogicalPlan, LogicalPlanBuilder, OperateFunctionArg, PlanType, Prepare,
SetVariable, Statement as PlanStatement, ToStringifiedPlan, TransactionAccessMode,
DropFunction, DropTable, DropView, EmptyRelation, Explain, ExprSchemable, Filter,
LogicalPlan, LogicalPlanBuilder, OperateFunctionArg, PlanType, Prepare, SetVariable,
Statement as PlanStatement, ToStringifiedPlan, TransactionAccessMode,
TransactionConclusion, TransactionEnd, TransactionIsolationLevel, TransactionStart,
Volatility, WriteOp,
};
use sqlparser::ast;
use sqlparser::ast::{self, AssignmentTarget, CreateTable};
use sqlparser::ast::{
Assignment, AssignmentTarget, ColumnDef, CreateTable, CreateTableOptions, Delete,
DescribeAlias, Expr as SQLExpr, FromTable, Ident, Insert, ObjectName, ObjectType,
OneOrManyWithParens, Query, SchemaName, SetExpr, ShowCreateObject,
ShowStatementFilter, Statement, TableConstraint, TableFactor, TableWithJoins,
TransactionMode, UnaryOperator, Value,
Assignment, ColumnDef, CreateTableOptions, Delete, DescribeAlias, Expr as SQLExpr,
Expr, FromTable, Ident, Insert, ObjectName, ObjectType, OneOrManyWithParens, Query,
SchemaName, SetExpr, ShowCreateObject, ShowStatementFilter, Statement,
TableConstraint, TableFactor, TableWithJoins, TransactionMode, UnaryOperator, Value,
};
use sqlparser::parser::ParserError::ParserError;

Expand Down Expand Up @@ -955,7 +954,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
order_exprs: Vec<LexOrdering>,
schema: &DFSchemaRef,
planner_context: &mut PlannerContext,
) -> Result<Vec<Vec<Expr>>> {
) -> Result<Vec<Vec<datafusion_expr::Expr>>> {
// Ask user to provide a schema if schema is empty.
if !order_exprs.is_empty() && schema.fields().is_empty() {
return plan_err!(
Expand Down Expand Up @@ -1160,7 +1159,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
local: bool,
hivevar: bool,
variables: &OneOrManyWithParens<ObjectName>,
value: Vec<SQLExpr>,
value: Vec<Expr>,
) -> Result<LogicalPlan> {
if local {
return not_impl_err!("LOCAL is not supported");
Expand Down Expand Up @@ -1219,7 +1218,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
fn delete_to_plan(
&self,
table_name: ObjectName,
predicate_expr: Option<SQLExpr>,
predicate_expr: Option<Expr>,
) -> Result<LogicalPlan> {
// Do a table lookup to verify the table exists
let table_ref = self.object_name_to_table_reference(table_name.clone())?;
Expand Down Expand Up @@ -1265,7 +1264,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
table: TableWithJoins,
assignments: Vec<Assignment>,
from: Option<TableWithJoins>,
predicate_expr: Option<SQLExpr>,
predicate_expr: Option<Expr>,
) -> Result<LogicalPlan> {
let (table_name, table_alias) = match &table.relation {
TableFactor::Table { name, alias, .. } => (name.clone(), alias.clone()),
Expand Down Expand Up @@ -1298,7 +1297,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
table_schema.field_with_unqualified_name(&col_name.value)?;
Ok((col_name.value.clone(), assign.value.clone()))
})
.collect::<Result<HashMap<String, SQLExpr>>>()?;
.collect::<Result<HashMap<String, Expr>>>()?;

// Build scan, join with from table if it exists.
let mut input_tables = vec![table];
Expand Down Expand Up @@ -1337,7 +1336,8 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
&mut planner_context,
)?;
// Update placeholder's datatype to the type of the target column
if let Expr::Placeholder(placeholder) = &mut expr {
if let datafusion_expr::Expr::Placeholder(placeholder) = &mut expr
{
placeholder.data_type = placeholder
.data_type
.take()
Expand All @@ -1349,12 +1349,14 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
None => {
// If the target table has an alias, use it to qualify the column name
if let Some(alias) = &table_alias {
Expr::Column(Column::new(
datafusion_expr::Expr::Column(Column::new(
Some(self.normalizer.normalize(alias.name.clone())),
field.name(),
))
} else {
Expr::Column(Column::from((qualifier, field)))
datafusion_expr::Expr::Column(Column::from((
qualifier, field,
)))
}
}
};
Expand Down Expand Up @@ -1429,7 +1431,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
if let SetExpr::Values(ast::Values { rows, .. }) = (*source.body).clone() {
for row in rows.iter() {
for (idx, val) in row.iter().enumerate() {
if let SQLExpr::Value(Value::Placeholder(name)) = val {
if let ast::Expr::Value(Value::Placeholder(name)) = val {
let name =
name.replace('$', "").parse::<usize>().map_err(|_| {
plan_datafusion_err!("Can't parse placeholder: {name}")
Expand Down Expand Up @@ -1462,23 +1464,23 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
.map(|(i, value_index)| {
let target_field = table_schema.field(i);
let expr = match value_index {
Some(v) => {
Expr::Column(Column::from(source.schema().qualified_field(v)))
.cast_to(target_field.data_type(), source.schema())?
}
Some(v) => datafusion_expr::Expr::Column(Column::from(
source.schema().qualified_field(v),
))
.cast_to(target_field.data_type(), source.schema())?,
// The value is not specified. Fill in the default value for the column.
None => table_source
.get_column_default(target_field.name())
.cloned()
.unwrap_or_else(|| {
// If there is no default for the column, then the default is NULL
Expr::Literal(ScalarValue::Null)
datafusion_expr::Expr::Literal(ScalarValue::Null)
})
.cast_to(target_field.data_type(), &DFSchema::empty())?,
};
Ok(expr.alias(target_field.name()))
})
.collect::<Result<Vec<Expr>>>()?;
.collect::<Result<Vec<datafusion_expr::Expr>>>()?;
let source = project(source, exprs)?;

let op = if overwrite {
Expand Down

0 comments on commit 4fc036a

Please sign in to comment.