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

fix: Only push predicates depending on the subset columns past unique() #14668

Merged
merged 5 commits into from
Feb 25, 2024

Conversation

nameexhaustion
Copy link
Collaborator

Fix #14595.

Also improves the display in explain() to show maintain_order and keep_strategy, as these are useful to know when debugging.

@github-actions github-actions bot added fix Bug fix python Related to Python Polars rust Related to Rust Polars labels Feb 24, 2024
let mut root_count = 0;

// if this condition is called more than once, its a binary or ternary operation.
let condition = |_| {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

From what I understand this wanted to block predicates that had more than 1 column input, but because mut root_count is not reset per predicate it would end up blocking all predicates after the first call.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, yeap. That had to reset.

true
}
if let Some(ref subset) = options.subset {
// Predicates on the subset can pass.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

since unique() is equivalent to group_by().gather(index), so similar to group_by we can pass predicates on the subset (<=>group key) columns

@@ -132,7 +133,7 @@ where
for name in root_names {
if condition(name) {
remove_keys.push(key.clone());
continue;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

would insert the same key multiple times

Copy link

codecov bot commented Feb 24, 2024

Codecov Report

Attention: Patch coverage is 68.18182% with 7 lines in your changes are missing coverage. Please review.

Project coverage is 80.82%. Comparing base (849953b) to head (5fb343d).
Report is 5 commits behind head on main.

Files Patch % Lines
crates/polars-plan/src/logical_plan/tree_format.rs 0.00% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #14668      +/-   ##
==========================================
+ Coverage   80.79%   80.82%   +0.03%     
==========================================
  Files        1326     1326              
  Lines      173249   173215      -34     
  Branches     2456     2455       -1     
==========================================
+ Hits       139976   140007      +31     
+ Misses      32800    32736      -64     
+ Partials      473      472       -1     

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

}
if let Some(ref subset) = options.subset {
// Predicates on the subset can pass.
let mut names_set = PlHashSet::<Arc<str>>::with_capacity(subset.len());
Copy link
Member

Choose a reason for hiding this comment

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

Can we use &str here? Then we don't have to heap allocate the Arc.

let mut root_count = 0;

// if this condition is called more than once, its a binary or ternary operation.
let condition = |_| {
Copy link
Member

Choose a reason for hiding this comment

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

Ah, yeap. That had to reset.

@ritchie46
Copy link
Member

I agree on the fact that this should be treated the same as group by. I've left one minor comment.

@nameexhaustion
Copy link
Collaborator Author

updated to use &str instead of allocating Arc<str> - originally did this because I was getting a borrow issue, but it seems I just need to clone the ref subset

409 |                 if let Some(ref subset) = options.subset {
    |                             ---------- borrow of `options.subset.0` occurs here
...
423 |                         options
    |                         ^^^^^^^ move out of `options` occurs here
...
426 |                 } else {
    |                 - borrow might be used here, when `names_set` is dropped and runs the destructor for type `hashbrown::set::HashSet<&str, polars_core::export::ahash::RandomState>`

@ritchie46
Copy link
Member

but it seems I just need to clone the ref subset

Which is cheap because of Arc<Vec<_>>. :)

@ritchie46 ritchie46 merged commit f52473a into pola-rs:main Feb 25, 2024
23 checks passed
@nameexhaustion nameexhaustion deleted the unique branch February 26, 2024 02:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Bug fix python Related to Python Polars rust Related to Rust Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Non-deterministic behaviour when using is_null() in LazyFrame
2 participants