Skip to content

Commit b0ec2d6

Browse files
authored
Refactor tests for union sorting properties, add tests for unions and constants (#12702)
* Refactor tests for union sorting properties * update doc test * Undo import reordering * remove unecessary static lifetimes
1 parent a515dec commit b0ec2d6

File tree

2 files changed

+467
-366
lines changed

2 files changed

+467
-366
lines changed

datafusion/physical-expr/src/equivalence/ordering.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use std::fmt::Display;
1919
use std::hash::Hash;
2020
use std::sync::Arc;
21+
use std::vec::IntoIter;
2122

2223
use crate::equivalence::add_offset_to_expr;
2324
use crate::{LexOrdering, PhysicalExpr, PhysicalSortExpr};
@@ -36,15 +37,15 @@ use arrow_schema::SortOptions;
3637
///
3738
/// Here, both `vec![a ASC, b ASC]` and `vec![c DESC, d ASC]` describe the table
3839
/// ordering. In this case, we say that these orderings are equivalent.
39-
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
40+
#[derive(Debug, Clone, Eq, PartialEq, Hash, Default)]
4041
pub struct OrderingEquivalenceClass {
4142
pub orderings: Vec<LexOrdering>,
4243
}
4344

4445
impl OrderingEquivalenceClass {
4546
/// Creates new empty ordering equivalence class.
4647
pub fn empty() -> Self {
47-
Self { orderings: vec![] }
48+
Default::default()
4849
}
4950

5051
/// Clears (empties) this ordering equivalence class.
@@ -197,6 +198,15 @@ impl OrderingEquivalenceClass {
197198
}
198199
}
199200

201+
impl IntoIterator for OrderingEquivalenceClass {
202+
type Item = LexOrdering;
203+
type IntoIter = IntoIter<LexOrdering>;
204+
205+
fn into_iter(self) -> Self::IntoIter {
206+
self.orderings.into_iter()
207+
}
208+
}
209+
200210
/// This function constructs a duplicate-free `LexOrdering` by filtering out
201211
/// duplicate entries that have same physical expression inside. For example,
202212
/// `vec![a ASC, a DESC]` collapses to `vec![a ASC]`.
@@ -229,10 +239,10 @@ impl Display for OrderingEquivalenceClass {
229239
write!(f, "[")?;
230240
let mut iter = self.orderings.iter();
231241
if let Some(ordering) = iter.next() {
232-
write!(f, "{}", PhysicalSortExpr::format_list(ordering))?;
242+
write!(f, "[{}]", PhysicalSortExpr::format_list(ordering))?;
233243
}
234244
for ordering in iter {
235-
write!(f, "{}", PhysicalSortExpr::format_list(ordering))?;
245+
write!(f, ", [{}]", PhysicalSortExpr::format_list(ordering))?;
236246
}
237247
write!(f, "]")?;
238248
Ok(())

0 commit comments

Comments
 (0)