jonahgao commented on code in PR #15033:
URL: https://github.com/apache/datafusion/pull/15033#discussion_r2029886625
##########
datafusion/sql/src/select.rs:
##########
@@ -891,29 +892,42 @@ fn match_window_definitions(
named_windows: &[NamedWindowDefinition],
) -> Result<()> {
for proj in projection.iter_mut() {
- if let SelectItem::ExprWithAlias {
- expr: SQLExpr::Function(f),
- alias: _,
- }
- | SelectItem::UnnamedExpr(SQLExpr::Function(f)) = proj
+ if let SelectItem::ExprWithAlias { expr, alias: _ }
+ | SelectItem::UnnamedExpr(expr) = proj
{
- for NamedWindowDefinition(window_ident, window_expr) in
named_windows.iter() {
- if let Some(WindowType::NamedWindow(ident)) = &f.over {
- if ident.eq(window_ident) {
- f.over = Some(match window_expr {
- NamedWindowExpr::NamedWindow(ident) => {
- WindowType::NamedWindow(ident.clone())
- }
- NamedWindowExpr::WindowSpec(spec) => {
- WindowType::WindowSpec(spec.clone())
+ let mut err = None;
+ visit_expressions_mut(expr, |expr| {
+ if let SQLExpr::Function(f) = expr {
+ if let Some(WindowType::NamedWindow(_)) = &f.over {
+ for NamedWindowDefinition(window_ident, window_expr) in
+ named_windows
+ {
+ if let Some(WindowType::NamedWindow(ident)) =
&f.over {
+ if ident.eq(window_ident) {
Review Comment:
Unrelated to the current fix, we should compare them using normalized names
to support
```sql
SELECT
t1.v1,
SUM(t1.v1) OVER W + 1
FROM
generate_series(1, 5) AS t1(v1)
WINDOW
w AS (ORDER BY t1.v1);
```
--
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]