ZhangHuiGui commented on code in PR #40687:
URL: https://github.com/apache/arrow/pull/40687#discussion_r1533481765


##########
cpp/src/arrow/compute/exec_test.cc:
##########
@@ -1425,6 +1426,33 @@ TEST(Ordering, IsSuborderOf) {
   CheckOrdering(unordered, {true, true, true, true, true, true});
 }
 
+static Status RegisterMyScalarPureFunction() {
+  const std::string name = "my_scalar_function";
+  auto func = std::make_shared<ScalarFunction>(name, Arity::Nullary(),
+                                               FunctionDoc::Empty(), nullptr);
+  auto func_exec = [](KernelContext* /*ctx*/, const ExecSpan& /*batch*/,
+                      ExecResult* out) -> Status {
+    auto scalar = MakeScalar("I am a scalar");
+    ARROW_ASSIGN_OR_RAISE(auto arr_res, MakeArrayFromScalar(*scalar, 1));
+    out->value = std::move(arr_res->data());
+    return Status::OK();
+  };
+
+  ScalarKernel kernel({}, utf8(), func_exec);
+  ARROW_RETURN_NOT_OK(func->AddKernel(kernel));
+
+  auto registry = GetFunctionRegistry();
+  ARROW_RETURN_NOT_OK(registry->AddFunction(std::move(func)));
+  return Status::OK();
+}
+
+TEST(CallFunction, ScalarPureFunction) {
+  ASSERT_OK(RegisterMyScalarPureFunction());
+
+  EXPECT_THAT(CallFunction("my_scalar_function", ExecBatch({})),
+              ResultWith(MakeScalar("I am a scalar")));
+}

Review Comment:
   Actually, Original logic can't work for pure function return only scalar.
   `my_scalar_function` has no arguments and input-length, `Array([])` will be 
returned at 
https://github.com/apache/arrow/blob/a36cc62f45e0ebe594f97212728531148afa6e82/cpp/src/arrow/compute/exec.cc#L786-L793.
 It's a previous bug.



-- 
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]

Reply via email to