Skip to content

Commit

Permalink
adopt comparison_coercion
Browse files Browse the repository at this point in the history
  • Loading branch information
xinlifoobar committed Jul 17, 2024
1 parent e739b1b commit 04a5f15
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions datafusion/optimizer/src/analyzer/type_coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,8 @@ impl AnalyzerRule for TypeCoercion {
/// Assumes that children have already been optimized
fn analyze_internal(
external_schema: &DFSchema,
plan: LogicalPlan,
mut plan: LogicalPlan,
) -> Result<Transformed<LogicalPlan>> {
if let LogicalPlan::Filter(Filter {
predicate, input, ..
}) = &plan
{
if predicate == &Expr::Literal(ScalarValue::Null) {
return Ok(Transformed::yes(LogicalPlan::Filter(Filter::try_new(
Expr::Literal(ScalarValue::Boolean(Some(false))),
Arc::clone(input),
)?)));
}
}

// get schema representing all available input fields. This is used for data type
// resolution only, so order does not matter here
let mut schema = merge_schema(plan.inputs());
Expand All @@ -116,6 +104,20 @@ fn analyze_internal(
// select t2.c2 from t1 where t1.c1 in (select t2.c1 from t2 where t2.c2=t1.c3)
schema.merge(external_schema);

if let LogicalPlan::Filter(Filter {
predicate, input, ..
}) = &plan
{
if let Some(boolean_type) =
comparison_coercion(&DataType::Boolean, &predicate.get_type(&schema)?)
{
if let Ok(predicate) = predicate.clone().cast_to(&boolean_type, &schema) {
plan =
LogicalPlan::Filter(Filter::try_new(predicate, Arc::clone(input))?);
}
};
}

let mut expr_rewrite = TypeCoercionRewriter::new(&schema);

let name_preserver = NamePreserver::new(&plan);
Expand Down

0 comments on commit 04a5f15

Please sign in to comment.