vibhatha commented on PR #13397:
URL: https://github.com/apache/arrow/pull/13397#issuecomment-1160958463
> All good points and thank you for taking a look! Your edit did the trick,
although the segfault may have been due to something about turning a `Scalar`
into an `Array`:
>
> ```r
> # remotes::install_github("apache/arrow/r#13397")
> library(arrow, warn.conflicts = FALSE)
>
> fun <- arrow:::arrow_scalar_function(
> int32(),
> int64(),
> function(x, y) {
> y[[1]]$cast(int64())
> }
> )
>
> arrow:::register_scalar_function("my_test_scalar_function", fun)
>
> # works!
> call_function("my_test_scalar_function", Array$create(1L))
> #> Array
> #> <int64>
> #> [
> #> 1
> #> ]
>
> # segfaults!
> # call_function("my_test_scalar_function", Scalar$create(1L))
> ```
>
> Created on 2022-06-20 by the [reprex
package](https://reprex.tidyverse.org) (v2.0.1)
>
Let me also look into this one a little bit closely.
> > you will get a test failure saying the function is already registered
>
> It seems there's no way to unregister a function...if there were, I could
unregister it in the test. I changed the `AddFunction()` call to overwrite the
existing function for now but that's probably not a good long-term choice.
Yes, we don't have such a function yet. There is a discussion to support
that or to keep a scoped function registry that can be used depending on using
functions in different scopes. For instance in the UDF case, the functions
could get registered in a scoped function registry and it get cleaned up after
the UDF scope goes out of scope. The aforementioned links include a discussion
and PRs associated with that. At least it is discussed in the Substrait space.
I think we could be able to use it for R API as well.
--
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]