Skip to content

Commit

Permalink
Change remove from swap to shift in index map (apache#9049)
Browse files Browse the repository at this point in the history
* Change remove from swap to shift in index map

* Add new tests
  • Loading branch information
mustafasrepo authored Jan 29, 2024
1 parent 9bf0f68 commit 92104a5
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions datafusion/physical-expr/src/equivalence/properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ impl EquivalenceProperties {
for (PhysicalSortExpr { expr, .. }, idx) in &ordered_exprs {
eq_properties =
eq_properties.add_constants(std::iter::once(expr.clone()));
search_indices.swap_remove(idx);
search_indices.shift_remove(idx);
}
// Add new ordered section to the state.
result.extend(ordered_exprs);
Expand Down Expand Up @@ -1779,6 +1779,7 @@ mod tests {
let col_c = &col("c", &test_schema)?;
let col_d = &col("d", &test_schema)?;
let col_e = &col("e", &test_schema)?;
let col_f = &col("f", &test_schema)?;
let col_h = &col("h", &test_schema)?;
// a + d
let a_plus_d = Arc::new(BinaryExpr::new(
Expand All @@ -1795,7 +1796,7 @@ mod tests {
descending: true,
nulls_first: true,
};
// [d ASC, h ASC] also satisfies schema.
// [d ASC, h DESC] also satisfies schema.
eq_properties.add_new_orderings([vec![
PhysicalSortExpr {
expr: col_d.clone(),
Expand Down Expand Up @@ -1836,6 +1837,39 @@ mod tests {
vec![col_c, col_e],
vec![(col_c, option_asc), (col_e, option_desc)],
),
// TEST CASE 7
(
vec![col_d, col_h, col_e, col_f, col_b],
vec![
(col_d, option_asc),
(col_e, option_desc),
(col_h, option_desc),
(col_f, option_asc),
(col_b, option_asc),
],
),
// TEST CASE 8
(
vec![col_e, col_d, col_h, col_f, col_b],
vec![
(col_e, option_desc),
(col_d, option_asc),
(col_h, option_desc),
(col_f, option_asc),
(col_b, option_asc),
],
),
// TEST CASE 9
(
vec![col_e, col_d, col_b, col_h, col_f],
vec![
(col_e, option_desc),
(col_d, option_asc),
(col_b, option_asc),
(col_h, option_desc),
(col_f, option_asc),
],
),
];
for (exprs, expected) in test_cases {
let exprs = exprs.into_iter().cloned().collect::<Vec<_>>();
Expand Down

0 comments on commit 92104a5

Please sign in to comment.