18
18
use std:: fmt:: Display ;
19
19
use std:: hash:: Hash ;
20
20
use std:: sync:: Arc ;
21
+ use std:: vec:: IntoIter ;
21
22
22
23
use crate :: equivalence:: add_offset_to_expr;
23
24
use crate :: { LexOrdering , PhysicalExpr , PhysicalSortExpr } ;
@@ -36,15 +37,15 @@ use arrow_schema::SortOptions;
36
37
///
37
38
/// Here, both `vec![a ASC, b ASC]` and `vec![c DESC, d ASC]` describe the table
38
39
/// 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 ) ]
40
41
pub struct OrderingEquivalenceClass {
41
42
pub orderings : Vec < LexOrdering > ,
42
43
}
43
44
44
45
impl OrderingEquivalenceClass {
45
46
/// Creates new empty ordering equivalence class.
46
47
pub fn empty ( ) -> Self {
47
- Self { orderings : vec ! [ ] }
48
+ Default :: default ( )
48
49
}
49
50
50
51
/// Clears (empties) this ordering equivalence class.
@@ -197,6 +198,15 @@ impl OrderingEquivalenceClass {
197
198
}
198
199
}
199
200
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
+
200
210
/// This function constructs a duplicate-free `LexOrdering` by filtering out
201
211
/// duplicate entries that have same physical expression inside. For example,
202
212
/// `vec![a ASC, a DESC]` collapses to `vec![a ASC]`.
@@ -229,10 +239,10 @@ impl Display for OrderingEquivalenceClass {
229
239
write ! ( f, "[" ) ?;
230
240
let mut iter = self . orderings . iter ( ) ;
231
241
if let Some ( ordering) = iter. next ( ) {
232
- write ! ( f, "{} " , PhysicalSortExpr :: format_list( ordering) ) ?;
242
+ write ! ( f, "[{}] " , PhysicalSortExpr :: format_list( ordering) ) ?;
233
243
}
234
244
for ordering in iter {
235
- write ! ( f, "{} " , PhysicalSortExpr :: format_list( ordering) ) ?;
245
+ write ! ( f, ", [{}] " , PhysicalSortExpr :: format_list( ordering) ) ?;
236
246
}
237
247
write ! ( f, "]" ) ?;
238
248
Ok ( ( ) )
0 commit comments