Skip to content

Commit

Permalink
sorting for deterministic
Browse files Browse the repository at this point in the history
Signed-off-by: Andres Taylor <andres@planetscale.com>
  • Loading branch information
systay committed Jan 10, 2025
1 parent 733fc1c commit 66ba4bc
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions go/test/vschemawrapper/vschema_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"errors"
"fmt"
"sort"
"strings"

"vitess.io/vitess/go/mysql/collations"
Expand Down Expand Up @@ -300,11 +301,19 @@ func (vw *VSchemaWrapper) AnyKeyspace() (*vindexes.Keyspace, error) {
return ks.Keyspace, nil
}

for _, ks := range vw.V.Keyspaces {
return ks.Keyspace, nil
size := len(vw.V.Keyspaces)
if size == 0 {
return nil, errors.New("no keyspace found in vschema")
}

// Find the first keyspace in the map alphabetically to get deterministic results
keys := make([]string, size)
for key := range vw.V.Keyspaces {
keys = append(keys, key)
}
sort.Strings(keys)

return nil, errors.New("no keyspace found in vschema")
return vw.V.Keyspaces[keys[0]].Keyspace, nil
}

func (vw *VSchemaWrapper) FirstSortedKeyspace() (*vindexes.Keyspace, error) {
Expand Down

0 comments on commit 66ba4bc

Please sign in to comment.