26 #include <cudf/detail/utilities/assert.cuh>
27 #include <cudf/hashing/detail/hash_functions.cuh>
28 #include <cudf/hashing/detail/hashing.hpp>
35 #include <cuda/std/limits>
36 #include <cuda/std/type_traits>
37 #include <thrust/equal.h>
41 namespace CUDF_EXPORT
cudf {
57 namespace row::primitive {
74 template <cudf::type_
id Id>
96 template <typename Element, CUDF_ENABLE_IF(cudf::is_equality_comparable<Element, Element>())>
103 rhs.element<Element>(rhs_element_index));
107 template <typename Element, CUDF_ENABLE_IF(not cudf::is_equality_comparable<Element, Element>())>
113 CUDF_UNREACHABLE(
"Attempted to compare elements of uncomparable types.");
136 std::shared_ptr<cudf::experimental::row::equality::preprocessed_table> lhs,
137 std::shared_ptr<cudf::experimental::row::equality::preprocessed_table> rhs,
139 : _has_nulls{
has_nulls}, _lhs{*lhs}, _rhs{*rhs}, _nulls_are_equal{nulls_are_equal}
141 CUDF_EXPECTS(_lhs.num_columns() == _rhs.num_columns(),
"Mismatched number of columns.");
153 auto equal_elements = [
this, lhs_row_index, rhs_row_index](
column_device_view const& l,
157 bool const lhs_is_null{l.is_null(lhs_row_index)};
158 bool const rhs_is_null{r.is_null(rhs_row_index)};
159 if (lhs_is_null and rhs_is_null) {
160 return _nulls_are_equal == null_equality::EQUAL;
161 }
else if (lhs_is_null != rhs_is_null) {
168 return cudf::type_dispatcher<dispatch_primitive_type>(
169 l.type(), comparator, l, r, lhs_row_index, rhs_row_index);
172 return thrust::equal(thrust::seq, _lhs.begin(), _lhs.end(), _rhs.begin(), equal_elements);
203 template <
template <
typename>
class Hash>
215 template <typename T, CUDF_ENABLE_IF(column_device_view::has_element_accessor<T>())>
220 return Hash<T>{seed}(col.element<T>(row_index));
224 template <typename T, CUDF_ENABLE_IF(not column_device_view::has_element_accessor<T>())>
227 CUDF_UNREACHABLE(
"Unsupported type in hash.");
240 template <
template <
typename>
class Hash = cudf::hashing::detail::default_hash>
255 : _has_nulls{
has_nulls}, _table{t}, _seed{seed}
267 std::shared_ptr<cudf::experimental::row::equality::preprocessed_table> t,
269 : _has_nulls{
has_nulls}, _table{*t}, _seed{seed}
283 auto hash = cuda::std::numeric_limits<hash_value_type>::max();
284 if (!_has_nulls || !_table.column(0).is_null(row_index)) {
285 hash = cudf::type_dispatcher<dispatch_primitive_type>(
286 _table.column(0).type(), hasher, _seed, _table.column(0), row_index);
289 for (
size_type i = 1; i < _table.num_columns(); ++i) {
290 if (!(_has_nulls && _table.column(i).is_null(row_index))) {
291 hash = cudf::hashing::detail::hash_combine(
293 cudf::type_dispatcher<dispatch_primitive_type>(
294 _table.column(i).type(), hasher, _seed, _table.column(i), row_index));
296 hash = cudf::hashing::detail::hash_combine(
297 hash, cuda::std::numeric_limits<hash_value_type>::max());
An immutable, non-owning view of device data as a column of elements that is trivially copyable and u...
T element(size_type element_index) const noexcept
Returns a copy of the element at the specified index.
Performs an equality comparison between two elements in two columns.
Function object for computing the hash value of a row in a column.
Performs a relational comparison between two elements in two tables.
row_equality_comparator(cudf::nullate::DYNAMIC const &has_nulls, std::shared_ptr< cudf::experimental::row::equality::preprocessed_table > lhs, std::shared_ptr< cudf::experimental::row::equality::preprocessed_table > rhs, null_equality nulls_are_equal)
Construct a new row equality comparator object.
bool operator()(cudf::experimental::row::lhs_index_type lhs_index, cudf::experimental::row::rhs_index_type rhs_index) const
Compares the specified rows for equality.
bool operator()(size_type lhs_row_index, size_type rhs_row_index) const
Compares the specified rows for equality.
Computes the hash value of a row in the given table.
auto operator()(size_type row_index) const
Computes the hash value of the row at row_index in the table
row_hasher(cudf::nullate::DYNAMIC const &has_nulls, table_device_view t, hash_value_type seed=DEFAULT_HASH_SEED)
Constructs a row_hasher object with a seed value.
row_hasher(cudf::nullate::DYNAMIC const &has_nulls, std::shared_ptr< cudf::experimental::row::equality::preprocessed_table > t, hash_value_type seed=DEFAULT_HASH_SEED)
Constructs a row_hasher object with a seed value.
Table device view that is usable in device memory.
A set of cudf::column_view's of the same size.
A set of cudf::column's of the same size.
Column device view class definitions.
lhs_index_type
Strongly typed index for left-hand side table rows.
rhs_index_type
Strongly typed index for right-hand side table rows.
uint32_t hash_value_type
Type of hash value.
#define CUDF_EXPECTS(...)
Macro for checking (pre-)conditions that throws an exception when a condition is violated.
null_equality
Enum to consider two nulls as equal or unequal.
int32_t size_type
Row index type for columns and tables.
bool is_primitive_row_op_compatible(cudf::table_view const &table)
Checks if a table is compatible with primitive row operations.
bool has_nulls(table_view const &view)
Returns True if the table has nulls in any of its columns.
bool equality_compare(Element lhs, Element rhs)
Alias for backward compatibility with legacy row operators.
cuda::std::conditional_t< cudf::is_numeric< T >(), T, void > primitive_type_t
Returns void if it's not a primitive type.
nullate::DYNAMIC defers the determination of nullability to run time rather than compile time....
Custom dispatcher for primitive types.
primitive_type_t< id_to_type< Id > > type
The underlying type.
Table device view class definitions.
Class definitions for (mutable)_table_view
Defines the mapping between cudf::type_id runtime type information and concrete C++ types.