cube2222 commented on issue #36936:
URL: https://github.com/apache/arrow/issues/36936#issuecomment-1658933183

   > So, part of disallowing the external custom functions like that was just 
overlooking it as the interface grew and expanded while trying to keep people 
from shooting themselves in the foot. Another part of it was to try to 
encourage people to contribute functions back to the repo, lol.
   
   Hah, I guess that makes sense @zeroshade!
   
   Not sure if you have any specific vision on what should and what should not 
be exported, but based on the structures and interfaces required to register a 
function, it seems that it makes sense to just make the whole `exec` package 
module-public.
   
   In case that makes sense, here's a PR 
https://github.com/apache/arrow/pull/36959, but no hard feelings if you prefer 
to approach it differently.
   
   With this change registering functions from "userspace" works like a charm. 
Quick example:
   ```
        myFunc := compute.NewScalarFunction("papaya", compute.Arity{
                NArgs: 1,
        }, compute.FunctionDoc{})
        if err := myFunc.AddNewKernel(
                []exec.InputType{
                        {
                                Kind: exec.InputExact,
                                Type: arrow.PrimitiveTypes.Int64,
                        },
                },
                exec.NewOutputType(arrow.PrimitiveTypes.Int64),
                func(ctx *exec.KernelCtx, span *exec.ExecSpan, result 
*exec.ExecResult) error {
                        inSlice := GetSpanValues(&span.Values[0].Array, 1)
                        outSlice := GetSpanValues(result, 1)
   
                        for i := range inSlice {
                                outSlice[i] = inSlice[i] + 42
                        }
                        return nil
                },
                nil,
        ); err != nil {
                panic(err)
        }
        execCtx.Registry.AddFunction(myFunc, true)
   
        arr1Builder := array.NewInt64Builder(allocator)
        for i := 0; i < 1024; i++ {
                arr1Builder.Append(int64(i))
        }
        arr1 := arr1Builder.NewArray()
   
        arr2Datum, err := compute.CallFunction(
                ctx,
                "papaya",
                nil,
                &compute.ArrayDatum{Value: arr1.Data()},
        )
        if err != nil {
                panic(err)
        }
   
        log.Println(array.NewInt64Data(arr2Datum.(*compute.ArrayDatum).Value))
   ```
   works as expected.
   
   All tests pass too.


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