-
Notifications
You must be signed in to change notification settings - Fork 917
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5874 from shwina/groupby-collect
[REVIEW] Add `COLLECT` groupby aggregation
- Loading branch information
Showing
14 changed files
with
275 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright (c) 2020, NVIDIA CORPORATION. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include <cudf/column/column_factories.hpp> | ||
#include <cudf/column/column_view.hpp> | ||
#include <cudf/detail/aggregation/aggregation.hpp> | ||
#include <cudf/detail/gather.cuh> | ||
#include <cudf/types.hpp> | ||
|
||
namespace cudf { | ||
namespace groupby { | ||
namespace detail { | ||
std::unique_ptr<column> group_collect(column_view const &values, | ||
rmm::device_vector<size_type> const &group_offsets, | ||
size_type num_groups, | ||
rmm::mr::device_memory_resource *mr, | ||
cudaStream_t stream) | ||
{ | ||
rmm::device_buffer offsets_data( | ||
group_offsets.data().get(), group_offsets.size() * sizeof(cudf::size_type), stream, mr); | ||
|
||
auto offsets = std::make_unique<cudf::column>( | ||
cudf::data_type(cudf::type_to_id<cudf::size_type>()), num_groups + 1, std::move(offsets_data)); | ||
|
||
return make_lists_column(num_groups, | ||
std::move(offsets), | ||
std::make_unique<cudf::column>(values, stream, mr), | ||
0, | ||
rmm::device_buffer{0, stream, mr}, | ||
stream, | ||
mr); | ||
} | ||
} // namespace detail | ||
} // namespace groupby | ||
} // namespace cudf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* Copyright (c) 2020, NVIDIA CORPORATION. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include <tests/groupby/groupby_test_util.hpp> | ||
|
||
#include <tests/utilities/base_fixture.hpp> | ||
#include <tests/utilities/column_wrapper.hpp> | ||
#include <tests/utilities/type_lists.hpp> | ||
|
||
#include <cudf/detail/aggregation/aggregation.hpp> | ||
|
||
namespace cudf { | ||
namespace test { | ||
|
||
template <typename V> | ||
struct groupby_collect_test : public cudf::test::BaseFixture { | ||
}; | ||
|
||
using FixedWidthTypesNotBool = cudf::test::Concat<cudf::test::IntegralTypesNotBool, | ||
cudf::test::FloatingPointTypes, | ||
cudf::test::TimestampTypes>; | ||
TYPED_TEST_CASE(groupby_collect_test, FixedWidthTypesNotBool); | ||
|
||
TYPED_TEST(groupby_collect_test, CollectWithoutNulls) | ||
{ | ||
using K = int32_t; | ||
using V = TypeParam; | ||
|
||
fixed_width_column_wrapper<K, int32_t> keys{1, 1, 1, 2, 2, 2}; | ||
fixed_width_column_wrapper<V, int32_t> values{1, 2, 3, 4, 5, 6}; | ||
|
||
fixed_width_column_wrapper<K, int32_t> expect_keys{1, 2}; | ||
lists_column_wrapper<V, int32_t> expect_vals{{1, 2, 3}, {4, 5, 6}}; | ||
|
||
auto agg = cudf::make_collect_aggregation(); | ||
test_single_agg(keys, values, expect_keys, expect_vals, std::move(agg)); | ||
} | ||
|
||
TYPED_TEST(groupby_collect_test, CollectWithNulls) | ||
{ | ||
using K = int32_t; | ||
using V = TypeParam; | ||
|
||
fixed_width_column_wrapper<K, int32_t> keys{1, 1, 2, 2, 3, 3}; | ||
fixed_width_column_wrapper<V, int32_t> values{{1, 2, 3, 4, 5, 6}, | ||
{true, false, true, false, true, false}}; | ||
|
||
fixed_width_column_wrapper<K, int32_t> expect_keys{1, 2, 3}; | ||
|
||
std::vector<int32_t> validity({true, false}); | ||
lists_column_wrapper<V, int32_t> expect_vals{ | ||
{{1, 2}, validity.begin()}, {{3, 4}, validity.begin()}, {{5, 6}, validity.begin()}}; | ||
|
||
auto agg = cudf::make_collect_aggregation(); | ||
test_single_agg(keys, values, expect_keys, expect_vals, std::move(agg)); | ||
} | ||
|
||
TYPED_TEST(groupby_collect_test, CollectLists) | ||
{ | ||
using K = int32_t; | ||
using V = TypeParam; | ||
|
||
using LCW = cudf::test::lists_column_wrapper<TypeParam, int32_t>; | ||
|
||
fixed_width_column_wrapper<K, int32_t> keys{1, 1, 2, 2, 3, 3}; | ||
lists_column_wrapper<V, int32_t> values{{1, 2}, {3, 4}, {5, 6, 7}, LCW{}, {9, 10}, {11}}; | ||
|
||
fixed_width_column_wrapper<K, int32_t> expect_keys{1, 2, 3}; | ||
|
||
lists_column_wrapper<V, int32_t> expect_vals{ | ||
{{1, 2}, {3, 4}}, {{5, 6, 7}, LCW{}}, {{9, 10}, {11}}}; | ||
|
||
auto agg = cudf::make_collect_aggregation(); | ||
test_single_agg(keys, values, expect_keys, expect_vals, std::move(agg)); | ||
} | ||
|
||
} // namespace test | ||
} // namespace cudf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.