Skip to content
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

feat: Enable joins between compatible differing numeric key columns #20332

Merged
merged 8 commits into from
Dec 17, 2024

Conversation

nameexhaustion
Copy link
Collaborator

@nameexhaustion nameexhaustion commented Dec 17, 2024

Joins between keys with differing numeric types now succeed if there is a compatible supertype to which both can be casted to without loss of information.

Fixes #15338

@github-actions github-actions bot added enhancement New feature or an improvement of an existing feature python Related to Python Polars rust Related to Rust Polars labels Dec 17, 2024
@nameexhaustion nameexhaustion changed the title feat: Automatically upcast numeric join keys feat: Automatically upcast compatible numeric join keys Dec 17, 2024
@ritchie46
Copy link
Member

Nice, I think we should follow up with a SupertypeFlag that allows (only) lossless supercasting.

Copy link

codecov bot commented Dec 17, 2024

Codecov Report

Attention: Patch coverage is 80.67227% with 23 lines in your changes missing coverage. Please review.

Project coverage is 79.50%. Comparing base (e03555c) to head (2caca96).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
crates/polars-core/src/utils/supertype.rs 54.34% 21 Missing ⚠️
.../polars-ops/src/frame/join/hash_join/sort_merge.rs 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #20332      +/-   ##
==========================================
+ Coverage   79.49%   79.50%   +0.01%     
==========================================
  Files        1569     1569              
  Lines      218634   218782     +148     
  Branches     2462     2462              
==========================================
+ Hits       173799   173953     +154     
+ Misses      44267    44261       -6     
  Partials      568      568              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@nameexhaustion nameexhaustion marked this pull request as ready for review December 17, 2024 12:10
@nameexhaustion nameexhaustion marked this pull request as draft December 17, 2024 12:10
let key_cols_coalesced =
options.args.should_coalesce() && matches!(&options.args.how, JoinType::Full);

if key_cols_coalesced {
Copy link
Collaborator Author

@nameexhaustion nameexhaustion Dec 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made it so that we maintain the input column types in the output for all cases except for full-join with coalesce=True. Alternatively we could also just always use the supertype in the result.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that what you did now is correct. 👍

@nameexhaustion nameexhaustion marked this pull request as ready for review December 17, 2024 12:13
@nameexhaustion nameexhaustion changed the title feat: Automatically upcast compatible numeric join keys feat: Enable joins between compatible numeric join keys Dec 17, 2024
@nameexhaustion nameexhaustion changed the title feat: Enable joins between compatible numeric join keys feat: Enable joins between compatible numeric key columns Dec 17, 2024
@nameexhaustion nameexhaustion changed the title feat: Enable joins between compatible numeric key columns feat: Enable joins between compatible differing numeric key columns Dec 17, 2024
@ritchie46 ritchie46 merged commit 00837b8 into pola-rs:main Dec 17, 2024
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or an improvement of an existing feature python Related to Python Polars rust Related to Rust Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow join on different types if upcast is safe
2 participants