| 638 | }; |
| 639 | |
| 640 | arrow::Result<arrow::TypeHolder> ResolveScalarUDFOutputType( |
| 641 | arrow::compute::KernelContext* context, |
| 642 | const std::vector<arrow::TypeHolder>& input_types) { |
| 643 | return SafeCallIntoR<arrow::TypeHolder>( |
| 644 | [&]() -> arrow::TypeHolder { |
| 645 | auto kernel = |
| 646 | reinterpret_cast<const arrow::compute::ScalarKernel*>(context->kernel()); |
| 647 | auto state = std::dynamic_pointer_cast<RScalarUDFKernelState>(kernel->data); |
| 648 | |
| 649 | cpp11::writable::list input_types_sexp(input_types.size()); |
| 650 | for (size_t i = 0; i < input_types.size(); i++) { |
| 651 | input_types_sexp[i] = |
| 652 | cpp11::to_r6<arrow::DataType>(input_types[i].GetSharedPtr()); |
| 653 | } |
| 654 | |
| 655 | cpp11::sexp output_type_sexp = |
| 656 | cpp11::function(state->resolver_)(input_types_sexp); |
| 657 | if (!Rf_inherits(output_type_sexp, "DataType")) { |
| 658 | cpp11::stop( |
| 659 | "Function specified as arrow_scalar_function() out_type argument must " |
| 660 | "return a DataType"); |
| 661 | } |
| 662 | |
| 663 | return arrow::TypeHolder( |
| 664 | cpp11::as_cpp<std::shared_ptr<arrow::DataType>>(output_type_sexp)); |
| 665 | }, |
| 666 | "resolve scalar user-defined function output data type"); |
| 667 | } |
| 668 | |
| 669 | arrow::Status CallRScalarUDF(arrow::compute::KernelContext* context, |
| 670 | const arrow::compute::ExecSpan& span, |
nothing calls this directly
no test coverage detected