| 114 | "ExampleFunctionOptions"}; |
| 115 | |
| 116 | arrow::Status RunComputeRegister(int argc, char** argv) { |
| 117 | const std::string name = "compute_register_example"; |
| 118 | auto func = std::make_shared<cp::ScalarFunction>(name, cp::Arity::Unary(), func_doc); |
| 119 | cp::ScalarKernel kernel({arrow::int64()}, arrow::int64(), ExampleFunctionImpl); |
| 120 | kernel.mem_allocation = cp::MemAllocation::NO_PREALLOCATE; |
| 121 | ARROW_RETURN_NOT_OK(func->AddKernel(std::move(kernel))); |
| 122 | |
| 123 | auto registry = cp::GetFunctionRegistry(); |
| 124 | ARROW_RETURN_NOT_OK(registry->AddFunction(std::move(func))); |
| 125 | |
| 126 | arrow::Int64Builder builder(arrow::default_memory_pool()); |
| 127 | std::shared_ptr<arrow::Array> arr; |
| 128 | ARROW_RETURN_NOT_OK(builder.Append(42)); |
| 129 | ARROW_RETURN_NOT_OK(builder.Finish(&arr)); |
| 130 | auto options = std::make_shared<ExampleFunctionOptions>(); |
| 131 | auto maybe_result = cp::CallFunction(name, {arr}, options.get()); |
| 132 | ARROW_RETURN_NOT_OK(maybe_result.status()); |
| 133 | |
| 134 | std::cout << maybe_result->make_array()->ToString() << std::endl; |
| 135 | |
| 136 | // Expression serialization will raise NotImplemented if an expression includes |
| 137 | // FunctionOptions for which serialization is not supported. |
| 138 | auto expr = cp::call(name, {}, options); |
| 139 | auto maybe_serialized = cp::Serialize(expr); |
| 140 | std::cerr << maybe_serialized.status().ToString() << std::endl; |
| 141 | |
| 142 | auto exec_registry = ac::default_exec_factory_registry(); |
| 143 | ARROW_RETURN_NOT_OK( |
| 144 | exec_registry->AddFactory("compute_register_example", ExampleExecNodeFactory)); |
| 145 | |
| 146 | auto maybe_plan = ac::ExecPlan::Make(); |
| 147 | ARROW_RETURN_NOT_OK(maybe_plan.status()); |
| 148 | ARROW_ASSIGN_OR_RAISE(auto plan, maybe_plan); |
| 149 | |
| 150 | arrow::AsyncGenerator<std::optional<cp::ExecBatch>> source_gen, sink_gen; |
| 151 | ARROW_RETURN_NOT_OK( |
| 152 | ac::Declaration::Sequence( |
| 153 | { |
| 154 | {"source", ac::SourceNodeOptions{arrow::schema({}), source_gen}}, |
| 155 | {"compute_register_example", ExampleNodeOptions{}}, |
| 156 | {"sink", ac::SinkNodeOptions{&sink_gen}}, |
| 157 | }) |
| 158 | .AddToPlan(plan.get()) |
| 159 | .status()); |
| 160 | return arrow::Status::OK(); |
| 161 | } |
| 162 | |
| 163 | int main(int argc, char** argv) { |
| 164 | auto status = RunComputeRegister(argc, argv); |
no test coverage detected