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


##########
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:
   Ah, I see. In that case, please add a comment
   ```c++
   // Ensure that KernelExecutor's fast path for zero-length batches
   // does not clobber scalar output for functions called with no arguments
   ```
   
   it's worth noting that this is independent of function purity; for example a 
function `query_start_time()` which always returns a Timestamp scalar of the 
instant when the query started would be impure and would have run afoul of this 
fast path too



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