Skip to content

Commit

Permalink
Refactor tests for union sorting properties, add tests for unions and…
Browse files Browse the repository at this point in the history
… constants (#12702)

* Refactor tests for union sorting properties

* update doc test

* Undo import reordering

* remove unecessary static lifetimes
  • Loading branch information
alamb authored Oct 2, 2024
1 parent a515dec commit b0ec2d6
Show file tree
Hide file tree
Showing 2 changed files with 467 additions and 366 deletions.
18 changes: 14 additions & 4 deletions datafusion/physical-expr/src/equivalence/ordering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use std::fmt::Display;
use std::hash::Hash;
use std::sync::Arc;
use std::vec::IntoIter;

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

impl OrderingEquivalenceClass {
/// Creates new empty ordering equivalence class.
pub fn empty() -> Self {
Self { orderings: vec![] }
Default::default()
}

/// Clears (empties) this ordering equivalence class.
Expand Down Expand Up @@ -197,6 +198,15 @@ impl OrderingEquivalenceClass {
}
}

impl IntoIterator for OrderingEquivalenceClass {
type Item = LexOrdering;
type IntoIter = IntoIter<LexOrdering>;

fn into_iter(self) -> Self::IntoIter {
self.orderings.into_iter()
}
}

/// This function constructs a duplicate-free `LexOrdering` by filtering out
/// duplicate entries that have same physical expression inside. For example,
/// `vec![a ASC, a DESC]` collapses to `vec![a ASC]`.
Expand Down Expand Up @@ -229,10 +239,10 @@ impl Display for OrderingEquivalenceClass {
write!(f, "[")?;
let mut iter = self.orderings.iter();
if let Some(ordering) = iter.next() {
write!(f, "{}", PhysicalSortExpr::format_list(ordering))?;
write!(f, "[{}]", PhysicalSortExpr::format_list(ordering))?;
}
for ordering in iter {
write!(f, "{}", PhysicalSortExpr::format_list(ordering))?;
write!(f, ", [{}]", PhysicalSortExpr::format_list(ordering))?;
}
write!(f, "]")?;
Ok(())
Expand Down
Loading

0 comments on commit b0ec2d6

Please sign in to comment.