diff --git a/cpp/src/arrow/compute/api_vector.h b/cpp/src/arrow/compute/api_vector.h index 00d38628e18bf..d02c505f3e59a 100644 --- a/cpp/src/arrow/compute/api_vector.h +++ b/cpp/src/arrow/compute/api_vector.h @@ -592,6 +592,13 @@ Result RunEndEncode( ARROW_EXPORT Result RunEndDecode(const Datum& value, ExecContext* ctx = NULLPTR); +/// \brief Compute the cumulative sum of an array-like object +/// +/// \param[in] values array-like input +/// \param[in] options configures cumulative sum behavior +/// \param[in] check_overflow whether to check for overflow, if true, return Invalid +/// status on overflow, otherwise wrap around on overflow +/// \param[in] ctx the function execution context, optional ARROW_EXPORT Result CumulativeSum( const Datum& values, diff --git a/cpp/src/arrow/compute/kernels/vector_cumulative_ops_test.cc b/cpp/src/arrow/compute/kernels/vector_cumulative_ops_test.cc index 9ec287b537d64..3c6bb3c1d10d9 100644 --- a/cpp/src/arrow/compute/kernels/vector_cumulative_ops_test.cc +++ b/cpp/src/arrow/compute/kernels/vector_cumulative_ops_test.cc @@ -23,6 +23,7 @@ #include "arrow/array.h" #include "arrow/chunked_array.h" +#include "arrow/compute/api_vector.h" #include "arrow/testing/gtest_util.h" #include "arrow/testing/util.h" #include "arrow/type.h" @@ -30,6 +31,7 @@ #include "arrow/array/builder_primitive.h" #include "arrow/compute/api.h" #include "arrow/compute/kernels/test_util.h" +#include "arrow/type_fwd.h" namespace arrow { namespace compute { @@ -344,5 +346,15 @@ TEST(TestCumulativeSum, HasStartDoSkip) { } } +TEST(TestCumulativeSum, ConvenienceFunctionCheckOverflow) { + ASSERT_ARRAYS_EQUAL(*CumulativeSum(ArrayFromJSON(int8(), "[127, 1]"), + CumulativeSumOptions::Defaults(), false) + ->make_array(), + *ArrayFromJSON(int8(), "[127, -128]")); + + EXPECT_RAISES_WITH_MESSAGE_THAT(Invalid, HasSubstr("overflow"), + CumulativeSum(ArrayFromJSON(int8(), "[127, 1]"), + CumulativeSumOptions::Defaults(), true)); +} } // namespace compute } // namespace arrow