rtpsw commented on code in PR #14043:
URL: https://github.com/apache/arrow/pull/14043#discussion_r1016229048
##########
cpp/src/arrow/compute/function_test.cc:
##########
@@ -351,5 +354,87 @@ TEST(ScalarAggregateFunction, DispatchExact) {
ASSERT_TRUE(selected_kernel->signature->MatchesInputs(dispatch_args));
}
+namespace {
+
+struct TestFunctionOptions : public FunctionOptions {
+ TestFunctionOptions();
+
+ static const char* kTypeName;
+};
+
+static auto kTestFunctionOptionsType =
+ internal::GetFunctionOptionsType<TestFunctionOptions>();
+
+TestFunctionOptions::TestFunctionOptions() :
FunctionOptions(kTestFunctionOptionsType) {}
+
+const char* TestFunctionOptions::kTypeName = "test_options";
+
+} // namespace
+
+TEST(FunctionExecutor, Basics) {
+ VectorFunction func("vector_test", Arity::Binary(),
/*doc=*/FunctionDoc::Empty());
+ bool init_called = false;
+ ExecContext exec_ctx;
+ TestFunctionOptions options;
+ auto init =
+ [&init_called, &exec_ctx, &options](
+ KernelContext* kernel_ctx,
+ const KernelInitArgs& init_args) ->
Result<std::unique_ptr<KernelState>> {
+ init_called = true;
+ if (&exec_ctx != kernel_ctx->exec_context()) {
+ return Status::Invalid("expected exec context not found in kernel
context");
+ }
+ if (&options != init_args.options) {
+ return Status::Invalid("expected options not found in kernel init args");
+ }
+ return NULLPTR;
+ };
+ auto exec = [](KernelContext* ctx, const ExecSpan& args, ExecResult* out) {
+ DCHECK_EQ(2, args.values.size());
Review Comment:
This and the next couple of similar suggestions don't work as is because the
gtest ASSERT/EXPECT macros require a void-returning function, whereas this
lambda needs to be a `Status`-returning one. Adding another lambda that
captures this one also doesn't work because it breaks the `AddKernel`
invocation:
```
/arrow/cpp/src/arrow/compute/function.h:369:10: note: candidate:
‘arrow::Status
arrow::compute::VectorFunction::AddKernel(std::vector<arrow::compute::InputType>,
arrow::compute::OutputType, arrow::compute::ArrayKernelExec,
arrow::compute::KernelInit)’
369 | Status AddKernel(std::vector<InputType> in_types, OutputType
out_type,
| ^~~~~~~~~
/arrow/cpp/src/arrow/compute/function.h:370:36: note: no known conversion
for argument 3 from
‘arrow::compute::FunctionExecutor_Basics_Test::TestBody()::<lambda(arrow::compute::KernelContext*,
const arrow::compute::ExecSpan&, arrow::compute::ExecResult*)>’ to
‘arrow::compute::ArrayKernelExec’ {aka ‘arrow::Status
(*)(arrow::compute::KernelContext*, const arrow::compute::ExecSpan&,
arrow::compute::ExecResult*)’}
```
However, placing the code of the first lambda within a nested void-returning
lambda works. I'll include that in the next commit.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]