retikulum commented on code in PR #4553:
URL: https://github.com/apache/arrow-datafusion/pull/4553#discussion_r1044534130
##########
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);
Review Comment:
You can use `as_int64_array` for better downcasting schema as it is
discussed in #3152
--
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]