MichaelScofield commented on code in PR #4553:
URL: https://github.com/apache/arrow-datafusion/pull/4553#discussion_r1045378304


##########
datafusion/sql/src/planner.rs:
##########
@@ -2408,6 +2406,21 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
         }
     }
 
+    fn find_window_func(&self, name: &str) -> Result<WindowFunction> {
+        window_function::find_df_window_func(name)

Review Comment:
   Yes, I think built-in functions are always take higher precedence to UDAFs.



##########
datafusion/core/src/physical_plan/windows/mod.rs:
##########
@@ -180,6 +188,81 @@ mod tests {
         Ok((csv, schema))
     }
 
+    #[tokio::test]
+    async fn window_function_with_udaf() -> Result<()> {
+        #[derive(Debug)]
+        struct MyCount(i64);
+
+        impl Accumulator for MyCount {
+            fn state(&self) -> Result<Vec<AggregateState>> {
+                Ok(vec![AggregateState::Scalar(ScalarValue::Int64(Some(
+                    self.0,
+                )))])
+            }
+
+            fn update_batch(&mut self, values: &[ArrayRef]) -> Result<()> {
+                let array = &values[0];
+                self.0 += (array.len() - array.data().null_count()) as i64;
+                Ok(())
+            }
+
+            fn merge_batch(&mut self, states: &[ArrayRef]) -> Result<()> {
+                let counts = downcast_value!(states[0], Int64Array);
+                if let Some(c) = &arrow::compute::sum(counts) {
+                    self.0 += *c;
+                }
+                Ok(())
+            }
+
+            fn evaluate(&self) -> Result<ScalarValue> {
+                Ok(ScalarValue::Int64(Some(self.0)))
+            }
+
+            fn size(&self) -> usize {
+                std::mem::size_of_val(self)
+            }
+        }
+
+        let my_count = create_udaf(
+            "my_count",
+            DataType::Int64,
+            Arc::new(DataType::Int64),
+            Volatility::Immutable,
+            Arc::new(|_| Ok(Box::new(MyCount(0)))),
+            Arc::new(vec![DataType::Int64]),
+        );
+
+        let session_ctx = SessionContext::new();
+        let task_ctx = session_ctx.task_ctx();
+        let (input, schema) = create_test_schema(1)?;
+
+        let window_exec = Arc::new(WindowAggExec::try_new(

Review Comment:
   thx!



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