Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicitly disable groupby on unsupported key types. #9227

Merged
merged 7 commits into from
Sep 20, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ add_library(cudf
src/filling/repeat.cu
src/filling/sequence.cu
src/groupby/groupby.cu
src/groupby/common/utils.cpp
src/groupby/hash/groupby.cu
src/groupby/sort/aggregate.cpp
src/groupby/sort/group_argmax.cu
Expand Down
31 changes: 31 additions & 0 deletions cpp/src/groupby/common/utils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2021, 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 <groupby/common/utils.hpp>

#include <cudf/strings/string_view.hpp>
#include <cudf/utilities/traits.hpp>

namespace cudf::groupby::detail {

void assert_keys_equality_comparable(cudf::table_view const& keys)
{
auto is_supported_key_type = [](auto col) { return cudf::is_equality_comparable(col.type()); };
CUDF_EXPECTS(std::all_of(keys.begin(), keys.end(), is_supported_key_type),
"Unsupported groupby key type does not support equality comparison");
}
mythrocks marked this conversation as resolved.
Show resolved Hide resolved

} // namespace cudf::groupby::detail
10 changes: 9 additions & 1 deletion cpp/src/groupby/common/utils.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-20, NVIDIA CORPORATION.
* Copyright (c) 2019-2021, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -39,6 +39,14 @@ inline std::vector<aggregation_result> extract_results(host_span<RequestType con
return results;
}

/**
* @brief Fails an assert if any of the specified `keys` columns do not support equality
* comparisons.
*
* @param keys Grouping keys to be checked for equality comparisons.
*/
void assert_keys_equality_comparable(cudf::table_view const& keys);
mythrocks marked this conversation as resolved.
Show resolved Hide resolved

} // namespace detail
} // namespace groupby
} // namespace cudf
9 changes: 2 additions & 7 deletions cpp/src/groupby/groupby.cu
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <cudf/types.hpp>
#include <cudf/utilities/error.hpp>
#include <cudf/utilities/traits.hpp>
#include <groupby/common/utils.hpp>
#include <structs/utilities.hpp>

#include <rmm/cuda_stream_view.hpp>
Expand All @@ -56,13 +57,6 @@ groupby::groupby(table_view const& keys,
_column_order{column_order},
_null_precedence{null_precedence}
{
auto is_supported_key_type = [](auto col) {
return col.type().id() == type_id::STRUCT // Struct does not support ==.
or col.type().id() == type_id::STRING // String does not support == on __host__.
or cudf::is_equality_comparable(col.type());
};
CUDF_EXPECTS(std::all_of(keys.begin(), keys.end(), is_supported_key_type),
"Unsupported groupby key type");
}

// Select hash vs. sort groupby implementation
Expand All @@ -84,6 +78,7 @@ std::pair<std::unique_ptr<table>, std::vector<aggregation_result>> groupby::disp
// Optionally flatten nested key columns.
auto [flattened_keys, _, __, ___] =
flatten_nested_columns(_keys, {}, {}, column_nullability::FORCE);
cudf::groupby::detail::assert_keys_equality_comparable(flattened_keys);
auto [grouped_keys, results] =
detail::hash::groupby(flattened_keys, requests, _include_null_keys, stream, mr);
return std::make_pair(unflatten_nested_columns(std::move(grouped_keys), _keys),
Expand Down
2 changes: 2 additions & 0 deletions cpp/src/groupby/sort/sort_helper.cu
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <cudf/detail/sorting.hpp>
#include <cudf/table/row_operators.cuh>
#include <cudf/table/table_device_view.cuh>
#include <groupby/common/utils.hpp>
#include <structs/utilities.hpp>

#include <rmm/cuda_stream_view.hpp>
Expand Down Expand Up @@ -102,6 +103,7 @@ sort_groupby_helper::sort_groupby_helper(table_view const& keys,

auto [flattened_keys, _, __, struct_null_vectors] =
flatten_nested_columns(keys, {}, {}, column_nullability::FORCE);
cudf::groupby::detail::assert_keys_equality_comparable(flattened_keys);
_struct_null_vectors = std::move(struct_null_vectors);
_keys = flattened_keys;

Expand Down