Skip to content
Open
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
20 changes: 17 additions & 3 deletions datafusion/core/src/physical_planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1382,15 +1382,29 @@ impl DefaultPhysicalPlanner {
&& session_state.config().repartition_joins()
&& !prefer_hash_join
{
// Use SortMergeJoin if hash join is not preferred
let join_on_len = join_on.len();
// Derive sort options from the left input's existing ordering
// rather than hardcoding SortOptions::default()
let sort_options: Vec<SortOptions> = join_on
.iter()
.map(|(left_col, _)| {
physical_left
.output_ordering()
.and_then(|ordering| {
ordering
.iter()
.find(|sort_expr| sort_expr.expr.eq(left_col))
.map(|sort_expr| sort_expr.options)
})
.unwrap_or_default()
})
.collect();
Arc::new(SortMergeJoinExec::try_new(
physical_left,
physical_right,
join_on,
join_filter,
*join_type,
vec![SortOptions::default(); join_on_len],
sort_options,
*null_equality,
)?)
} else if session_state.config().target_partitions() > 1
Expand Down
Loading