-
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
Changes from all commits
095cac8
e0525bc
f34855d
4c9758d
49d0686
1fb0292
7c9abec
f670a5d
7c9ef9e
94654f1
f2debeb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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.
Contributor
Author
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. I don't know how to do that. Can you point me to an example?
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. #23490 is probably the smallest merged example.
Contributor
Author
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. I tried to change the new APIs but this ended up cascading to the other existing APIs that were not touched in this PR. I think it would be better to wait until after #23642 merges or do this in a follow-up PR.
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. OK no worries, it's not urgent. I assume Bradley and Niranda are working through APIs in some systematic order that ensures dependent APIs are updated after their dependencies. |
||
| 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 | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.