jayzhan211 commented on code in PR #9249:
URL: https://github.com/apache/arrow-datafusion/pull/9249#discussion_r1537533757


##########
datafusion/core/tests/user_defined/user_defined_aggregates.rs:
##########
@@ -209,6 +211,102 @@ async fn execute(ctx: &SessionContext, sql: &str) -> 
Result<Vec<RecordBatch>> {
     ctx.sql(sql).await?.collect().await
 }
 
+#[tokio::test]
+async fn simple_udaf_order() -> Result<()> {
+    let schema = Schema::new(vec![
+        Field::new("a", DataType::Int32, false),
+        Field::new("b", DataType::Int32, false),
+    ]);
+
+    let batch = RecordBatch::try_new(
+        Arc::new(schema.clone()),
+        vec![
+            Arc::new(Int32Array::from(vec![1, 2, 3, 4])),
+            Arc::new(Int32Array::from(vec![1, 1, 2, 2])),
+        ],
+    )?;
+
+    let ctx = SessionContext::new();
+
+    let provider = MemTable::try_new(Arc::new(schema.clone()), 
vec![vec![batch]])?;
+    ctx.register_table("t", Arc::new(provider))?;
+
+    fn create_accumulator(
+        data_type: &DataType,
+        order_by: &[Expr],
+        schema: &Schema,
+    ) -> Result<Box<dyn Accumulator>> {
+        let mut all_sort_orders = vec![];
+
+        // Construct PhysicalSortExpr objects from Expr objects:
+        let mut sort_exprs = vec![];
+        for expr in order_by {
+            if let Expr::Sort(sort) = expr {
+                if let Expr::Column(col) = sort.expr.as_ref() {
+                    let name = &col.name;
+                    let e = expressions::col(name, schema)?;
+                    sort_exprs.push(PhysicalSortExpr {
+                        expr: e,
+                        options: SortOptions {
+                            descending: !sort.asc,
+                            nulls_first: sort.nulls_first,
+                        },
+                    });
+                }
+            }
+        }
+        if !sort_exprs.is_empty() {
+            all_sort_orders.extend(sort_exprs);
+        }
+
+        let ordering_req = all_sort_orders;
+
+        let ordering_dtypes = ordering_req
+            .iter()
+            .map(|e| e.expr.data_type(schema))
+            .collect::<Result<Vec<_>>>()?;
+
+        let acc = FirstValueAccumulator::try_new(
+            data_type,
+            &ordering_dtypes,
+            ordering_req,
+            false,

Review Comment:
   `is_nulls` or other arguments are given in accumulator provided from the 
user.



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