Skip to content

Commit

Permalink
fix(rust, python): don't set sorted flag if we reverse sort the left … (
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 authored Feb 10, 2023
1 parent 2d7d728 commit 1a45830
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
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

0 comments on commit 1a45830

Please sign in to comment.