From 8178c24e40d4b21eb71da2c60a5efd7fa592e1e9 Mon Sep 17 00:00:00 2001 From: jackwener Date: Tue, 7 Feb 2023 11:33:00 +0800 Subject: [PATCH] bugfix: fix eval `nullalbe()` in` `simplify_exprs` --- .../src/simplify_expressions/simplify_exprs.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/datafusion/optimizer/src/simplify_expressions/simplify_exprs.rs b/datafusion/optimizer/src/simplify_expressions/simplify_exprs.rs index fe5d62c64a594..d7b2e1c3b2693 100644 --- a/datafusion/optimizer/src/simplify_expressions/simplify_exprs.rs +++ b/datafusion/optimizer/src/simplify_expressions/simplify_exprs.rs @@ -18,8 +18,9 @@ //! Simplify expressions optimizer rule and implementation use super::{ExprSimplifier, SimplifyContext}; +use crate::utils::merge_schema; use crate::{OptimizerConfig, OptimizerRule}; -use datafusion_common::Result; +use datafusion_common::{DFSchemaRef, Result}; use datafusion_expr::{logical_plan::LogicalPlan, utils::from_plan}; use datafusion_physical_expr::execution_props::ExecutionProps; @@ -59,13 +60,12 @@ impl SimplifyExpressions { plan: &LogicalPlan, execution_props: &ExecutionProps, ) -> Result { - // We need to pass down the all schemas within the plan tree to `optimize_expr` in order to - // to evaluate expression types. For example, a projection plan's schema will only include - // projected columns. With just the projected schema, it's not possible to infer types for - // expressions that references non-projected columns within the same project plan or its - // children plans. - let info = plan - .all_schemas() + // Pass down the `children merge schema` and `plan schema` to evaluate expression types. + // pass all `child schema` and `plan schema` isn't enough, because like `t1 semi join t2 on + // on t1.id = t2.id`, each individual schema cannot contain all the columns in it. + let children_merge_schema = DFSchemaRef::new(merge_schema(plan.inputs())); + let schemas = vec![plan.schema(), &children_merge_schema]; + let info = schemas .into_iter() .fold(SimplifyContext::new(execution_props), |context, schema| { context.with_schema(schema.clone())