Repository navigation
Refactor distinct join to use primitive row operators when proper #17726
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
Merged
rapids-bot
merged 22 commits into
NVIDIA:branch-25.06
from
PointKernel:primitive-row-op
May 13, 2025
Merged
Changes from 16 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
369768a
Add naive primitive row operator with no null handling
PointKernel 163a248
Update distonct join to use primitive row operators
PointKernel d330084
Add null hanlding to primitive row operators
PointKernel 05edbd9
Cleanups
PointKernel e84d8dd
Clean up distinct join details
PointKernel c9242fc
Merge remote-tracking branch 'upstream/branch-25.06' into primitive_r…
tgujar c815ed4
fix slowdown
tgujar 3bd6480
Merge remote-tracking branch 'tanmay/primitive_row_op' into primitive…
PointKernel 3525863
Formatting
PointKernel 4bc4035
Cleanups
PointKernel d5e8e47
Merge remote-tracking branch 'upstream/branch-25.06' into primitive-r…
PointKernel ed7c550
Merge remote-tracking branch 'upstream/branch-25.06' into primitive-r…
PointKernel ce10a03
Cleanups
PointKernel 309b379
Move distinct join query to a free function
PointKernel 207584a
Move code around
PointKernel 03adc0b
Final cleanup
PointKernel 615c587
Minor cleanups
PointKernel 105111b
Merge remote-tracking branch 'upstream/branch-25.06' into primitive-r…
PointKernel 8b18472
Fix doc typos
PointKernel 2443caf
Update docs
PointKernel 3d37b69
Renaming
PointKernel da73099
Merge branch 'branch-25.06' into primitive-row-op
PointKernel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,249 @@ | ||
| /* | ||
| * Copyright (c) 2025, 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. | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <cudf/column/column_device_view.cuh> | ||
| #include <cudf/detail/utilities/assert.cuh> | ||
| #include <cudf/hashing/detail/hash_functions.cuh> | ||
| #include <cudf/hashing/detail/hashing.hpp> | ||
| #include <cudf/table/experimental/row_operators.cuh> | ||
| #include <cudf/table/row_operators.cuh> | ||
| #include <cudf/table/table_device_view.cuh> | ||
| #include <cudf/utilities/traits.hpp> | ||
| #include <cudf/utilities/type_dispatcher.hpp> | ||
|
|
||
| #include <cuda/std/limits> | ||
| #include <cuda/std/type_traits> | ||
|
|
||
| namespace CUDF_EXPORT cudf { | ||
| namespace row::primitive { | ||
|
|
||
| /** | ||
| * @brief Returns `void` if it's not a primitive type | ||
| */ | ||
| template <typename T> | ||
| using primitive_type_t = cuda::std::conditional_t<cudf::is_numeric<T>(), T, void>; | ||
|
|
||
| /** | ||
| * @brief Custom dispatcher for primitive types | ||
| */ | ||
| template <cudf::type_id Id> | ||
| struct dispatch_primitive_type { | ||
| using type = primitive_type_t<id_to_type<Id>>; ///< The underlying type | ||
| }; | ||
|
|
||
| /** | ||
| * @brief Performs an equality comparison between two elements in two columns. | ||
| */ | ||
| class element_equality_comparator { | ||
| public: | ||
| /** | ||
| * @brief Construct type-dispatched function object for comparing equality | ||
| * between two elements. | ||
| * | ||
| * @note `lhs` and `rhs` may be the same. | ||
| * | ||
| * @param lhs The column containing the first element | ||
| * @param rhs The column containing the second element (may be the same as lhs) | ||
| */ | ||
| __host__ __device__ element_equality_comparator(column_device_view lhs, column_device_view rhs) | ||
| : _lhs{lhs}, _rhs{rhs} | ||
| { | ||
| } | ||
|
|
||
| /** | ||
| * @brief Compares the specified elements for equality. | ||
| * | ||
| * @param lhs_element_index The index of the first element | ||
| * @param rhs_element_index The index of the second element | ||
| * @return True if lhs and rhs element are equal | ||
| */ | ||
| template <typename Element, CUDF_ENABLE_IF(cudf::is_equality_comparable<Element, Element>())> | ||
| __device__ bool operator()(size_type lhs_element_index, size_type rhs_element_index) const | ||
| { | ||
| return cudf::equality_compare(_lhs.element<Element>(lhs_element_index), | ||
| _rhs.element<Element>(rhs_element_index)); | ||
| } | ||
|
|
||
| // @cond | ||
| template <typename Element, CUDF_ENABLE_IF(not cudf::is_equality_comparable<Element, Element>())> | ||
| __device__ bool operator()(size_type, size_type) const | ||
| { | ||
| CUDF_UNREACHABLE("Attempted to compare elements of uncomparable types."); | ||
| } | ||
| // @endcond | ||
|
|
||
| private: | ||
| column_device_view _lhs; | ||
| column_device_view _rhs; | ||
| }; | ||
|
|
||
| /** | ||
| * @brief Performs a relational comparison between two elements in two tables. | ||
| */ | ||
| class row_equality_comparator { | ||
| public: | ||
| /** | ||
| * @brief Construct a new row equality comparator object | ||
| * | ||
| * @param has_nulls Indicates if either input column contains nulls | ||
| * @param lhs Preprocessed table containing the first element | ||
| * @param rhs Preprocessed table containing the second element (may be the same as lhs) | ||
| * @param nulls_are_equal Indicates if two null elements are treated as equivalent | ||
| */ | ||
| 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) | ||
| : _has_nulls{has_nulls}, _lhs{*lhs}, _rhs{*rhs}, _nulls_are_equal{nulls_are_equal} | ||
| { | ||
| CUDF_EXPECTS(_lhs.num_columns() == _rhs.num_columns(), "Mismatched number of columns."); | ||
| } | ||
|
|
||
| /** | ||
| * @brief Compares the specified rows for equality. | ||
| * | ||
| * @param lhs_row_index The index of the first row to compare (in the lhs table) | ||
| * @param rhs_row_index The index of the second row to compare (in the rhs table) | ||
| * @return true if both rows are equal, otherwise false | ||
| */ | ||
| __device__ bool operator()(size_type lhs_row_index, size_type rhs_row_index) const | ||
| { | ||
| if (_has_nulls) { | ||
| bool const lhs_is_null{_lhs.column(0).is_null(lhs_row_index)}; | ||
| bool const rhs_is_null{_rhs.column(0).is_null(rhs_row_index)}; | ||
| if (lhs_is_null and rhs_is_null) { | ||
| return _nulls_are_equal == null_equality::EQUAL; | ||
| } else if (lhs_is_null != rhs_is_null) { | ||
| return false; | ||
| } | ||
| } | ||
| return cudf::type_dispatcher<dispatch_primitive_type>( | ||
| _lhs.begin()->type(), | ||
| element_equality_comparator{_lhs.column(0), _rhs.column(0)}, | ||
| lhs_row_index, | ||
| rhs_row_index); | ||
| } | ||
|
|
||
| private: | ||
| cudf::nullate::DYNAMIC _has_nulls; | ||
| table_device_view _lhs; | ||
| table_device_view _rhs; | ||
| null_equality _nulls_are_equal; | ||
| }; | ||
|
|
||
| /** | ||
| * @brief Function object for computing the hash value of a row in a column. | ||
| * | ||
| * @tparam Hash Hash functor to use for hashing elements | ||
| */ | ||
| template <template <typename> class Hash> | ||
| class element_hasher { | ||
| public: | ||
| /** | ||
| * @brief Constructs a function object for hashing an element in the given column | ||
| * | ||
| * @param seed The seed to use for the hash function | ||
| */ | ||
| __device__ element_hasher(hash_value_type seed) : _seed{seed} {} | ||
|
|
||
| /** | ||
| * @brief Returns the hash value of the given element in the given column. | ||
| * | ||
| * @tparam T The type of the element to hash | ||
| * @param col The column to hash | ||
| * @param row_index The index of the row to hash | ||
| * @return The hash value of the given element | ||
| */ | ||
| template <typename T, CUDF_ENABLE_IF(column_device_view::has_element_accessor<T>())> | ||
| __device__ hash_value_type operator()(column_device_view const& col, size_type row_index) const | ||
| { | ||
| return Hash<T>{_seed}(col.element<T>(row_index)); | ||
| } | ||
|
|
||
| // @cond | ||
| template <typename T, CUDF_ENABLE_IF(not column_device_view::has_element_accessor<T>())> | ||
| __device__ hash_value_type operator()(column_device_view const&, size_type) const | ||
| { | ||
| CUDF_UNREACHABLE("Unsupported type in hash."); | ||
| } | ||
| // @endcond | ||
|
|
||
| private: | ||
| hash_value_type _seed; | ||
| }; | ||
|
|
||
| /** | ||
| * @brief Computes the hash value of a row in the given table. | ||
| * | ||
| * @tparam Hash Hash functor to use for hashing elements. | ||
| */ | ||
| template <template <typename> class Hash> | ||
| class row_hasher { | ||
| public: | ||
| row_hasher() = delete; | ||
|
|
||
| /** | ||
| * @brief Constructs a row_hasher object with a seed value. | ||
| * | ||
| * @param has_nulls Indicates if the input column contains nulls | ||
| * @param t A table_device_view to hash | ||
| * @param seed A seed value to use for hashing | ||
| */ | ||
| row_hasher(cudf::nullate::DYNAMIC const& has_nulls, table_device_view t, hash_value_type seed) | ||
| : _has_nulls{has_nulls}, _table{t}, _seed{seed} | ||
| { | ||
| } | ||
|
|
||
| /** | ||
| * @brief Constructs a row_hasher object with a seed value. | ||
| * | ||
| * @param has_nulls Indicates if the input column contains nulls | ||
| * @param t Preprocessed table to hash | ||
| * @param seed A seed value to use for hashing | ||
| */ | ||
| row_hasher(cudf::nullate::DYNAMIC const& has_nulls, | ||
| std::shared_ptr<cudf::experimental::row::equality::preprocessed_table> t, | ||
| hash_value_type seed) | ||
| : _has_nulls{has_nulls}, _table{*t}, _seed{seed} | ||
| { | ||
| } | ||
|
|
||
| /** | ||
| * @brief Computes the hash value of the row at `row_index` in the `table` | ||
| * | ||
| * @param row_index The index of the row in the `table` to hash | ||
| * @return The hash value of the row at `row_index` in the `table` | ||
| */ | ||
| __device__ auto operator()(size_type row_index) const | ||
| { | ||
| if (_has_nulls && _table.column(0).is_null(row_index)) { | ||
| return cuda::std::numeric_limits<hash_value_type>::max(); | ||
| } | ||
| return cudf::type_dispatcher<dispatch_primitive_type>( | ||
| _table.column(0).type(), element_hasher<Hash>{_seed}, _table.column(0), row_index); | ||
| } | ||
|
|
||
| private: | ||
| cudf::nullate::DYNAMIC _has_nulls; | ||
| table_device_view _table; | ||
| hash_value_type _seed; | ||
| }; | ||
|
|
||
| } // namespace row::primitive | ||
| } // namespace CUDF_EXPORT cudf |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.