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
63 changes: 63 additions & 0 deletions cpp/include/cudf/table/row_operators.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <cudf/utilities/type_dispatcher.hpp>

#include <thrust/equal.h>
#include <thrust/logical.h>
#include <thrust/swap.h>
#include <thrust/transform_reduce.h>

Expand Down Expand Up @@ -222,13 +223,75 @@ class element_equality_comparator {
bool nulls_are_equal;
};

namespace detail {

/**
* @brief Helper functor to check if two types `LhsType` and `RhsType` are comparable for equality.
*/
template <typename LhsType>
struct equality_comparable_functor {
template <typename RhsType>
bool __device__ operator()() const
{
return cudf::is_equality_comparable<LhsType, RhsType>();
}
};

/**
* @brief Helper functor to check if a specified column `rhs_col` can be compared for equality
* with type `LhsType`.
*/
struct lhs_equality_comparable_functor {
template <typename LhsType>
bool __device__ operator()(column_device_view rhs_col) const
{
return cudf::type_dispatcher(rhs_col.type(), equality_comparable_functor<LhsType>{});
}
};

/**
* @brief Checks if two columns have types that permit equality comparisons
*
* @param lhs Left column for equality comparisons
* @param rhs Right column for equality comparisons
* @return true If `lhs` and `rhs` columns have types whose values may be compared for equality
* @return false Otherwise.
*/
bool __device__ columns_are_equality_comparable(column_device_view lhs, column_device_view rhs)
mythrocks marked this conversation as resolved.
Show resolved Hide resolved
{
return cudf::type_dispatcher(lhs.type(), lhs_equality_comparable_functor{}, rhs);
}

/**
* @brief Checks if corresponding columns in `lhs` and `rhs` tables may be compared for equality
*
* @param lhs Left table, whose columns are to be compared for equality.
* @param rhs Right table, whose columns are to be compared for equality.
* @return true If *all* columns in `lhs` permit equality comparisons with corresponding columns in
* `rhs`.
* @return false Otherwise.
*/
bool all_columns_are_equality_comparable(table_device_view lhs, table_device_view rhs)
mythrocks marked this conversation as resolved.
Show resolved Hide resolved
{
auto columns_begin = thrust::make_counting_iterator<size_type>(0);
auto columns_end = columns_begin + lhs.num_columns();
auto eq_comparable = [lhs, rhs] __device__(auto col_idx) {
return columns_are_equality_comparable(lhs.column(col_idx), rhs.column(col_idx));
};
return thrust::all_of(thrust::seq, columns_begin, columns_end, eq_comparable);
mythrocks marked this conversation as resolved.
Show resolved Hide resolved
}

} // namespace detail

template <bool has_nulls = true>
class row_equality_comparator {
public:
row_equality_comparator(table_device_view lhs, table_device_view rhs, bool nulls_are_equal = true)
: lhs{lhs}, rhs{rhs}, nulls_are_equal{nulls_are_equal}
{
CUDF_EXPECTS(lhs.num_columns() == rhs.num_columns(), "Mismatched number of columns.");
CUDF_EXPECTS(all_columns_are_equality_comparable(lhs, rhs),
"Incompatible columns in row equality comparison.");
}

__device__ bool operator()(size_type lhs_row_index, size_type rhs_row_index) const noexcept
Expand Down
3 changes: 0 additions & 3 deletions cpp/src/groupby/groupby.cu
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ groupby::groupby(table_view const& keys,
_column_order{column_order},
_null_precedence{null_precedence}
{
auto is_list = [](auto const& col) { return col.type().id() == cudf::type_id::LIST; };
auto has_list = std::any_of(keys.begin(), keys.end(), is_list);
CUDF_EXPECTS(not has_list, "Groupby does not support LIST columns as keys.");
}

// Select hash vs. sort groupby implementation
Expand Down