berkaysynnada commented on code in PR #6419:
URL: https://github.com/apache/arrow-datafusion/pull/6419#discussion_r1205060247


##########
datafusion/sql/src/select.rs:
##########
@@ -70,10 +71,37 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
         // process `where` clause
         let plan = self.plan_selection(select.selection, plan, 
planner_context)?;
 
+        // handle named windows before processing the projection expression
+        let mut modified_projection = select.projection.clone();
+        // If the projection is done over a named window, that window
+        // name must be defined. Otherwise, it gives an error.
+        for proj in modified_projection.iter_mut() {
+            if let SelectItem::ExprWithAlias {
+                expr: SQLExpr::Function(f),
+                alias: _,
+            } = proj
+            {
+                for NamedWindowDefinition(window_ident, window_spec) in
+                    select.named_window.iter()
+                {
+                    if let Some(WindowType::NamedWindow(ident)) = &f.over {
+                        if ident.eq(window_ident) {
+                            f.over = 
Some(WindowType::WindowSpec(window_spec.clone()))
+                        }
+                    }
+                }
+                // All named windows must be defined with a WindowSpec.

Review Comment:
   I have checked, it says "Query Error: error: window "window3" is already 
defined"



-- 
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]

Reply via email to