Skip to content

Commit

Permalink
pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
js8544 committed May 31, 2023
1 parent e96e867 commit c6b945a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cpp/src/arrow/compute/api_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,13 @@ Result<Datum> RunEndEncode(
ARROW_EXPORT
Result<Datum> 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<Datum> CumulativeSum(
const Datum& values,
Expand Down
12 changes: 12 additions & 0 deletions cpp/src/arrow/compute/kernels/vector_cumulative_ops_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@

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

#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 {
Expand Down Expand Up @@ -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

0 comments on commit c6b945a

Please sign in to comment.