diff --git a/cpp/include/cudf/detail/aggregation/aggregation.hpp b/cpp/include/cudf/detail/aggregation/aggregation.hpp index 1f70e68fce8..6b4a537d21b 100644 --- a/cpp/include/cudf/detail/aggregation/aggregation.hpp +++ b/cpp/include/cudf/detail/aggregation/aggregation.hpp @@ -411,6 +411,15 @@ struct target_type_impl< using type = int64_t; }; +// Summing fixed_point numbers, always use the decimal64 accumulator +template +struct target_type_impl< + Source, + k, + std::enable_if_t() && (k == aggregation::SUM)>> { + using type = numeric::decimal64; +}; + // Summing/Multiplying float/doubles, use same type accumulator template struct target_type_impl< diff --git a/cpp/src/rolling/rolling_detail.hpp b/cpp/src/rolling/rolling_detail.hpp index ed136405a79..1d1c42190ec 100644 --- a/cpp/src/rolling/rolling_detail.hpp +++ b/cpp/src/rolling/rolling_detail.hpp @@ -50,10 +50,14 @@ static constexpr bool is_rolling_supported() return is_valid_numeric_agg; - } else if (cudf::is_timestamp() || cudf::is_fixed_point()) { + } else if (cudf::is_timestamp()) { return (op == aggregation::MIN) or (op == aggregation::MAX) or (op == aggregation::COUNT_VALID) or (op == aggregation::COUNT_ALL) or (op == aggregation::ROW_NUMBER) or (op == aggregation::LEAD) or (op == aggregation::LAG); + } else if (cudf::is_fixed_point()) { + return (op == aggregation::SUM) or (op == aggregation::MIN) or (op == aggregation::MAX) or + (op == aggregation::COUNT_VALID) or (op == aggregation::COUNT_ALL) or + (op == aggregation::ROW_NUMBER) or (op == aggregation::LEAD) or (op == aggregation::LAG); } else if (std::is_same()) { return (op == aggregation::MIN) or (op == aggregation::MAX) or (op == aggregation::COUNT_VALID) or (op == aggregation::COUNT_ALL) or diff --git a/cpp/tests/rolling/rolling_test.cpp b/cpp/tests/rolling/rolling_test.cpp index 7b1ab3cf273..a9d52d8405c 100644 --- a/cpp/tests/rolling/rolling_test.cpp +++ b/cpp/tests/rolling/rolling_test.cpp @@ -1005,13 +1005,15 @@ TYPED_TEST(FixedPointTests, MinMaxCountLagLeadNulls) { using namespace numeric; using namespace cudf; - using decimalXX = TypeParam; - using RepType = cudf::device_storage_type_t; - using fp_wrapper = cudf::test::fixed_point_column_wrapper; - using fw_wrapper = cudf::test::fixed_width_column_wrapper; + using decimalXX = TypeParam; + using RepType = cudf::device_storage_type_t; + using fp_wrapper = cudf::test::fixed_point_column_wrapper; + using fp64_wrapper = cudf::test::fixed_point_column_wrapper; + using fw_wrapper = cudf::test::fixed_width_column_wrapper; auto const scale = scale_type{-1}; auto const input = fp_wrapper{{42, 1729, 55, 343, 1, 2}, {1, 0, 1, 0, 1, 1}, scale}; + auto const expected_sum = fp64_wrapper{{42, 97, 55, 56, 3, 3}, {1, 1, 1, 1, 1, 1}, scale}; auto const expected_min = fp_wrapper{{42, 42, 55, 1, 1, 1}, {1, 1, 1, 1, 1, 1}, scale}; auto const expected_max = fp_wrapper{{42, 55, 55, 55, 2, 2}, {1, 1, 1, 1, 1, 1}, scale}; auto const expected_lag = fp_wrapper{{0, 42, 1729, 55, 343, 1}, {0, 1, 0, 1, 0, 1}, scale}; @@ -1020,6 +1022,7 @@ TYPED_TEST(FixedPointTests, MinMaxCountLagLeadNulls) auto const expected_count_all = fw_wrapper{{2, 3, 3, 3, 3, 2}, {1, 1, 1, 1, 1, 1}}; auto const expected_rowno = fw_wrapper{{1, 2, 2, 2, 2, 2}, {1, 1, 1, 1, 1, 1}}; + auto const sum = rolling_window(input, 2, 1, 1, make_sum_aggregation()); auto const min = rolling_window(input, 2, 1, 1, make_min_aggregation()); auto const max = rolling_window(input, 2, 1, 1, make_max_aggregation()); auto const lag = rolling_window(input, 2, 1, 1, make_lag_aggregation(1)); @@ -1028,6 +1031,7 @@ TYPED_TEST(FixedPointTests, MinMaxCountLagLeadNulls) auto const all = rolling_window(input, 2, 1, 1, make_count_aggregation(null_policy::INCLUDE)); auto const rowno = rolling_window(input, 2, 1, 1, make_row_number_aggregation()); + CUDF_TEST_EXPECT_COLUMNS_EQUAL(expected_sum, sum->view()); CUDF_TEST_EXPECT_COLUMNS_EQUAL(expected_min, min->view()); CUDF_TEST_EXPECT_COLUMNS_EQUAL(expected_max, max->view()); CUDF_TEST_EXPECT_COLUMNS_EQUAL(expected_lag, lag->view()); @@ -1035,6 +1039,13 @@ TYPED_TEST(FixedPointTests, MinMaxCountLagLeadNulls) CUDF_TEST_EXPECT_COLUMNS_EQUAL(expected_count_val, valid->view()); CUDF_TEST_EXPECT_COLUMNS_EQUAL(expected_count_all, all->view()); CUDF_TEST_EXPECT_COLUMNS_EQUAL(expected_rowno, rowno->view()); + + EXPECT_THROW(rolling_window(input, 2, 1, 1, make_product_aggregation()), cudf::logic_error); + EXPECT_THROW(rolling_window(input, 2, 1, 1, make_mean_aggregation()), cudf::logic_error); + EXPECT_THROW(rolling_window(input, 2, 1, 1, make_variance_aggregation()), cudf::logic_error); + EXPECT_THROW(rolling_window(input, 2, 1, 1, make_std_aggregation()), cudf::logic_error); + EXPECT_THROW(rolling_window(input, 2, 1, 1, make_sum_of_squares_aggregation()), + cudf::logic_error); } CUDF_TEST_PROGRAM_MAIN()