Skip to content

Commit b8c0f98

Browse files
committed
text: add sorting
Signed-off-by: Nick Van Wiggeren <[email protected]>
1 parent a7358ad commit b8c0f98

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

go/cmd/vtctldclient/command/vreplication/vdiff/vdiff.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ HasMismatch: {{.HasMismatch}}
439439
StartedAt: {{.StartedAt}}
440440
{{if (eq .State "started")}}Progress: {{printf "%.2f" .Progress.Percentage}}%{{if .Progress.ETA}}, ETA: {{.Progress.ETA}}{{end}}{{end}}
441441
{{if .CompletedAt}}CompletedAt: {{.CompletedAt}}{{end}}
442-
{{range $table := .TableSummaryMap}}
442+
{{range $table := .SortedTableSummaries}}
443443
Table {{$table.TableName}}:
444444
State: {{$table.State}}
445445
ProcessedRows: {{$table.RowsCompared}}

go/vt/vtctl/workflow/vdiff.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,22 @@ type Summary struct {
6969
Progress *vdiff.ProgressReport `json:"Progress,omitempty"`
7070
}
7171

72+
// SortedTableSummaries returns the table summaries sorted alphabetically by table name.
73+
// This is used by text templates to display tables in a consistent order.
74+
func (s *Summary) SortedTableSummaries() []TableSummary {
75+
names := make([]string, 0, len(s.TableSummaryMap))
76+
for name := range s.TableSummaryMap {
77+
names = append(names, name)
78+
}
79+
sort.Strings(names)
80+
81+
result := make([]TableSummary, 0, len(names))
82+
for _, name := range names {
83+
result = append(result, s.TableSummaryMap[name])
84+
}
85+
return result
86+
}
87+
7288
// BuildSummary generates a summary from a vdiff show response.
7389
func BuildSummary(keyspace, workflow, uuid string, resp *vtctldatapb.VDiffShowResponse, verbose bool) (*Summary, error) {
7490
summary := &Summary{

0 commit comments

Comments
 (0)