rok commented on a change in pull request #9758: URL: https://github.com/apache/arrow/pull/9758#discussion_r616261694
########## File path: cpp/src/arrow/compute/kernels/aggregate_test.cc ########## @@ -104,71 +104,128 @@ static Datum NaiveSum(const Array& array) { } template <typename ArrowType> -void ValidateSum(const Array& input, Datum expected) { +void ValidateSum( + const Array& input, Datum expected, + const ScalarAggregateOptions& options = ScalarAggregateOptions::Defaults()) { using OutputType = typename FindAccumulatorType<ArrowType>::Type; - ASSERT_OK_AND_ASSIGN(Datum result, Sum(input)); + ASSERT_OK_AND_ASSIGN(Datum result, Sum(input, options)); DatumEqual<OutputType>::EnsureEqual(result, expected); } template <typename ArrowType> -void ValidateSum(const std::shared_ptr<ChunkedArray>& input, Datum expected) { +void ValidateSum(const std::shared_ptr<ChunkedArray>& input, Datum expected, + const ScalarAggregateOptions& options) { using OutputType = typename FindAccumulatorType<ArrowType>::Type; - ASSERT_OK_AND_ASSIGN(Datum result, Sum(input)); + ASSERT_OK_AND_ASSIGN(Datum result, Sum(input, options)); DatumEqual<OutputType>::EnsureEqual(result, expected); } template <typename ArrowType> -void ValidateSum(const char* json, Datum expected) { +void ValidateSum( + const char* json, Datum expected, + const ScalarAggregateOptions& options = ScalarAggregateOptions::Defaults()) { auto array = ArrayFromJSON(TypeTraits<ArrowType>::type_singleton(), json); - ValidateSum<ArrowType>(*array, expected); + ValidateSum<ArrowType>(*array, expected, options); } template <typename ArrowType> -void ValidateSum(const std::vector<std::string>& json, Datum expected) { +void ValidateSum( + const std::vector<std::string>& json, Datum expected, + const ScalarAggregateOptions& options = ScalarAggregateOptions::Defaults()) { auto array = ChunkedArrayFromJSON(TypeTraits<ArrowType>::type_singleton(), json); - ValidateSum<ArrowType>(array, expected); + ValidateSum<ArrowType>(array, expected, options); } template <typename ArrowType> -void ValidateSum(const Array& array) { - ValidateSum<ArrowType>(array, NaiveSum<ArrowType>(array)); +void ValidateSum(const Array& array, const ScalarAggregateOptions& options = + ScalarAggregateOptions::Defaults()) { + ValidateSum<ArrowType>(array, NaiveSum<ArrowType>(array), options); } -using UnaryOp = Result<Datum>(const Datum&, ExecContext*); +using UnaryOp = Result<Datum>(const Datum&, const ScalarAggregateOptions&, ExecContext*); -template <UnaryOp& Op, typename ScalarType> +template <UnaryOp& Op, typename ScalarAggregateOptions, typename ScalarType> void ValidateBooleanAgg(const std::string& json, - const std::shared_ptr<ScalarType>& expected) { + const std::shared_ptr<ScalarType>& expected, + const ScalarAggregateOptions& options) { auto array = ArrayFromJSON(boolean(), json); - auto exp = Datum(expected); - ASSERT_OK_AND_ASSIGN(Datum result, Op(array, nullptr)); - ASSERT_TRUE(result.Equals(exp)); + ASSERT_OK_AND_ASSIGN(Datum result, Op(array, options, nullptr)); + + const auto& exp = Datum(expected); + const auto& res = checked_pointer_cast<ScalarType>(result.scalar()); + if (!(std::isnan((double)res->value) && std::isnan((double)expected->value))) { + ASSERT_TRUE(result.Equals(exp)); + } Review comment: Is there a better way to check equality when `nan`s are involved? -- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org