princejain756 commented on issue #26620: URL: https://github.com/apache/datafusion/issues/26620#issuecomment-6370831473
I tracked this down to `ExprCSEController` in `common_subexpr_eliminate.rs`: when `simplify_expressions` folds `1 + 1`, it wraps that window expression in an outer `Alias` to preserve its display name, while the sibling `sum(b) OVER (ORDER BY a + 1)` has no outer `Alias`. Because `ExprCSEController` only incremented `alias_counter` on `Expr::Alias`, the extracted `ORDER BY` sort key under the unaliased window expression received a name-preserving alias (`__common_expr_1 AS t.a + Int64(1)`) while the aliased sibling received bare `__common_expr_1`, tripping the debug assertion in `DefaultPhysicalPlanner`. Treating `Expr::WindowFunction` as a name-preservation boundary alongside `Expr::Alias` (since `try_optimize_window` already wraps each window expression with `NamePreserver`) makes all children inside a window expression emit bare `__common_expr_*` references. I have a tested patch and regression tests ready on [`fix-window-cse-sort-keys`](https://github.com/princejain756/datafusion/commit/52a96bb253dda3b91814faf108c69f3d480edd81) if you'd like me to open a PR. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
