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