jayzhan211 commented on code in PR #10214:
URL: https://github.com/apache/datafusion/pull/10214#discussion_r1577964818


##########
datafusion/core/tests/user_defined/user_defined_aggregates.rs:
##########
@@ -795,3 +798,87 @@ impl GroupsAccumulator for TestGroupsAccumulator {
         std::mem::size_of::<u64>()
     }
 }
+
+#[derive(Clone)]
+struct TestReverseUDAF {
+    signature: Signature,
+}
+
+impl Debug for TestReverseUDAF {
+    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
+        f.debug_struct("TestReverseUDAF")
+            .field("name", &self.name())
+            .field("signature", self.signature())
+            .finish()
+    }
+}
+
+impl AggregateUDFImpl for TestReverseUDAF {
+    fn as_any(&self) -> &dyn std::any::Any {
+        self
+    }
+
+    fn name(&self) -> &str {
+        "test_reverse"
+    }
+
+    fn signature(&self) -> &Signature {
+        &self.signature
+    }
+
+    fn return_type(&self, _arg_types: &[DataType]) -> Result<DataType> {
+        Ok(DataType::Float64)
+    }
+
+    fn accumulator(&self, _acc_args: AccumulatorArgs) -> Result<Box<dyn 
Accumulator>> {
+        todo!("no need")
+    }
+
+    fn state_fields(
+        &self,
+        _name: &str,
+        _value_type: DataType,
+        _ordering_fields: Vec<Field>,
+    ) -> Result<Vec<Field>> {
+        Ok(vec![])
+    }
+
+    fn reverse_expr(&self) -> ReversedExpr {
+        ReversedExpr::Reversed(AggregateFunction::new_udf(
+            Arc::new(self.clone().into()),
+            vec![],
+            false,
+            None,
+            None,
+            Some(NullTreatment::RespectNulls),
+        ))
+    }
+}
+
+/// tests the creation, registration and usage of a UDAF
+#[tokio::test]
+async fn test_reverse_udaf() -> Result<()> {
+    let my_reverse = AggregateUDF::from(TestReverseUDAF {
+        signature: Signature::exact(vec![], Volatility::Immutable),
+    });
+
+    let empty_schema = Schema::empty();
+    let e = create_aggregate_expr(
+        &my_reverse,
+        &[],
+        &[],
+        &[],
+        &empty_schema,
+        "test_reverse_udaf",
+        true,
+    )?;
+
+    // TODO: We don't have a nice way to test the change without introducing 
many other things
+    // We check with the output string. `ignore nulls` is expeceted to be 
false.

Review Comment:
   I think we can even remove this if first/last are moved to UDAF based.



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

Reply via email to