vibhatha commented on code in PR #13397:
URL: https://github.com/apache/arrow/pull/13397#discussion_r902062655
##########
r/src/compute.cpp:
##########
@@ -574,3 +576,89 @@ SEXP compute__CallFunction(std::string func_name,
cpp11::list args, cpp11::list
std::vector<std::string> compute__GetFunctionNames() {
return arrow::compute::GetFunctionRegistry()->GetFunctionNames();
}
+
+class RScalarUDFCallable : public arrow::compute::ArrayKernelExec {
+ public:
+ RScalarUDFCallable(const std::shared_ptr<arrow::Schema>& input_types,
+ const std::shared_ptr<arrow::DataType>& output_type,
cpp11::sexp fun)
+ : input_types_(input_types), output_type_(output_type), fun_(fun) {}
+
+ arrow::Status operator()(arrow::compute::KernelContext* context,
+ const arrow::compute::ExecSpan& span,
+ arrow::compute::ExecResult* result) {
+ auto fun_result = SafeCallIntoR<std::shared_ptr<arrow::Array>>([&]() {
+ cpp11::writable::list args_sexp;
+ args_sexp.reserve(span.num_values());
+
+ for (int64_t i = 0; i < span.num_values(); i++) {
+ const arrow::compute::ExecValue& v = span[i];
+ if (v.is_array()) {
+ std::shared_ptr<arrow::Array> array = v.array.ToArray();
+ args_sexp.push_back(cpp11::to_r6<arrow::Array>(array));
+ } else if (v.is_scalar()) {
+ std::shared_ptr<const arrow::Scalar> scalar =
v.scalar->shared_from_this();
+ args_sexp.push_back(cpp11::to_r6<const arrow::Scalar>(scalar));
Review Comment:
When we execute the `LOC:599` I think it is making a copy, right? If so,
instead can we use the given experimental function in the `Scalar` API.
--
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]