paleolimbot commented on code in PR #13397:
URL: https://github.com/apache/arrow/pull/13397#discussion_r903760083


##########
r/src/compute.cpp:
##########
@@ -574,3 +576,154 @@ SEXP compute__CallFunction(std::string func_name, 
cpp11::list args, cpp11::list
 std::vector<std::string> compute__GetFunctionNames() {
   return arrow::compute::GetFunctionRegistry()->GetFunctionNames();
 }
+
+class RScalarUDFKernelState : public arrow::compute::KernelState {
+ public:
+  RScalarUDFKernelState(cpp11::sexp exec_func, cpp11::sexp resolver)
+      : exec_func_(exec_func), resolver_(resolver) {}
+
+  cpp11::function exec_func_;
+  cpp11::function resolver_;
+};
+
+class RScalarUDFOutputTypeResolver : public 
arrow::compute::OutputType::Resolver {
+ public:
+  arrow::Result<arrow::ValueDescr> operator()(
+      arrow::compute::KernelContext* context,
+      const std::vector<arrow::ValueDescr>& descr) {
+    return SafeCallIntoR<arrow::ValueDescr>([&]() -> arrow::ValueDescr {
+      auto kernel =
+          reinterpret_cast<const 
arrow::compute::ScalarKernel*>(context->kernel());
+      auto state = 
std::dynamic_pointer_cast<RScalarUDFKernelState>(kernel->data);
+
+      cpp11::writable::list input_types_sexp;
+      input_types_sexp.reserve(descr.size());
+      for (const auto& item : descr) {
+        input_types_sexp.push_back(cpp11::to_r6<arrow::DataType>(item.type));
+      }

Review Comment:
   Good call! I updated another place where this was the case 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]

Reply via email to