1616//! equivalences classes, each a list of equivalent expressions.
1717
1818use std:: collections:: BTreeMap ;
19+ use std:: fmt:: Formatter ;
1920
2021use mz_expr:: { Id , MirRelationExpr , MirScalarExpr } ;
22+ use mz_ore:: str:: { bracketed, separated} ;
2123use mz_repr:: { ColumnType , Datum } ;
2224
2325use crate :: analysis:: { Analysis , Lattice } ;
@@ -318,7 +320,7 @@ pub struct EquivalenceClasses {
318320 /// The first element should be the "canonical" simplest element, that any other element
319321 /// can be replaced by.
320322 /// These classes are unified whenever possible, to minimize the number of classes.
321- /// They are only guaranteed to form an equivalence relation after a call to `minimimize `,
323+ /// They are only guaranteed to form an equivalence relation after a call to `minimize `,
322324 /// which refreshes both `self.classes` and `self.remap`.
323325 pub classes : Vec < Vec < MirScalarExpr > > ,
324326
@@ -334,6 +336,17 @@ pub struct EquivalenceClasses {
334336 remap : BTreeMap < MirScalarExpr , MirScalarExpr > ,
335337}
336338
339+ impl std:: fmt:: Display for EquivalenceClasses {
340+ fn fmt ( & self , f : & mut Formatter < ' _ > ) -> std:: fmt:: Result {
341+ // Only show `classes`.
342+ let classes = self
343+ . classes
344+ . iter ( )
345+ . map ( |class| format ! ( "{}" , bracketed( "[" , "]" , separated( ", " , class) ) ) ) ;
346+ write ! ( f, "{}" , bracketed( "[" , "]" , separated( ", " , classes) ) )
347+ }
348+ }
349+
337350impl EquivalenceClasses {
338351 /// Comparator function for the complexity of scalar expressions. Simpler expressions are
339352 /// smaller. Can be used when we need to decide which of several equivalent expressions to use.
0 commit comments