lidavidm commented on a change in pull request #11152:
URL: https://github.com/apache/arrow/pull/11152#discussion_r709430488



##########
File path: cpp/src/arrow/compute/kernels/aggregate_basic.cc
##########
@@ -282,6 +282,43 @@ Result<std::unique_ptr<KernelState>> 
MinMaxInit(KernelContext* ctx,
   return visitor.Create();
 }
 
+// For "min" and "max" functions: dispatch to the MinMax kernel.
+Result<std::unique_ptr<KernelState>> MinOrMaxInit(KernelContext* ctx,
+                                                  const KernelInitArgs& args) {
+  std::vector<ValueDescr> inputs = args.inputs;
+
+  ARROW_ASSIGN_OR_RAISE(auto func, 
GetFunctionRegistry()->GetFunction("min_max"));
+  ARROW_ASSIGN_OR_RAISE(auto kernel, func->DispatchBest(&inputs));
+
+  KernelInitArgs new_args{kernel, inputs, args.options};
+  return kernel->init(ctx, new_args);
+}
+
+Result<ValueDescr> MinOrMaxType(KernelContext*, const std::vector<ValueDescr>& 
descrs) {
+  // any[T] -> scalar[T]
+  return ValueDescr::Scalar(descrs.front().type);
+}
+
+template <uint8_t index>
+Status MinOrMaxFinalize(KernelContext* ctx, Datum* out) {
+  Datum temp;
+  RETURN_NOT_OK(checked_cast<ScalarAggregator*>(ctx->state())->Finalize(ctx, 
&temp));
+  *out = temp.scalar_as<StructScalar>().value[index];
+  return Status::OK();

Review comment:
       Good idea. I added this + moved some things to lambdas instead of free 
functions.




-- 
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: github-unsubscr...@arrow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to