@@ -24,7 +24,6 @@ import (
24
24
"slices"
25
25
"sort"
26
26
"strconv"
27
- "strings"
28
27
"time"
29
28
30
29
"vitess.io/vitess/go/slice"
@@ -238,53 +237,50 @@ func renderTablesJoined(md *markdown.MarkDown, summary *keys.Output) {
238
237
g .AddJoinPredicate (key , pred )
239
238
}
240
239
}
241
- ks := slices .Collect (maps .Keys (g ))
242
- slices .SortFunc (ks , func (a , b graphKey ) int {
243
- if a .Tbl1 == b .Tbl1 {
244
- return strings .Compare (a .Tbl2 , b .Tbl2 )
245
- }
246
- return strings .Compare (a .Tbl1 , b .Tbl1 )
247
- })
248
240
249
241
if len (g ) > 0 {
250
242
md .PrintHeader ("Tables Joined" , 2 )
251
243
}
252
244
253
- // we really want the output to be deterministic
254
- tables := slices .Collect (maps .Keys (g ))
255
- sort .Slice (tables , func (i , j int ) bool {
256
- if tables [i ].Tbl1 == tables [j ].Tbl1 {
257
- return tables [i ].Tbl2 < tables [j ].Tbl2
258
- }
259
- return tables [i ].Tbl1 < tables [j ].Tbl1
260
- })
245
+ type foo struct {
246
+ Tbl1 , Tbl2 string
247
+ Occurrences int
248
+ predicates []operators.JoinPredicate
249
+ }
261
250
262
- md .Println ("```" )
263
- for _ , table := range tables {
264
- predicates := g [table ]
265
- numberOfPreds := len (predicates )
266
- totalt := 0
251
+ var joins []foo
252
+ for tables , predicates := range g {
253
+ occurrences := 0
267
254
for _ , count := range predicates {
268
- totalt += count
255
+ occurrences += count
269
256
}
270
- md .Printf ("%s ↔ %s (Occurrences: %d)\n " , table .Tbl1 , table .Tbl2 , totalt )
271
-
272
- // we want the output to be deterministic
273
- preds := slices .Collect (maps .Keys (predicates ))
274
- sort .Slice (preds , func (i , j int ) bool {
275
- return preds [i ].String () < preds [j ].String ()
257
+ joinPredicates := slices .Collect (maps .Keys (predicates ))
258
+ sort .Slice (joinPredicates , func (i , j int ) bool {
259
+ return joinPredicates [i ].String () < joinPredicates [j ].String ()
260
+ })
261
+ joins = append (joins , foo {
262
+ Tbl1 : tables .Tbl1 ,
263
+ Tbl2 : tables .Tbl2 ,
264
+ Occurrences : occurrences ,
265
+ predicates : joinPredicates ,
276
266
})
267
+ }
277
268
278
- for _ , predicate := range preds {
279
- count := predicates [predicate ]
280
- numberOfPreds --
269
+ sort .Slice (joins , func (i , j int ) bool {
270
+ return joins [i ].Occurrences > joins [j ].Occurrences
271
+ })
272
+
273
+ md .Println ("```" )
274
+ for _ , join := range joins {
275
+ md .Printf ("%s ↔ %s (Occurrences: %d)\n " , join .Tbl1 , join .Tbl2 , join .Occurrences )
276
+ for i , pred := range join .predicates {
281
277
var s string
282
- if numberOfPreds == 0 {
278
+ if i == len ( join . predicates ) - 1 {
283
279
s = "└─"
284
280
} else {
285
281
s = "├─"
286
282
}
287
- md .Printf ("%s %s %d%% \n " , s , predicate .String (), ( count * 100 ) / totalt )
283
+ md .Printf ("%s %s\n " , s , pred .String ())
288
284
}
289
285
md .NewLine ()
290
286
}
0 commit comments