westonpace commented on code in PR #12590:
URL: https://github.com/apache/arrow/pull/12590#discussion_r842186517


##########
python/pyarrow/_compute.pyx:
##########
@@ -2182,3 +2255,175 @@ cdef CExpression _bind(Expression filter, Schema 
schema) except *:
 
     return GetResultValue(filter.unwrap().Bind(
         deref(pyarrow_unwrap_schema(schema).get())))
+
+
+cdef CFunctionDoc _make_function_doc(func_doc):
+    """
+    Helper function to generate the FunctionDoc
+    """
+    cdef:
+        CFunctionDoc f_doc
+        vector[c_string] c_arg_names
+        c_bool c_options_required
+    if func_doc and isinstance(func_doc, dict):
+        if func_doc["summary"] and isinstance(func_doc["summary"], str):
+            f_doc.summary = func_doc["summary"].encode()
+        else:
+            raise ValueError("key `summary` cannot be None")
+
+        if func_doc["description"] and isinstance(func_doc["description"], 
str):
+            f_doc.description = func_doc["description"].encode()
+        else:
+            raise ValueError("key `description` cannot be None")
+
+        if func_doc["arg_names"] and isinstance(func_doc["arg_names"], list):
+            for arg_name in func_doc["arg_names"]:
+                if isinstance(arg_name, str):
+                    c_arg_names.push_back(arg_name.encode())
+                else:
+                    raise ValueError(
+                        "key `arg_names` must be a list of strings")
+            f_doc.arg_names = c_arg_names
+        else:
+            raise ValueError("key `arg_names` cannot be None")
+
+        # UDFOptions integration:
+        # TODO: https://issues.apache.org/jira/browse/ARROW-16041
+        f_doc.options_class = tobytes("None")
+
+        c_options_required = False
+        f_doc.options_required = c_options_required
+
+        return f_doc
+    else:
+        raise ValueError(f"func_doc must be a dictionary")
+
+
+def register_function(func_name, num_args, function_doc, in_types,
+                      out_type, callback):
+    """
+    Register a user-defined-function
+
+    Parameters
+    ----------
+
+    func_name : str
+        function name 
+    num_args : int
+       number of arguments in the function
+    function_doc : dict
+        a dictionary object with keys 
+        ("summary", 
+        "description", 
+        "arg_names"
+        )
+    in_types : List[InputType]
+        list of InputType objects which defines the input 
+        types for the function
+    out_type : DataType
+        output type of the function
+    callback : callable
+        user defined function
+        function includes arguments equal to the number
+        of input_types defined. The return type of the 
+        function is of the type defined as output_type. 
+        The output is a datum object which can be
+        an Array or a ChunkedArray or a Table or a RecordBatch.

Review Comment:
   These need to be safe to use in a projection so the output can't be a 
`Table` or `RecordBatch` (also, maybe this function should be named 
`register_scalar_function` or `register_custom_projection` or something like 
that.



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