From 0acc1bc42f3c7dd02ea23bfab65dc640030c7ca1 Mon Sep 17 00:00:00 2001 From: Mithun RK Date: Mon, 13 Sep 2021 22:06:45 -0700 Subject: [PATCH 1/2] Add grouped_rolling test for STRUCT groupby keys. This commit adds a test for `grouped_rolling_window()` where the groupby keys are `STRUCT`. --- cpp/tests/rolling/grouped_rolling_test.cpp | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/cpp/tests/rolling/grouped_rolling_test.cpp b/cpp/tests/rolling/grouped_rolling_test.cpp index 72b30c19fd5..f7ee3d35a65 100644 --- a/cpp/tests/rolling/grouped_rolling_test.cpp +++ b/cpp/tests/rolling/grouped_rolling_test.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -2413,3 +2414,38 @@ TYPED_TEST(TypedUnboundedWindowTest, UnboundedPrecedingAndFollowingWindowMultiGr fixed_width_column_wrapper{ {3, 3, 3, 3, 3, 4, 4, 4, 4, 4}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}}); } + +TYPED_TEST(TypedUnboundedWindowTest, UnboundedPrecedingAndFollowingStructGroup) +{ + // Test that grouping on STRUCT keys produces is possible. + + using namespace cudf; + using namespace cudf::test; + using T = TypeParam; + using numerics = fixed_width_column_wrapper; + + auto const grp_col = [] { + auto grp_col_inner = numerics{0, 0, 0, 0, 0, 1, 1, 1, 1, 1}; + return structs_column_wrapper{{grp_col_inner}}; + }(); + + // clang-format off + auto const agg_col = numerics{{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, + {0, 1, 1, 0, 1, 0, 1, 1, 1, 1}}; + // clang-format on + + auto const grouping_keys = table_view{{grp_col}}; + auto const unbounded_preceding = cudf::window_bounds::unbounded(); + auto const unbounded_following = cudf::window_bounds::unbounded(); + auto const min_periods = 1L; + auto const output = + cudf::grouped_rolling_window(grouping_keys, + agg_col, + unbounded_preceding, + unbounded_following, + min_periods, + *cudf::make_count_aggregation()); + + CUDF_TEST_EXPECT_COLUMNS_EQUAL(output->view(), + numerics{{3, 3, 3, 3, 3, 4, 4, 4, 4, 4}, iterators::no_nulls()}); +} From 8e67306443986ac3e53aee1a22e7298f1a498cc8 Mon Sep 17 00:00:00 2001 From: Mithun RK Date: Tue, 14 Sep 2021 11:56:36 -0700 Subject: [PATCH 2/2] Review: Update namespace using directives. --- cpp/tests/rolling/grouped_rolling_test.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/cpp/tests/rolling/grouped_rolling_test.cpp b/cpp/tests/rolling/grouped_rolling_test.cpp index f7ee3d35a65..0bd88c78200 100644 --- a/cpp/tests/rolling/grouped_rolling_test.cpp +++ b/cpp/tests/rolling/grouped_rolling_test.cpp @@ -2419,22 +2419,20 @@ TYPED_TEST(TypedUnboundedWindowTest, UnboundedPrecedingAndFollowingStructGroup) { // Test that grouping on STRUCT keys produces is possible. - using namespace cudf; - using namespace cudf::test; + using cudf::test::iterators::no_nulls; + using cudf::test::iterators::nulls_at; using T = TypeParam; using numerics = fixed_width_column_wrapper; + using result_t = fixed_width_column_wrapper; auto const grp_col = [] { auto grp_col_inner = numerics{0, 0, 0, 0, 0, 1, 1, 1, 1, 1}; - return structs_column_wrapper{{grp_col_inner}}; + return cudf::test::structs_column_wrapper{{grp_col_inner}}; }(); - // clang-format off - auto const agg_col = numerics{{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, - {0, 1, 1, 0, 1, 0, 1, 1, 1, 1}}; - // clang-format on + auto const agg_col = numerics{{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, nulls_at({0, 3, 5})}; - auto const grouping_keys = table_view{{grp_col}}; + auto const grouping_keys = cudf::table_view{{grp_col}}; auto const unbounded_preceding = cudf::window_bounds::unbounded(); auto const unbounded_following = cudf::window_bounds::unbounded(); auto const min_periods = 1L; @@ -2447,5 +2445,5 @@ TYPED_TEST(TypedUnboundedWindowTest, UnboundedPrecedingAndFollowingStructGroup) *cudf::make_count_aggregation()); CUDF_TEST_EXPECT_COLUMNS_EQUAL(output->view(), - numerics{{3, 3, 3, 3, 3, 4, 4, 4, 4, 4}, iterators::no_nulls()}); + result_t{{3, 3, 3, 3, 3, 4, 4, 4, 4, 4}, no_nulls()}); }