diff --git a/cpp/src/arrow/compute/api_scalar.cc b/cpp/src/arrow/compute/api_scalar.cc index 105ba7a0589..6f77d6f9785 100644 --- a/cpp/src/arrow/compute/api_scalar.cc +++ b/cpp/src/arrow/compute/api_scalar.cc @@ -63,6 +63,16 @@ SCALAR_ARITHMETIC_BINARY(Multiply, "multiply", "multiply_checked") SCALAR_ARITHMETIC_BINARY(Divide, "divide", "divide_checked") SCALAR_ARITHMETIC_BINARY(Power, "power", "power_checked") +Result ElementWiseMax(const std::vector& args, + ElementWiseAggregateOptions options, ExecContext* ctx) { + return CallFunction("element_wise_max", args, &options, ctx); +} + +Result ElementWiseMin(const std::vector& args, + ElementWiseAggregateOptions options, ExecContext* ctx) { + return CallFunction("element_wise_min", args, &options, ctx); +} + // ---------------------------------------------------------------------- // Set-related operations diff --git a/cpp/src/arrow/compute/api_scalar.h b/cpp/src/arrow/compute/api_scalar.h index 0a05b123a44..ab690f4c456 100644 --- a/cpp/src/arrow/compute/api_scalar.h +++ b/cpp/src/arrow/compute/api_scalar.h @@ -42,6 +42,11 @@ struct ArithmeticOptions : public FunctionOptions { bool check_overflow; }; +struct ARROW_EXPORT ElementWiseAggregateOptions : public FunctionOptions { + ElementWiseAggregateOptions() : skip_nulls(true) {} + bool skip_nulls; +}; + struct ARROW_EXPORT MatchSubstringOptions : public FunctionOptions { explicit MatchSubstringOptions(std::string pattern, bool ignore_case = false) : pattern(std::move(pattern)), ignore_case(ignore_case) {} @@ -253,6 +258,30 @@ Result Power(const Datum& left, const Datum& right, ArithmeticOptions options = ArithmeticOptions(), ExecContext* ctx = NULLPTR); +/// \brief Find the element-wise maximum of any number of arrays or scalars. +/// Array values must be the same length. +/// +/// \param[in] args arrays or scalars to operate on. +/// \param[in] options options for handling nulls, optional +/// \param[in] ctx the function execution context, optional +/// \return the element-wise maximum +ARROW_EXPORT +Result ElementWiseMax(const std::vector& args, + ElementWiseAggregateOptions options = {}, + ExecContext* ctx = NULLPTR); + +/// \brief Find the element-wise minimum of any number of arrays or scalars. +/// Array values must be the same length. +/// +/// \param[in] args arrays or scalars to operate on. +/// \param[in] options options for handling nulls, optional +/// \param[in] ctx the function execution context, optional +/// \return the element-wise minimum +ARROW_EXPORT +Result ElementWiseMin(const std::vector& args, + ElementWiseAggregateOptions options = {}, + ExecContext* ctx = NULLPTR); + /// \brief Compare a numeric array with a scalar. /// /// \param[in] left datum to compare, must be an Array diff --git a/cpp/src/arrow/compute/kernels/codegen_internal.h b/cpp/src/arrow/compute/kernels/codegen_internal.h index e31771a89ca..6d5c837f514 100644 --- a/cpp/src/arrow/compute/kernels/codegen_internal.h +++ b/cpp/src/arrow/compute/kernels/codegen_internal.h @@ -303,8 +303,12 @@ struct BoxScalar; template struct BoxScalar> { using T = typename GetOutputType::T; - using ScalarType = typename TypeTraits::ScalarType; - static void Box(T val, Scalar* out) { checked_cast(out)->value = val; } + static void Box(T val, Scalar* out) { + // Enables BoxScalar to work on a (for example) Time64Scalar + T* mutable_data = reinterpret_cast( + checked_cast<::arrow::internal::PrimitiveScalarBase*>(out)->mutable_data()); + *mutable_data = val; + } }; template @@ -1093,6 +1097,41 @@ ArrayKernelExec GeneratePhysicalInteger(detail::GetTypeId get_id) { } } +template