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(rust, python): don't set sorted flag if we reverse sort the left … #6772

Merged
merged 1 commit into from
Feb 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion polars/polars-core/src/frame/hash_join/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,13 +357,13 @@ impl DataFrame {
if left_join && join_tuples.len() == self.height() {
self.clone()
} else {
// left join tuples are always in ascending order
let sorted = if left_join || sorted {
IsSorted::Ascending
} else {
IsSorted::Not
};

// left join tuples are always in ascending order
self._take_unchecked_slice2(join_tuples, true, sorted)
}
}
Expand Down
7 changes: 6 additions & 1 deletion polars/polars-core/src/frame/hash_join/sort_merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ pub fn _sort_or_hash_inner(
s_right: &Series,
verbose: bool,
) -> ((Vec<IdxSize>, Vec<IdxSize>), bool) {
// We check if keys are sorted.
// - If they are we can do a sorted merge join
// If one of the keys is not, it can still be faster to sort that key and use
// the `arg_sort` indices to revert the sort once the join keys are determined.
let size_factor_rhs = s_right.len() as f32 / s_left.len() as f32;
let size_factor_lhs = s_left.len() as f32 / s_right.len() as f32;
let size_factor_acceptable = std::env::var("POLARS_JOIN_SORT_FACTOR")
Expand Down Expand Up @@ -247,7 +251,8 @@ pub fn _sort_or_hash_inner(
});
});

((left, right), true)
// set sorted to `false` as we reverse sorted the left key.
((left, right), false)
}
_ => s_left.hash_join_inner(s_right),
}
Expand Down