peter-toth commented on code in PR #10396: URL: https://github.com/apache/datafusion/pull/10396#discussion_r1591489991
########## datafusion/optimizer/src/common_subexpr_eliminate.rs: ########## @@ -471,37 +471,56 @@ fn pop_expr(new_expr: &mut Vec<Vec<Expr>>) -> Result<Vec<Expr>> { .ok_or_else(|| DataFusionError::Internal("Failed to pop expression".to_string())) } +fn to_arrays( + expr: &[Expr], + input_schema: DFSchemaRef, + expr_stats: &mut ExprStats, + expr_mask: ExprMask, +) -> Result<Vec<Vec<(usize, String)>>> { + expr.iter() + .map(|e| { + let mut id_array = vec![]; + expr_to_identifier( + e, + expr_stats, + &mut id_array, + Arc::clone(&input_schema), + expr_mask, + )?; + + Ok(id_array) + }) + .collect::<Result<Vec<_>>>() +} + /// Build the "intermediate" projection plan that evaluates the extracted common /// expressions. /// /// # Arguments /// input: the input plan /// -/// affected_id: which common subexpressions were used (and thus are added to +/// common_exprs: which common subexpressions were used (and thus are added to /// intermediate projection) /// -/// expr_set: the set of common subexpressions +/// expr_stats: the set of common subexpressions fn build_common_expr_project_plan( input: LogicalPlan, - affected_id: BTreeSet<Identifier>, - expr_set: &ExprSet, + common_exprs: IndexMap<Identifier, Expr>, + expr_stats: &ExprStats, ) -> Result<LogicalPlan> { - let mut project_exprs = vec![]; let mut fields_set = BTreeSet::new(); - - for id in affected_id { - match expr_set.get(&id) { - Some((expr, _, data_type, symbol)) => { - // todo: check `nullable` - let field = Field::new(&id, data_type.clone(), true); - fields_set.insert(field.name().to_owned()); - project_exprs.push(expr.clone().alias(symbol.as_str())); Review Comment: this clone is also eliminated -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org