alamb commented on code in PR #6769:
URL: https://github.com/apache/arrow-datafusion/pull/6769#discussion_r1246911303


##########
datafusion/proto/src/logical_plan/mod.rs:
##########
@@ -2786,12 +2788,155 @@ mod roundtrip_tests {
             vec![col("col1")],
             vec![col("col1")],
             vec![col("col2")],
+            row_number_frame.clone(),
+        ));
+
+        // 5. test with AggregateUDF
+        #[derive(Debug)]
+        struct Dummy {}
+
+        impl Accumulator for Dummy {
+            fn state(&self) -> datafusion::error::Result<Vec<ScalarValue>> {
+                Ok(vec![])
+            }
+
+            fn update_batch(
+                &mut self,
+                _values: &[ArrayRef],
+            ) -> datafusion::error::Result<()> {
+                Ok(())
+            }
+
+            fn merge_batch(
+                &mut self,
+                _states: &[ArrayRef],
+            ) -> datafusion::error::Result<()> {
+                Ok(())
+            }
+
+            fn evaluate(&self) -> datafusion::error::Result<ScalarValue> {
+                Ok(ScalarValue::Float64(None))
+            }
+
+            fn size(&self) -> usize {
+                std::mem::size_of_val(self)
+            }
+        }
+
+        let dummy_agg = create_udaf(
+            // the name; used to represent it in plan descriptions and in the 
registry, to use in SQL.
+            "dummy_agg",
+            // the input type; DataFusion guarantees that the first entry of 
`values` in `update` has this type.
+            DataType::Float64,
+            // the return type; DataFusion expects this to match the type 
returned by `evaluate`.
+            Arc::new(DataType::Float64),
+            Volatility::Immutable,
+            // This is the accumulator factory; DataFusion uses it to create 
new accumulators.
+            Arc::new(|_| Ok(Box::new(Dummy {}))),
+            // This is the description of the state. `state()` must match the 
types here.
+            Arc::new(vec![DataType::Float64, DataType::UInt32]),
+        );
+
+        let test_expr5 = Expr::WindowFunction(expr::WindowFunction::new(
+            WindowFunction::AggregateUDF(Arc::new(dummy_agg.clone())),
+            vec![col("col1")],
+            vec![col("col1")],
+            vec![col("col2")],
+            row_number_frame.clone(),
+        ));
+        ctx.register_udaf(dummy_agg);
+
+        // 6. test with WindowUDF
+        #[derive(Clone, Debug)]
+        struct MyPartitionEvaluator {}
+
+        impl MyPartitionEvaluator {
+            fn new() -> Self {
+                Self {}
+            }
+        }
+
+        /// Different evaluation methods are called depending on the various
+        /// settings of WindowUDF. This example uses the simplest and most
+        /// general, `evaluate`. See `PartitionEvaluator` for the other more
+        /// advanced uses.
+        impl PartitionEvaluator for MyPartitionEvaluator {
+            /// Tell DataFusion the window function varies based on the value
+            /// of the window frame.
+            fn uses_window_frame(&self) -> bool {
+                true
+            }
+
+            /// This function is called once per input row.
+            ///
+            /// `range`specifies which indexes of `values` should be
+            /// considered for the calculation.
+            ///
+            /// Note this is the SLOWEST, but simplest, way to evaluate a
+            /// window function. It is much faster to implement
+            /// evaluate_all or evaluate_all_with_rank, if possible
+            fn evaluate(
+                &mut self,
+                values: &[ArrayRef],
+                range: &std::ops::Range<usize>,
+            ) -> Result<ScalarValue> {
+                // Again, the input argument is an array of floating

Review Comment:
   Perhaps we can just use `todo!()` here and in the other functions? These 
should not be called during the logical plan testing



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