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

Function CheckAddDispatch

cpp/src/arrow/compute/function_test.cc:243–287  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

241
242template <typename FunctionType, typename ExecType>
243void CheckAddDispatch(FunctionType* func, ExecType exec) {
244 using KernelType = typename FunctionType::KernelType;
245
246 ASSERT_EQ(0, func->num_kernels());
247 ASSERT_EQ(0, func->kernels().size());
248
249 std::vector<InputType> in_types1 = {int32(), int32()};
250 OutputType out_type1 = int32();
251
252 ASSERT_OK(func->AddKernel(in_types1, out_type1, exec));
253 ASSERT_OK(func->AddKernel({int32(), int8()}, int32(), exec));
254
255 // Duplicate sig is okay
256 ASSERT_OK(func->AddKernel(in_types1, out_type1, exec));
257
258 // Add a kernel
259 KernelType kernel({float64(), float64()}, float64(), exec);
260 ASSERT_OK(func->AddKernel(kernel));
261
262 ASSERT_EQ(4, func->num_kernels());
263 ASSERT_EQ(4, func->kernels().size());
264
265 // Try adding some invalid kernels
266 ASSERT_RAISES(Invalid, func->AddKernel({}, int32(), exec));
267 ASSERT_RAISES(Invalid, func->AddKernel({int32()}, int32(), exec));
268 ASSERT_RAISES(Invalid, func->AddKernel({int8(), int8(), int8()}, int32(), exec));
269
270 // Add valid and invalid kernel using kernel struct directly
271 KernelType valid_kernel({boolean(), boolean()}, boolean(), exec);
272 ASSERT_OK(func->AddKernel(valid_kernel));
273
274 KernelType invalid_kernel({boolean()}, boolean(), exec);
275 ASSERT_RAISES(Invalid, func->AddKernel(invalid_kernel));
276
277 ASSERT_OK_AND_ASSIGN(const Kernel* dispatched, func->DispatchExact({int32(), int32()}));
278 KernelSignature expected_sig(in_types1, out_type1);
279 ASSERT_TRUE(dispatched->signature->Equals(expected_sig));
280
281 // No kernel available
282 ASSERT_RAISES(NotImplemented, func->DispatchExact({utf8(), utf8()}));
283
284 // Wrong arity
285 ASSERT_RAISES(Invalid, func->DispatchExact({}));
286 ASSERT_RAISES(Invalid, func->DispatchExact({int32(), int32(), int32()}));
287}
288
289TEST(ScalarVectorFunction, DispatchExact) {
290 ScalarFunction func1("scalar_test", Arity::Binary(), /*doc=*/FunctionDoc::Empty());

Callers 1

TESTFunction · 0.85

Calls 6

num_kernelsMethod · 0.80
kernelsMethod · 0.80
sizeMethod · 0.45
AddKernelMethod · 0.45
EqualsMethod · 0.45
DispatchExactMethod · 0.45

Tested by

no test coverage detected