hash_join.hpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2025-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 
6 #pragma once
7 
8 #include <cudf/hashing.hpp>
9 #include <cudf/join/join.hpp>
11 #include <cudf/types.hpp>
13 #include <cudf/utilities/export.hpp>
15 #include <cudf/utilities/span.hpp>
16 
17 #include <rmm/device_uvector.hpp>
18 
19 #include <cuda/stream>
20 
21 #include <optional>
22 #include <utility>
23 
30 namespace CUDF_EXPORT cudf {
31 
37 // forward declaration
38 namespace hashing::detail {
42 template <typename T>
44 } // namespace hashing::detail
45 
46 namespace detail {
50 template <typename T>
51 class hash_join;
52 } // namespace detail
53 
61 class hash_join {
62  public:
65 
66  hash_join() = delete;
67  ~hash_join();
68  hash_join(hash_join const&) = delete;
69  hash_join(hash_join&&) = delete;
70  hash_join& operator=(hash_join const&) = delete;
71  hash_join& operator=(hash_join&&) = delete;
72 
87  null_equality compare_nulls,
88  cuda::stream_ref stream = cudf::get_default_stream(),
89  cuda::mr::any_resource<cuda::mr::device_accessible> mr =
91 
112  null_equality compare_nulls,
113  double load_factor,
114  cuda::stream_ref stream = cudf::get_default_stream(),
115  cuda::mr::any_resource<cuda::mr::device_accessible> mr =
117 
140  [[nodiscard]] std::pair<std::unique_ptr<rmm::device_uvector<size_type>>,
141  std::unique_ptr<rmm::device_uvector<size_type>>>
143  std::optional<std::size_t> output_size = {},
144  cuda::stream_ref stream = cudf::get_default_stream(),
146 
169  [[nodiscard]] std::pair<std::unique_ptr<rmm::device_uvector<size_type>>,
170  std::unique_ptr<rmm::device_uvector<size_type>>>
172  std::optional<std::size_t> output_size = {},
173  cuda::stream_ref stream = cudf::get_default_stream(),
175 
198  [[nodiscard]] std::pair<std::unique_ptr<rmm::device_uvector<size_type>>,
199  std::unique_ptr<rmm::device_uvector<size_type>>>
201  std::optional<std::size_t> output_size = {},
202  cuda::stream_ref stream = cudf::get_default_stream(),
204 
218  [[nodiscard]] std::size_t inner_join_size(
219  cudf::table_view const& left, cuda::stream_ref stream = cudf::get_default_stream()) const;
220 
234  [[nodiscard]] std::size_t left_join_size(
235  cudf::table_view const& left, cuda::stream_ref stream = cudf::get_default_stream()) const;
236 
252  [[nodiscard]] std::size_t full_join_size(
253  cudf::table_view const& left,
254  cuda::stream_ref stream = cudf::get_default_stream(),
256 
279  cudf::table_view const& left,
280  cuda::stream_ref stream = cudf::get_default_stream(),
282 
304  cudf::table_view const& left,
305  cuda::stream_ref stream = cudf::get_default_stream(),
307 
329  cudf::table_view const& left,
330  cuda::stream_ref stream = cudf::get_default_stream(),
332 
353  [[nodiscard]] std::pair<std::unique_ptr<rmm::device_uvector<size_type>>,
354  std::unique_ptr<rmm::device_uvector<size_type>>>
356  cudf::join_partition_context const& context,
357  cuda::stream_ref stream = cudf::get_default_stream(),
359 
379  [[nodiscard]] std::pair<std::unique_ptr<rmm::device_uvector<size_type>>,
380  std::unique_ptr<rmm::device_uvector<size_type>>>
382  cudf::join_partition_context const& context,
383  cuda::stream_ref stream = cudf::get_default_stream(),
385 
409  [[nodiscard]] std::pair<std::unique_ptr<rmm::device_uvector<size_type>>,
410  std::unique_ptr<rmm::device_uvector<size_type>>>
412  cudf::join_partition_context const& context,
413  cuda::stream_ref stream = cudf::get_default_stream(),
415 
435  [[nodiscard]] static std::pair<std::unique_ptr<rmm::device_uvector<size_type>>,
436  std::unique_ptr<rmm::device_uvector<size_type>>>
440  size_type left_table_num_rows,
441  size_type right_table_num_rows,
442  cuda::stream_ref stream = cudf::get_default_stream(),
444 
445  private:
446  std::unique_ptr<impl_type const> _impl;
447 };
448  // end of group
450 
451 } // namespace CUDF_EXPORT cudf
Forward declaration for our hash join.
Definition: hash_join.hpp:51
Hash join that builds a hash table with the right table on construction and probes results in subsequ...
Definition: hash_join.hpp:61
std::pair< std::unique_ptr< rmm::device_uvector< size_type > >, std::unique_ptr< rmm::device_uvector< size_type > > > partitioned_inner_join(cudf::join_partition_context const &context, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref()) const
Performs an inner join on a partition of the probe table.
static std::pair< std::unique_ptr< rmm::device_uvector< size_type > >, std::unique_ptr< rmm::device_uvector< size_type > > > finalize_partitioned_full_join(cudf::host_span< cudf::device_span< size_type const > const > left_partials, cudf::host_span< cudf::device_span< size_type const > const > right_partials, size_type left_table_num_rows, size_type right_table_num_rows, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Finalizes a partitioned full join by concatenating all per-partition results and appending the unmatc...
hash_join(cudf::table_view const &right, null_equality compare_nulls, cuda::stream_ref stream=cudf::get_default_stream(), cuda::mr::any_resource< cuda::mr::device_accessible > mr=cudf::get_current_device_resource_ref())
Construct a hash join object for subsequent probe calls.
typename cudf::detail::hash_join< cudf::hashing::detail::MurmurHash3_x86_32< cudf::hash_value_type > > impl_type
Implementation type.
Definition: hash_join.hpp:64
cudf::join_match_context left_join_match_context(cudf::table_view const &left, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref()) const
Returns context information about matches between the left and right tables.
cudf::join_match_context full_join_match_context(cudf::table_view const &left, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref()) const
Returns context information about matches between the left and right tables.
std::size_t full_join_size(cudf::table_view const &left, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref()) const
std::pair< std::unique_ptr< rmm::device_uvector< size_type > >, std::unique_ptr< rmm::device_uvector< size_type > > > inner_join(cudf::table_view const &left, std::optional< std::size_t > output_size={}, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref()) const
std::pair< std::unique_ptr< rmm::device_uvector< size_type > >, std::unique_ptr< rmm::device_uvector< size_type > > > left_join(cudf::table_view const &left, std::optional< std::size_t > output_size={}, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref()) const
std::pair< std::unique_ptr< rmm::device_uvector< size_type > >, std::unique_ptr< rmm::device_uvector< size_type > > > partitioned_full_join(cudf::join_partition_context const &context, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref()) const
Performs a full join probe on a partition of the probe table.
std::pair< std::unique_ptr< rmm::device_uvector< size_type > >, std::unique_ptr< rmm::device_uvector< size_type > > > partitioned_left_join(cudf::join_partition_context const &context, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref()) const
Performs a left join on a partition of the probe table.
std::size_t left_join_size(cudf::table_view const &left, cuda::stream_ref stream=cudf::get_default_stream()) const
std::size_t inner_join_size(cudf::table_view const &left, cuda::stream_ref stream=cudf::get_default_stream()) const
hash_join(cudf::table_view const &right, nullable_join has_nulls, null_equality compare_nulls, double load_factor, cuda::stream_ref stream=cudf::get_default_stream(), cuda::mr::any_resource< cuda::mr::device_accessible > mr=cudf::get_current_device_resource_ref())
Construct a hash join object for subsequent probe calls.
cudf::join_match_context inner_join_match_context(cudf::table_view const &left, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref()) const
Returns context information about matches between the left and right tables.
std::pair< std::unique_ptr< rmm::device_uvector< size_type > >, std::unique_ptr< rmm::device_uvector< size_type > > > full_join(cudf::table_view const &left, std::optional< std::size_t > output_size={}, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref()) const
Forward declaration for our Murmur Hash 3 implementation.
Definition: hash_join.hpp:43
A set of cudf::column_view's of the same size.
Definition: table_view.hpp:206
APIs for querying the default CUDA stream and per-thread default stream status.
nullable_join
Specifies whether join-key columns may contain nulls.
Definition: join.hpp:68
cuda::stream_ref const get_default_stream()
Get the current default stream.
rmm::device_async_resource_ref get_current_device_resource_ref()
Get the current device memory resource reference.
cuda::mr::resource_ref< cuda::mr::device_accessible > device_async_resource_ref
cuda::std::span< T, Extent > device_span
Device span is an alias of cuda::std::span.
Definition: span.hpp:300
null_equality
Enum to consider two nulls as equal or unequal.
Definition: types.hpp:132
int32_t size_type
Row index type for columns and tables.
Definition: types.hpp:76
APIs for computing hash values of columns and tables using various hash algorithms.
Common types and utilities shared by cuDF's join APIs.
APIs for getting and setting the current device memory resource.
cuDF interfaces
Definition: host_udf.hpp:27
bool has_nulls(table_view const &view)
Returns True if the table has nulls in any of its columns.
APIs for spans.
Host span, a non-owning view over a contiguous sequence of host-accessible elements.
Definition: span.hpp:65
Holds context information about matches between tables during a join operation.
Definition: join.hpp:89
Stores context information for partitioned join operations.
Definition: join.hpp:128
Class definitions for (mutable)_table_view
Type declarations for libcudf.