MCPcopy Create free account
hub / github.com/apache/arrow / RunComputeRegister

Function RunComputeRegister

cpp/examples/arrow/acero_register_example.cc:116–161  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

114 "ExampleFunctionOptions"};
115
116arrow::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
163int main(int argc, char** argv) {
164 auto status = RunComputeRegister(argc, argv);

Callers 1

mainFunction · 0.85

Calls 15

UnaryFunction · 0.85
GetFunctionRegistryFunction · 0.85
default_memory_poolFunction · 0.85
CallFunctionFunction · 0.85
make_arrayMethod · 0.80
AddFactoryMethod · 0.80
AddToPlanMethod · 0.80
callFunction · 0.50
SerializeFunction · 0.50
MakeFunction · 0.50
schemaFunction · 0.50

Tested by

no test coverage detected