peter-toth commented on code in PR #10473: URL: https://github.com/apache/datafusion/pull/10473#discussion_r1650118870
########## datafusion/optimizer/src/common_subexpr_eliminate.rs: ########## @@ -118,21 +137,86 @@ type CommonExprs = IndexMap<Identifier, (Expr, String)>; /// ProjectionExec(exprs=[extract (day from new_col), extract (year from new_col)]) <-- reuse here /// ProjectionExec(exprs=[to_date(c1) as new_col]) <-- compute to_date once /// ``` -pub struct CommonSubexprEliminate {} +pub struct CommonSubexprEliminate { + random_state: RandomState, +} impl CommonSubexprEliminate { + pub fn new() -> Self { + Self { + random_state: RandomState::new(), + } + } + + /// Returns the identifier list for each element in `exprs` and a flag to indicate if + /// rewrite phase of CSE make sense. + /// + /// Returns and array with 1 element for each input expr in `exprs` + /// + /// Each element is itself the result of [`CommonSubexprEliminate::expr_to_identifier`] for that expr + /// (e.g. the identifiers for each node in the tree) + fn to_arrays<'n>( + &self, + exprs: &'n [Expr], + expr_stats: &mut ExprStats<'n>, + expr_mask: ExprMask, + ) -> Result<(bool, Vec<IdArray<'n>>)> { + let mut found_common = false; + exprs + .iter() + .map(|e| { + let mut id_array = vec![]; + self.expr_to_identifier(e, expr_stats, &mut id_array, expr_mask) + .map(|fc| { + found_common |= fc; + + id_array + }) + }) + .collect::<Result<Vec<_>>>() + .map(|id_arrays| (found_common, id_arrays)) + } + + /// Go through an expression tree and generate identifier for every node in this tree. Review Comment: Fixed in https://github.com/apache/datafusion/commit/ee61224f1a948c38ac99ae53d9d426bb69da9548. -- 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