Skip to content

Commit b72a1d1

Browse files
committed
Account for constant equivalence properties in union, tests
1 parent 8aac9b4 commit b72a1d1

File tree

4 files changed

+561
-364
lines changed

4 files changed

+561
-364
lines changed

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

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
use std::fmt::Display;
19-
use std::hash::Hash;
20-
use std::sync::Arc;
21-
2218
use crate::equivalence::add_offset_to_expr;
2319
use crate::{LexOrdering, PhysicalExpr, PhysicalSortExpr};
2420
use arrow_schema::SortOptions;
21+
use std::fmt::Display;
22+
use std::hash::Hash;
23+
use std::sync::Arc;
24+
use std::vec::IntoIter;
2525

2626
/// An `OrderingEquivalenceClass` object keeps track of different alternative
2727
/// orderings than can describe a schema. For example, consider the following table:
@@ -36,15 +36,15 @@ use arrow_schema::SortOptions;
3636
///
3737
/// Here, both `vec![a ASC, b ASC]` and `vec![c DESC, d ASC]` describe the table
3838
/// ordering. In this case, we say that these orderings are equivalent.
39-
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
39+
#[derive(Debug, Clone, Eq, PartialEq, Hash, Default)]
4040
pub struct OrderingEquivalenceClass {
4141
pub orderings: Vec<LexOrdering>,
4242
}
4343

4444
impl OrderingEquivalenceClass {
4545
/// Creates new empty ordering equivalence class.
4646
pub fn empty() -> Self {
47-
Self { orderings: vec![] }
47+
Default::default()
4848
}
4949

5050
/// Clears (empties) this ordering equivalence class.
@@ -197,6 +197,15 @@ impl OrderingEquivalenceClass {
197197
}
198198
}
199199

200+
impl IntoIterator for OrderingEquivalenceClass {
201+
type Item = LexOrdering;
202+
type IntoIter = IntoIter<LexOrdering>;
203+
204+
fn into_iter(self) -> Self::IntoIter {
205+
self.orderings.into_iter()
206+
}
207+
}
208+
200209
/// This function constructs a duplicate-free `LexOrdering` by filtering out
201210
/// duplicate entries that have same physical expression inside. For example,
202211
/// `vec![a ASC, a DESC]` collapses to `vec![a ASC]`.
@@ -229,10 +238,10 @@ impl Display for OrderingEquivalenceClass {
229238
write!(f, "[")?;
230239
let mut iter = self.orderings.iter();
231240
if let Some(ordering) = iter.next() {
232-
write!(f, "{}", PhysicalSortExpr::format_list(ordering))?;
241+
write!(f, "[{}]", PhysicalSortExpr::format_list(ordering))?;
233242
}
234243
for ordering in iter {
235-
write!(f, "{}", PhysicalSortExpr::format_list(ordering))?;
244+
write!(f, ", [{}]", PhysicalSortExpr::format_list(ordering))?;
236245
}
237246
write!(f, "]")?;
238247
Ok(())

0 commit comments

Comments
 (0)