| 450 | |
| 451 | template <class Function, class Kernel> |
| 452 | Status RegisterUdf(PyObject* function, compute::KernelInit kernel_init, |
| 453 | UdfWrapperCallback cb, const UdfOptions& options, |
| 454 | compute::FunctionRegistry* registry) { |
| 455 | if (!PyCallable_Check(function)) { |
| 456 | return Status::TypeError("Expected a callable Python object."); |
| 457 | } |
| 458 | auto scalar_func = |
| 459 | std::make_shared<Function>(options.func_name, options.arity, options.func_doc); |
| 460 | std::vector<compute::InputType> input_types; |
| 461 | for (const auto& in_dtype : options.input_types) { |
| 462 | input_types.emplace_back(in_dtype); |
| 463 | } |
| 464 | compute::OutputType output_type(options.output_type); |
| 465 | // Take reference before wrapping with OwnedRefNoGIL |
| 466 | Py_INCREF(function); |
| 467 | auto udf_data = std::make_shared<PythonUdf>( |
| 468 | std::make_shared<OwnedRefNoGIL>(function), cb, |
| 469 | TypeHolder::FromTypes(options.input_types), options.output_type); |
| 470 | Kernel kernel( |
| 471 | compute::KernelSignature::Make(std::move(input_types), std::move(output_type), |
| 472 | options.arity.is_varargs), |
| 473 | PythonUdfExec, kernel_init); |
| 474 | kernel.data = std::move(udf_data); |
| 475 | |
| 476 | kernel.mem_allocation = compute::MemAllocation::NO_PREALLOCATE; |
| 477 | kernel.null_handling = compute::NullHandling::COMPUTED_NO_PREALLOCATE; |
| 478 | RETURN_NOT_OK(scalar_func->AddKernel(std::move(kernel))); |
| 479 | if (registry == NULLPTR) { |
| 480 | registry = compute::GetFunctionRegistry(); |
| 481 | } |
| 482 | RETURN_NOT_OK(registry->AddFunction(std::move(scalar_func))); |
| 483 | return Status::OK(); |
| 484 | } |
| 485 | |
| 486 | } // namespace |
| 487 |
nothing calls this directly
no test coverage detected