asuhan commented on a change in pull request #11793: URL: https://github.com/apache/arrow/pull/11793#discussion_r759883847
########## File path: cpp/src/arrow/compute/kernels/scalar_compare.cc ########## @@ -439,6 +471,330 @@ struct ScalarMinMax { } }; +template <typename Type, typename Op> +struct BinaryScalarMinMax { + using ArrayType = typename TypeTraits<Type>::ArrayType; + using BuilderType = typename TypeTraits<Type>::BuilderType; + using offset_type = typename Type::offset_type; + + static Status Exec(KernelContext* ctx, const ExecBatch& batch, Datum* out) { + const ElementWiseAggregateOptions& options = MinMaxState::Get(ctx); + if (std::all_of(batch.values.begin(), batch.values.end(), + [](const Datum& d) { return d.is_scalar(); })) { + return ExecOnlyScalar(ctx, options, batch, out); + } + return ExecContainingArrays(ctx, options, batch, out); + } + + static Status ExecOnlyScalar(KernelContext* ctx, + const ElementWiseAggregateOptions& options, + const ExecBatch& batch, Datum* out) { + if (batch.values.empty()) { + return Status::OK(); + } + auto output = checked_cast<BaseBinaryScalar*>(out->scalar().get()); + if (!options.skip_nulls) { + // any nulls in the input will produce a null output + for (const auto& value : batch.values) { + if (!value.scalar()->is_valid) { + output->is_valid = false; + return Status::OK(); + } + } + } + const Scalar& first_scalar = *batch.values.front().scalar(); Review comment: Done here and elsewhere. Out of curiosity, is there a style rule for using `auto` vs stating the type? ########## File path: cpp/src/arrow/compute/kernels/scalar_compare.cc ########## @@ -439,6 +472,330 @@ struct ScalarMinMax { } }; +template <typename Type, typename Op> +struct BinaryScalarMinMax { + using ArrayType = typename TypeTraits<Type>::ArrayType; + using BuilderType = typename TypeTraits<Type>::BuilderType; + using offset_type = typename Type::offset_type; + + static Status Exec(KernelContext* ctx, const ExecBatch& batch, Datum* out) { + const ElementWiseAggregateOptions& options = MinMaxState::Get(ctx); + if (std::all_of(batch.values.begin(), batch.values.end(), + [](const Datum& d) { return d.is_scalar(); })) { + return ExecOnlyScalar(ctx, options, batch, out); + } + return ExecContainingArrays(ctx, options, batch, out); + } + + static Status ExecOnlyScalar(KernelContext* ctx, + const ElementWiseAggregateOptions& options, + const ExecBatch& batch, Datum* out) { + if (batch.values.empty()) { + return Status::OK(); + } + auto output = checked_cast<BaseBinaryScalar*>(out->scalar().get()); + if (!options.skip_nulls) { + // any nulls in the input will produce a null output + for (const auto& value : batch.values) { + if (!value.scalar()->is_valid) { + output->is_valid = false; + return Status::OK(); + } + } + } + const Scalar& first_scalar = *batch.values.front().scalar(); + string_view result = UnboxScalar<Type>::Unbox(first_scalar); + bool valid = first_scalar.is_valid; + for (size_t i = 1; i < batch.values.size(); i++) { + const Scalar& scalar = *batch[i].scalar(); + if (!scalar.is_valid) { + DCHECK(options.skip_nulls); + continue; + } else { + string_view value = UnboxScalar<Type>::Unbox(scalar); + result = !valid ? value : Op::Call(result, value); + valid = true; + } + } + if (valid) { + ARROW_ASSIGN_OR_RAISE(output->value, ctx->Allocate(result.size())); + uint8_t* buf = output->value->mutable_data(); + buf = std::copy(result.begin(), result.end(), buf); Review comment: Done. -- 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