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 
10 #include <cudf/types.hpp>
12 #include <cudf/utilities/export.hpp>
14 
15 #include <rmm/device_uvector.hpp>
16 
17 #include <cuda/std/limits>
18 #include <cuda/stream>
19 
20 #include <cstddef>
21 #include <cstdint>
22 #include <memory>
23 #include <optional>
24 #include <utility>
25 
31 namespace CUDF_EXPORT cudf {
32 
45 enum class join_kind : int32_t {
46  INNER_JOIN = 0,
47  LEFT_JOIN = 1,
48  FULL_JOIN = 2,
49  LEFT_SEMI_JOIN = 3,
50  LEFT_ANTI_JOIN = 4
51 };
52 
60 enum class join_prefilter : bool { NO = false, YES = true };
61 
68 enum class nullable_join : bool { YES = true, NO = false };
69 
80 CUDF_HOST_DEVICE constexpr size_type JoinNoMatch = cuda::std::numeric_limits<size_type>::min();
81 
91  std::unique_ptr<rmm::device_uvector<size_type>>
94 
102  join_match_context(table_view const& left_table, // NOLINT(modernize-pass-by-value)
103  std::unique_ptr<rmm::device_uvector<size_type>> match_counts)
104  : _left_table{left_table}, _match_counts{std::move(match_counts)}
105  {
106  }
107  join_match_context(join_match_context const&) = delete;
108  join_match_context& operator=(join_match_context const&) = delete;
115  virtual ~join_match_context() = default;
116 };
117 
129  std::unique_ptr<join_match_context>
133 };
134 
168 std::pair<std::unique_ptr<rmm::device_uvector<size_type>>,
169  std::unique_ptr<rmm::device_uvector<size_type>>>
170 inner_join(cudf::table_view const& left_keys,
171  cudf::table_view const& right_keys,
172  null_equality compare_nulls = null_equality::EQUAL,
173  cuda::stream_ref stream = cudf::get_default_stream(),
175 
209 std::pair<std::unique_ptr<rmm::device_uvector<size_type>>,
210  std::unique_ptr<rmm::device_uvector<size_type>>>
211 left_join(cudf::table_view const& left_keys,
212  cudf::table_view const& right_keys,
213  null_equality compare_nulls = null_equality::EQUAL,
214  cuda::stream_ref stream = cudf::get_default_stream(),
216 
250 std::pair<std::unique_ptr<rmm::device_uvector<size_type>>,
251  std::unique_ptr<rmm::device_uvector<size_type>>>
252 full_join(cudf::table_view const& left_keys,
253  cudf::table_view const& right_keys,
254  null_equality compare_nulls = null_equality::EQUAL,
255  cuda::stream_ref stream = cudf::get_default_stream(),
257 
286 std::unique_ptr<cudf::table> cross_join(
287  cudf::table_view const& left,
288  cudf::table_view const& right,
289  cuda::stream_ref stream = cudf::get_default_stream(),
291 
364 std::pair<std::unique_ptr<rmm::device_uvector<size_type>>,
365  std::unique_ptr<rmm::device_uvector<size_type>>>
367  cudf::table_view const& right,
370  cudf::ast::expression const& predicate,
372  std::optional<std::size_t> output_size = std::nullopt,
373  cuda::stream_ref stream = cudf::get_default_stream(),
375 
411 [[nodiscard]] std::pair<std::size_t, std::unique_ptr<rmm::device_uvector<size_type>>>
413  cudf::table_view const& left,
414  cudf::table_view const& right,
417  cudf::ast::expression const& predicate,
419  cuda::stream_ref stream = cudf::get_default_stream(),
421 
484 std::pair<std::unique_ptr<rmm::device_uvector<size_type>>,
485  std::unique_ptr<rmm::device_uvector<size_type>>>
487  cudf::table_view const& left,
488  cudf::table_view const& right,
491  std::string const& predicate_code,
493  bool is_ptx = false,
494  cuda::stream_ref stream = cudf::get_default_stream(),
496 
513 std::pair<std::unique_ptr<rmm::device_uvector<size_type>>,
514  std::unique_ptr<rmm::device_uvector<size_type>>>
516  cudf::table_view const& left,
517  cudf::table_view const& right,
520  cudf::ast::expression const& predicate,
522  cuda::stream_ref stream = cudf::get_default_stream(),
524  // end of group
526 
527 } // namespace CUDF_EXPORT cudf
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.
Class definitions for building and evaluating abstract syntax tree expressions.
join_prefilter
Specifies whether a join implementation should apply an optional prefilter that reduces candidate row...
Definition: join.hpp:60
std::pair< std::size_t, std::unique_ptr< rmm::device_uvector< size_type > > > filter_join_indices_output_size(cudf::table_view const &left, cudf::table_view const &right, cudf::device_span< size_type const > left_indices, cudf::device_span< size_type const > right_indices, cudf::ast::expression const &predicate, cudf::join_kind join_kind, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Returns the exact output size of filter_join_indices without materializing the filtered index vectors...
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_keys, cudf::table_view const &right_keys, null_equality compare_nulls=null_equality::EQUAL, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Returns a pair of row index vectors corresponding to an inner join between the specified tables.
constexpr CUDF_HOST_DEVICE size_type JoinNoMatch
Sentinel value used to indicate an unmatched row index in join operations.
Definition: join.hpp:80
std::pair< std::unique_ptr< rmm::device_uvector< size_type > >, std::unique_ptr< rmm::device_uvector< size_type > > > filter_join_indices_jit(cudf::table_view const &left, cudf::table_view const &right, cudf::device_span< size_type const > left_indices, cudf::device_span< size_type const > right_indices, cudf::ast::expression const &predicate, cudf::join_kind join_kind, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Filters join indices using a JIT-compiled predicate from an AST expression.
std::unique_ptr< cudf::table > cross_join(cudf::table_view const &left, cudf::table_view const &right, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Performs a cross join on two tables (left, right)
std::pair< std::unique_ptr< rmm::device_uvector< size_type > >, std::unique_ptr< rmm::device_uvector< size_type > > > filter_join_indices(cudf::table_view const &left, cudf::table_view const &right, cudf::device_span< size_type const > left_indices, cudf::device_span< size_type const > right_indices, cudf::ast::expression const &predicate, cudf::join_kind join_kind, std::optional< std::size_t > output_size=std::nullopt, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Filters join result indices based on a conditional predicate and join type.
nullable_join
Specifies whether join-key columns may contain nulls.
Definition: join.hpp:68
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_keys, cudf::table_view const &right_keys, null_equality compare_nulls=null_equality::EQUAL, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Returns a pair of row index vectors corresponding to a full join between the specified tables.
join_kind
Specifies the type of join operation to perform.
Definition: join.hpp:45
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_keys, cudf::table_view const &right_keys, null_equality compare_nulls=null_equality::EQUAL, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Returns a pair of row index vectors corresponding to a left join between the specified tables.
@ LEFT_ANTI_JOIN
Left anti join: left rows that have no matches in right table.
@ LEFT_SEMI_JOIN
Left semi join: left rows that have matches in right table.
@ FULL_JOIN
Full outer join: all rows from both tables.
@ LEFT_JOIN
Left join: all rows from left table plus matching rows from right.
@ INNER_JOIN
Inner join: only matching rows from both tables.
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 getting and setting the current device memory resource.
cuDF interfaces
Definition: host_udf.hpp:27
A generic expression that can be evaluated to return a value.
Definition: expressions.hpp:72
Holds context information about matches between tables during a join operation.
Definition: join.hpp:89
join_match_context(join_match_context &&)=default
Move constructor.
join_match_context & operator=(join_match_context &&)=default
Move assignment operator.
std::unique_ptr< rmm::device_uvector< size_type > > _match_counts
Definition: join.hpp:92
table_view _left_table
View of the left table involved in the join operation.
Definition: join.hpp:90
join_match_context(table_view const &left_table, std::unique_ptr< rmm::device_uvector< size_type >> match_counts)
Construct a join_match_context.
Definition: join.hpp:102
virtual ~join_match_context()=default
Virtual destructor for proper polymorphic deletion.
Stores context information for partitioned join operations.
Definition: join.hpp:128
size_type left_start_idx
The starting row index of the current left table partition.
Definition: join.hpp:131
std::unique_ptr< join_match_context > left_table_context
The match context from a previous inner_join_match_context call.
Definition: join.hpp:130
size_type left_end_idx
The ending row index (exclusive) of the current left table partition.
Definition: join.hpp:132
Class definitions for (mutable)_table_view
Type declarations for libcudf.
#define CUDF_HOST_DEVICE
Indicates that the function or method is usable on host and device.
Definition: types.hpp:21