Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* revert: from_plan keep same schema Project in apache#6595

* revert: from_plan keep same schema Agg/Window in apache#6820

* revert type coercion

* add comment
  • Loading branch information
jackwener authored and yukkit committed Jul 10, 2023
1 parent b3a8ab9 commit 0a2fe02
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
8 changes: 2 additions & 6 deletions datafusion/common/src/dfschema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,12 +384,8 @@ impl DFSchema {
let self_fields = self.fields().iter();
let other_fields = other.fields().iter();
self_fields.zip(other_fields).all(|(f1, f2)| {
// TODO: resolve field when exist alias
// f1.qualifier() == f2.qualifier()
// && f1.name() == f2.name()
// column(t1.a) field is "t1"."a"
// column(x) as t1.a field is ""."t1.a"
f1.qualified_name() == f2.qualified_name()
f1.qualifier() == f2.qualifier()
&& f1.name() == f2.name()
&& Self::datatype_is_semantically_equal(f1.data_type(), f2.data_type())
})
}
Expand Down
14 changes: 10 additions & 4 deletions datafusion/expr/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -725,16 +725,22 @@ where
/// // create new plan using rewritten_exprs in same position
/// let new_plan = from_plan(&plan, rewritten_exprs, new_inputs);
/// ```
///
/// Notice: sometimes [from_plan] will use schema of original plan, it don't change schema!
/// Such as `Projection/Aggregate/Window`
pub fn from_plan(
plan: &LogicalPlan,
expr: &[Expr],
inputs: &[LogicalPlan],
) -> Result<LogicalPlan> {
match plan {
LogicalPlan::Projection(_) => Ok(LogicalPlan::Projection(Projection::try_new(
expr.to_vec(),
Arc::new(inputs[0].clone()),
)?)),
LogicalPlan::Projection(Projection { schema, .. }) => {
Ok(LogicalPlan::Projection(Projection::try_new_with_schema(
expr.to_vec(),
Arc::new(inputs[0].clone()),
schema.clone(),
)?))
}
LogicalPlan::Dml(DmlStatement {
table_name,
table_schema,
Expand Down
11 changes: 9 additions & 2 deletions datafusion/optimizer/src/analyzer/type_coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ use datafusion_expr::utils::from_plan;
use datafusion_expr::{
aggregate_function, is_false, is_not_false, is_not_true, is_not_unknown, is_true,
is_unknown, type_coercion, AggregateFunction, BuiltinScalarFunction, Expr,
LogicalPlan, Operator, WindowFrame, WindowFrameBound, WindowFrameUnits,
LogicalPlan, Operator, Projection, WindowFrame, WindowFrameBound, WindowFrameUnits,
};
use datafusion_expr::{ExprSchemable, Signature};

Expand Down Expand Up @@ -109,7 +109,14 @@ fn analyze_internal(
})
.collect::<Result<Vec<_>>>()?;

from_plan(plan, &new_expr, &new_inputs)
// TODO: from_plan can't change the schema, so we need to do this here
match &plan {
LogicalPlan::Projection(_) => Ok(LogicalPlan::Projection(Projection::try_new(
new_expr,
Arc::new(new_inputs[0].clone()),
)?)),
_ => from_plan(plan, &new_expr, &new_inputs),
}
}

pub(crate) struct TypeCoercionRewriter {
Expand Down

0 comments on commit 0a2fe02

Please sign in to comment.