From 049c59d611461d360239a090c8c294dfe3939b53 Mon Sep 17 00:00:00 2001 From: Xin Li Date: Thu, 18 Jul 2024 10:06:10 +0800 Subject: [PATCH] Fix comments --- .../optimizer/src/analyzer/type_coercion.rs | 18 +++++++++--------- datafusion/physical-plan/src/filter.rs | 3 ++- datafusion/sqllogictest/test_files/misc.slt | 1 + 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/datafusion/optimizer/src/analyzer/type_coercion.rs b/datafusion/optimizer/src/analyzer/type_coercion.rs index 913667eb0342..337492d1a55b 100644 --- a/datafusion/optimizer/src/analyzer/type_coercion.rs +++ b/datafusion/optimizer/src/analyzer/type_coercion.rs @@ -47,9 +47,8 @@ use datafusion_expr::type_coercion::{is_datetime, is_utf8_or_large_utf8}; use datafusion_expr::utils::merge_schema; use datafusion_expr::{ is_false, is_not_false, is_not_true, is_not_unknown, is_true, is_unknown, not, - type_coercion, AggregateFunction, AggregateUDF, Expr, ExprSchemable, Filter, - LogicalPlan, Operator, ScalarUDF, Signature, WindowFrame, WindowFrameBound, - WindowFrameUnits, + type_coercion, AggregateFunction, AggregateUDF, Expr, ExprSchemable, LogicalPlan, + Operator, ScalarUDF, Signature, WindowFrame, WindowFrameBound, WindowFrameUnits, }; use crate::analyzer::AnalyzerRule; @@ -104,12 +103,13 @@ 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 Ok(predicate) = predicate.clone().cast_to(&DataType::Boolean, &schema) { - plan = LogicalPlan::Filter(Filter::try_new(predicate, Arc::clone(input))?); + if let LogicalPlan::Filter(filter) = &mut plan { + if let Ok(new_predicate) = filter + .predicate + .clone() + .cast_to(&DataType::Boolean, filter.input.schema()) + { + filter.predicate = new_predicate; } } diff --git a/datafusion/physical-plan/src/filter.rs b/datafusion/physical-plan/src/filter.rs index 5455bdc55947..a9d78d059f5c 100644 --- a/datafusion/physical-plan/src/filter.rs +++ b/datafusion/physical-plan/src/filter.rs @@ -355,13 +355,14 @@ pub(crate) fn batch_filter( .and_then(|v| v.into_array(batch.num_rows())) .and_then(|array| { Ok(match as_boolean_array(&array) { + // apply filter array to record batch Ok(filter_array) => filter_record_batch(batch, filter_array)?, Err(_) => { return internal_err!( "Cannot create filter_array from non-boolean predicates" ); } - }) // apply filter array to record batch + }) }) } diff --git a/datafusion/sqllogictest/test_files/misc.slt b/datafusion/sqllogictest/test_files/misc.slt index 666a69d9169d..9f4710eb9bcc 100644 --- a/datafusion/sqllogictest/test_files/misc.slt +++ b/datafusion/sqllogictest/test_files/misc.slt @@ -25,6 +25,7 @@ select 'foo', '', NULL ---- foo (empty) NULL +# Where clause accept NULL literal query I select 1 where NULL ----