alamb commented on code in PR #14888: URL: https://github.com/apache/datafusion/pull/14888#discussion_r1971708109
########## datafusion/optimizer/src/simplify_expressions/simplify_exprs.rs: ########## @@ -122,14 +123,21 @@ impl SimplifyExpressions { // Preserve expression names to avoid changing the schema of the plan. let name_preserver = NamePreserver::new(&plan); - plan.map_expressions(|e| { - let original_name = name_preserver.save(&e); - let new_e = simplifier - .simplify(e) - .map(|expr| original_name.restore(expr))?; + let mut rewrite_expr = |expr: Expr| { + let name = name_preserver.save(&expr); + let expr = simplifier.simplify(expr)?; // TODO it would be nice to have a way to know if the expression was simplified // or not. For now conservatively return Transformed::yes - Ok(Transformed::yes(new_e)) + Ok(Transformed::yes(name.restore(expr))) + }; + + plan.map_expressions(|expr| { + // Preserve the aliasing of grouping sets. Review Comment: > What makes you think so? I was thinking that the code skips calling `rewrite_expr` (which calls name preserver) for the GroupingSets (so thus does not preserve the aliases of the `Expr::Grouping` itself ########## datafusion/optimizer/src/simplify_expressions/simplify_exprs.rs: ########## @@ -122,14 +123,21 @@ impl SimplifyExpressions { // Preserve expression names to avoid changing the schema of the plan. let name_preserver = NamePreserver::new(&plan); - plan.map_expressions(|e| { - let original_name = name_preserver.save(&e); - let new_e = simplifier - .simplify(e) - .map(|expr| original_name.restore(expr))?; + let mut rewrite_expr = |expr: Expr| { + let name = name_preserver.save(&expr); + let expr = simplifier.simplify(expr)?; // TODO it would be nice to have a way to know if the expression was simplified // or not. For now conservatively return Transformed::yes - Ok(Transformed::yes(new_e)) + Ok(Transformed::yes(name.restore(expr))) + }; + + plan.map_expressions(|expr| { + // Preserve the aliasing of grouping sets. Review Comment: > What makes you think so? I was thinking that the code skips calling `rewrite_expr` (which calls name preserver) for the GroupingSets (so thus does not preserve the aliases of the `Expr::Grouping` itself To be clear I think the code in PR looks good to me, I am just discussing if we can make the comment better ########## datafusion/optimizer/src/simplify_expressions/simplify_exprs.rs: ########## @@ -122,14 +123,21 @@ impl SimplifyExpressions { // Preserve expression names to avoid changing the schema of the plan. let name_preserver = NamePreserver::new(&plan); - plan.map_expressions(|e| { - let original_name = name_preserver.save(&e); - let new_e = simplifier - .simplify(e) - .map(|expr| original_name.restore(expr))?; + let mut rewrite_expr = |expr: Expr| { + let name = name_preserver.save(&expr); + let expr = simplifier.simplify(expr)?; // TODO it would be nice to have a way to know if the expression was simplified // or not. For now conservatively return Transformed::yes - Ok(Transformed::yes(new_e)) + Ok(Transformed::yes(name.restore(expr))) + }; + + plan.map_expressions(|expr| { + // Preserve the aliasing of grouping sets. Review Comment: > What makes you think so? I was thinking that the code skips calling `rewrite_expr` (which calls name preserver) for the GroupingSets (so thus does not preserve the aliases of the `Expr::Grouping` itself -- 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