davisp commented on code in PR #1145:
URL: 
https://github.com/apache/datafusion-python/pull/1145#discussion_r2157354951


##########
examples/datafusion-ffi-example/python/tests/_test_aggregate_udf.py:
##########
@@ -0,0 +1,77 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from __future__ import annotations
+
+import pyarrow as pa
+from datafusion import SessionContext, col, udaf
+from datafusion_ffi_example import MySumUDF
+
+
+def setup_context_with_table():
+    ctx = SessionContext()
+
+    # Pick numbers here so we get the same value in both groups
+    # since we cannot be certain of the output order of batches
+    batch = pa.RecordBatch.from_arrays(
+        [
+            pa.array([1, 2, 3, None], type=pa.int64()),
+            pa.array([1, 1, 2, 2], type=pa.int64()),
+        ],
+        names=["a", "b"],
+    )
+    ctx.register_record_batches("test_table", [[batch]])
+    return ctx
+
+
+def test_ffi_aggregate_register():
+    ctx = setup_context_with_table()
+    my_udaf = udaf(MySumUDF())
+    ctx.register_udaf(my_udaf)
+
+    result = ctx.sql("select my_custom_sum(a) from test_table group by 
b").collect()
+
+    assert len(result) == 2
+    assert result[0].num_columns == 1
+
+    result = [r.column(0) for r in result]
+    expected = [
+        pa.array([3], type=pa.int64()),
+        pa.array([3], type=pa.int64()),

Review Comment:
   Completely unrelated to this PR, but why isn't this `null` instead of 3?
   
   ```
   > select 1 + null;
   +-----------------+
   | Int64(1) + NULL |
   +-----------------+
   |                 |
   +-----------------+
   1 row(s) fetched.
   Elapsed 0.004 seconds.
   ```
   
   I'm more than open to the possibility that the group by has a subtly 
different behavior than normal addition, but it just caught me by surprise 
because I expected to see `null` there. Poking a bit, none of the other 
aggregates I thought of off the top of my head return `null` so I guess its at 
least consistent.
   
   Anywho, just a curiosity while I was reviewing.



-- 
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: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to