diff --git a/datafusion/expr/src/logical_plan/plan.rs b/datafusion/expr/src/logical_plan/plan.rs index a6ba1c96154f..5c93bb6f2d8b 100644 --- a/datafusion/expr/src/logical_plan/plan.rs +++ b/datafusion/expr/src/logical_plan/plan.rs @@ -24,8 +24,7 @@ use crate::logical_plan::display::{GraphvizVisitor, IndentVisitor}; use crate::logical_plan::extension::UserDefinedLogicalNode; use crate::logical_plan::plan; use crate::utils::{ - self, exprlist_to_fields, from_plan, grouping_set_expr_count, - grouping_set_to_exprlist, + exprlist_to_fields, from_plan, grouping_set_expr_count, grouping_set_to_exprlist, }; use crate::{ build_join_schema, Expr, ExprSchemable, TableProviderFilterPushDown, TableSource, @@ -632,22 +631,21 @@ impl LogicalPlan { /// params_values pub fn replace_params_with_values( &self, - param_values: &Vec, + param_values: &[ScalarValue], ) -> Result { - let exprs = self.expressions(); - let mut new_exprs = vec![]; - for expr in exprs { - new_exprs.push(Self::replace_placeholders_with_values(expr, param_values)?); - } + let new_exprs = self + .expressions() + .into_iter() + .map(|e| Self::replace_placeholders_with_values(e, param_values)) + .collect::, DataFusionError>>()?; - let new_inputs = self.inputs(); - let mut new_inputs_with_values = vec![]; - for input in new_inputs { - new_inputs_with_values.push(input.replace_params_with_values(param_values)?); - } + let new_inputs_with_values = self + .inputs() + .into_iter() + .map(|inp| inp.replace_params_with_values(param_values)) + .collect::, DataFusionError>>()?; - let new_plan = utils::from_plan(self, &new_exprs, &new_inputs_with_values)?; - Ok(new_plan) + from_plan(self, &new_exprs, &new_inputs_with_values) } /// Walk the logical plan, find any `PlaceHolder` tokens, and return a map of their IDs and DataTypes @@ -748,10 +746,8 @@ impl LogicalPlan { Ok(Expr::Literal(value.clone())) } Expr::ScalarSubquery(qry) => { - let subquery = Arc::new( - qry.subquery - .replace_params_with_values(¶m_values.to_vec())?, - ); + let subquery = + Arc::new(qry.subquery.replace_params_with_values(param_values)?); Ok(Expr::ScalarSubquery(plan::Subquery { subquery })) } _ => Ok(expr),