-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Use dictionary indices in join functions #23534
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
Open
davidwendt
wants to merge
11
commits into
NVIDIA:main
Choose a base branch
from
davidwendt:match-dictionaries
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
095cac8
Improve join performance for dictionary columns
davidwendt e0525bc
check for empty input
davidwendt f34855d
Merge branch 'main' into match-dictionaries
davidwendt 4c9758d
Merge branch 'main' into match-dictionaries
davidwendt 49d0686
Merge branch 'main' into match-dictionaries
davidwendt 1fb0292
Merge branch 'main' into match-dictionaries
davidwendt 7c9abec
Merge branch 'main' into match-dictionaries
davidwendt f670a5d
cleanup doxygen; comments
davidwendt 7c9ef9e
Merge branch 'main' into match-dictionaries
davidwendt 94654f1
fix merge conflict
davidwendt f2debeb
update doxygen
davidwendt 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -158,6 +158,78 @@ std::pair<std::vector<std::unique_ptr<column>>, std::vector<table_view>> match_d | |
| return {std::move(dictionary_columns), std::move(updated_tables)}; | ||
| } | ||
|
|
||
| std::vector<std::unique_ptr<column>> match_dictionaries_to_indices( | ||
| std::span<dictionary_column_view const> input, | ||
| cuda::stream_ref stream, | ||
| rmm::device_async_resource_ref mr) | ||
| { | ||
| CUDF_EXPECTS(not input.empty(), "expect at least one dictionary", std::invalid_argument); | ||
|
|
||
| auto temp_mr = cudf::get_current_device_resource_ref(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we adapt this API to accept the temp_mr as a parameter? We're already doing that throughout the library so may as well add the new APIs correctly. |
||
| std::vector<cudf::column_view> keys(input.size()); | ||
| std::transform(input.begin(), input.end(), keys.begin(), [](auto& col) { return col.keys(); }); | ||
| auto all_keys = cudf::detail::concatenate(keys, stream, temp_mr); | ||
|
|
||
| auto new_keys = cudf::type_dispatcher( | ||
| keys.front().type(), unique_keys_dispatch_fn{}, all_keys->view(), stream, temp_mr); | ||
| auto keys_view = new_keys->view(); | ||
|
|
||
| std::vector<std::unique_ptr<column>> result(input.size()); | ||
| std::transform(input.begin(), input.end(), result.begin(), [keys_view, mr, stream](auto& col) { | ||
| return remap_indices(col, keys_view, stream, mr); | ||
| }); | ||
|
davidwendt marked this conversation as resolved.
|
||
| return result; | ||
| } | ||
|
|
||
| std::pair<std::vector<std::unique_ptr<column>>, std::vector<table_view>> | ||
| match_dictionaries_to_indices(std::vector<table_view> tables, | ||
| cuda::stream_ref stream, | ||
| rmm::device_async_resource_ref mr) | ||
| { | ||
| CUDF_EXPECTS(not tables.empty(), "expect at least one table", std::invalid_argument); | ||
|
|
||
| // Make a copy of all the column views from each table_view | ||
| std::vector<std::vector<column_view>> updated_columns; | ||
| std::transform(tables.begin(), tables.end(), std::back_inserter(updated_columns), [](auto& t) { | ||
| return std::vector<column_view>(t.begin(), t.end()); | ||
| }); | ||
|
|
||
| // Each column in a table must match in type. | ||
| // Once a dictionary column is found, all the corresponding column_views in the | ||
| // other table_views are matched. The matched column_views then replace the originals. | ||
| std::vector<std::unique_ptr<column>> index_columns; | ||
| auto first_table = tables.front(); | ||
|
davidwendt marked this conversation as resolved.
|
||
| for (size_type col_idx = 0; col_idx < first_table.num_columns(); ++col_idx) { | ||
| auto col = first_table.column(col_idx); | ||
| if (col.type().id() == type_id::DICTIONARY32) { | ||
| std::vector<dictionary_column_view> dict_views; // hold all column_views at col_idx | ||
| std::transform( | ||
| tables.begin(), tables.end(), std::back_inserter(dict_views), [col_idx](auto& t) { | ||
| return dictionary_column_view(t.column(col_idx)); | ||
| }); | ||
| // now match the keys and return index columns | ||
| auto idx_cols = dictionary::detail::match_dictionaries_to_indices(dict_views, stream, mr); | ||
| // replace the updated_columns vector entries for the set of columns at col_idx | ||
| auto dict_col_idx = 0; | ||
| for (auto& v : updated_columns) | ||
| v[col_idx] = idx_cols[dict_col_idx++]->view(); | ||
| // move the updated index columns into the main output vector | ||
| std::move(idx_cols.begin(), idx_cols.end(), std::back_inserter(index_columns)); | ||
| } | ||
| } | ||
| // All the new column_views are now included in updated_columns | ||
|
|
||
| // Rebuild the table_views from the column_views | ||
| std::vector<table_view> updated_tables; | ||
| std::transform(updated_columns.begin(), | ||
| updated_columns.end(), | ||
| std::back_inserter(updated_tables), | ||
| [](auto& v) { return table_view{v}; }); | ||
|
|
||
| // Return the new index columns and table_views | ||
| return {std::move(index_columns), std::move(updated_tables)}; | ||
| } | ||
|
|
||
| } // namespace detail | ||
|
|
||
| // external API | ||
|
|
||
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
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.