devinjdangelo commented on code in PR #10767: URL: https://github.com/apache/datafusion/pull/10767#discussion_r1623586842
########## datafusion/sql/src/unparser/utils.rs: ########## @@ -82,3 +91,28 @@ pub(crate) fn unproject_agg_exprs(expr: &Expr, agg: &Aggregate) -> Result<Expr> }) .map(|e| e.data) } + +/// Recursively identify all Column expressions and transform them into the appropriate +/// window expression contained in window. +/// +/// For example, if expr contains the column expr "COUNT(*) PARTITION BY id" it will be transformed +/// into an actual window expression as identified in the window node. +pub(crate) fn unproject_window_exprs(expr: &Expr, window: &Window) -> Result<Expr> { Review Comment: The difference I found is that the Aggregate structure maintains all of the relevant Exprs that a Projection node may be referencing in its group by and aggr expr vecs. So, you can look up any column in the schema of the aggregate plan to find the correct expression to sub into the Projection node. Window on the other hand only keeps the list of window functions whereas the schema has all of the fields. So its no longer possible to rely on the index of a column within the schema to find the correct expression. Instead, I am using the auto generated column name for the expression to identify the correct expression. This is definitely a more brittle way to do it and could break if there are unexpected changes to how names are generated or propagated during planning. -- 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