diff --git a/go/maps2/maps.go b/go/maps2/maps.go deleted file mode 100644 index 56191bea1a7..00000000000 --- a/go/maps2/maps.go +++ /dev/null @@ -1,37 +0,0 @@ -/* -Copyright 2023 The Vitess Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package maps2 - -// Keys returns the keys of the map m. -// The keys will be in an indeterminate order. -func Keys[M ~map[K]V, K comparable, V any](m M) []K { - r := make([]K, 0, len(m)) - for k := range m { - r = append(r, k) - } - return r -} - -// Values returns the values of the map m. -// The values will be in an indeterminate order. -func Values[M ~map[K]V, K comparable, V any](m M) []V { - r := make([]V, 0, len(m)) - for _, v := range m { - r = append(r, v) - } - return r -} diff --git a/go/maps2/maps_test.go b/go/maps2/maps_test.go deleted file mode 100644 index b12bcfbc3d1..00000000000 --- a/go/maps2/maps_test.go +++ /dev/null @@ -1,65 +0,0 @@ -/* -Copyright 2023 The Vitess Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package maps2 - -import ( - "reflect" - "sort" - "testing" -) - -func TestMaps(t *testing.T) { - tests := []struct { - name string - m map[int]string - keys []int - values []string - }{ - { - name: "EmptyMap", - m: map[int]string{}, - keys: []int{}, - values: []string{}, - }, - { - name: "NonEmptyMap", - m: map[int]string{1: "one", 2: "two", 3: "three"}, - keys: []int{1, 2, 3}, - values: []string{"one", "two", "three"}, - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - gotKeys := Keys(tt.m) - // Sort the keys so that we can compare them - sort.Ints(gotKeys) - sort.Ints(tt.keys) - if !reflect.DeepEqual(gotKeys, tt.keys) { - t.Errorf("Keys() = %v, want %v", gotKeys, tt.keys) - } - - gotValues := Values(tt.m) - // Sort the values so that we can compare them - sort.Strings(gotValues) - sort.Strings(tt.values) - if !reflect.DeepEqual(gotValues, tt.values) { - t.Errorf("Values() = %v, want %v", gotValues, tt.values) - } - }) - } -} diff --git a/go/vt/vtctl/workflow/switcher_dry_run.go b/go/vt/vtctl/workflow/switcher_dry_run.go index 1932e48fe20..cae26160ad6 100644 --- a/go/vt/vtctl/workflow/switcher_dry_run.go +++ b/go/vt/vtctl/workflow/switcher_dry_run.go @@ -24,7 +24,7 @@ import ( "strings" "time" - "vitess.io/vitess/go/maps2" + "golang.org/x/exp/maps" "vitess.io/vitess/go/mysql/replication" binlogdatapb "vitess.io/vitess/go/vt/proto/binlogdata" @@ -380,7 +380,7 @@ func (dr *switcherDryRun) resetSequences(ctx context.Context) error { } func (dr *switcherDryRun) initializeTargetSequences(ctx context.Context, sequencesByBackingTable map[string]*sequenceMetadata) error { - sortedBackingTableNames := maps2.Keys(sequencesByBackingTable) + sortedBackingTableNames := maps.Keys(sequencesByBackingTable) slices.Sort(sortedBackingTableNames) dr.drLog.Log(fmt.Sprintf("The following sequence backing tables used by tables being moved will be initialized: %s", strings.Join(sortedBackingTableNames, ","))) diff --git a/go/vt/vtctl/workflow/traffic_switcher.go b/go/vt/vtctl/workflow/traffic_switcher.go index 871b4b6c10a..47a29100cd5 100644 --- a/go/vt/vtctl/workflow/traffic_switcher.go +++ b/go/vt/vtctl/workflow/traffic_switcher.go @@ -25,10 +25,10 @@ import ( "sync" "time" + "golang.org/x/exp/maps" "golang.org/x/sync/errgroup" "vitess.io/vitess/go/json2" - "vitess.io/vitess/go/maps2" "vitess.io/vitess/go/sqlescape" "vitess.io/vitess/go/sqltypes" "vitess.io/vitess/go/vt/binlog/binlogplayer" @@ -1347,7 +1347,7 @@ func (ts *trafficSwitcher) getTargetSequenceMetadata(ctx context.Context) (map[s // error if any is seen. func (ts *trafficSwitcher) findSequenceUsageInKeyspace(vschema *vschemapb.Keyspace) (map[string]*sequenceMetadata, bool, error) { allFullyQualified := true - targets := maps2.Values(ts.Targets()) + targets := maps.Values(ts.Targets()) if len(targets) == 0 || targets[0].GetPrimary() == nil { // This should never happen return nil, false, vterrors.Errorf(vtrpcpb.Code_INTERNAL, "no primary tablet found for target keyspace %s", ts.targetKeyspace) } diff --git a/go/vt/vttablet/tabletserver/schema/db_test.go b/go/vt/vttablet/tabletserver/schema/db_test.go index 740ec847e71..5e1bc429136 100644 --- a/go/vt/vttablet/tabletserver/schema/db_test.go +++ b/go/vt/vttablet/tabletserver/schema/db_test.go @@ -23,9 +23,9 @@ import ( "testing" "github.com/stretchr/testify/require" + "golang.org/x/exp/maps" "vitess.io/vitess/go/constants/sidecar" - "vitess.io/vitess/go/maps2" "vitess.io/vitess/go/mysql/collations" "vitess.io/vitess/go/mysql/config" "vitess.io/vitess/go/mysql/fakesqldb" @@ -150,7 +150,7 @@ func TestGetChangedViewNames(t *testing.T) { got, err := getChangedViewNames(context.Background(), conn, true) require.NoError(t, err) require.Len(t, got, 3) - require.ElementsMatch(t, maps2.Keys(got), []string{"v1", "v2", "lead"}) + require.ElementsMatch(t, maps.Keys(got), []string{"v1", "v2", "lead"}) require.NoError(t, db.LastError()) // Not serving primary @@ -187,7 +187,7 @@ func TestGetViewDefinition(t *testing.T) { got, err := collectGetViewDefinitions(conn, bv) require.NoError(t, err) require.Len(t, got, 2) - require.ElementsMatch(t, maps2.Keys(got), []string{"v1", "lead"}) + require.ElementsMatch(t, maps.Keys(got), []string{"v1", "lead"}) require.Equal(t, "create_view_v1", got["v1"]) require.Equal(t, "create_view_lead", got["lead"]) require.NoError(t, db.LastError()) @@ -358,7 +358,7 @@ func TestGetMismatchedTableNames(t *testing.T) { if tc.expectedError != "" { require.ErrorContains(t, err, tc.expectedError) } else { - require.ElementsMatch(t, maps2.Keys(mismatchedTableNames), tc.expectedTableNames) + require.ElementsMatch(t, maps.Keys(mismatchedTableNames), tc.expectedTableNames) require.NoError(t, db.LastError()) } }) diff --git a/go/vt/vttablet/tabletserver/schema/engine.go b/go/vt/vttablet/tabletserver/schema/engine.go index 6117840a097..da93de324be 100644 --- a/go/vt/vttablet/tabletserver/schema/engine.go +++ b/go/vt/vttablet/tabletserver/schema/engine.go @@ -21,14 +21,12 @@ import ( "context" "encoding/json" "fmt" - "maps" "net/http" "strings" "sync" "time" "vitess.io/vitess/go/constants/sidecar" - "vitess.io/vitess/go/maps2" "vitess.io/vitess/go/mysql/collations" "vitess.io/vitess/go/mysql/config" "vitess.io/vitess/go/mysql/replication" @@ -52,6 +50,8 @@ import ( "vitess.io/vitess/go/vt/vttablet/tabletserver/connpool" "vitess.io/vitess/go/vt/vttablet/tabletserver/tabletenv" + "golang.org/x/exp/maps" + binlogdatapb "vitess.io/vitess/go/vt/proto/binlogdata" topodatapb "vitess.io/vitess/go/vt/proto/topodata" vtrpcpb "vitess.io/vitess/go/vt/proto/vtrpc" @@ -589,7 +589,7 @@ func (se *Engine) getDroppedTables(curTables map[string]bool, changedViews map[s } } - return maps2.Values(dropped) + return maps.Values(dropped) } func getTableData(ctx context.Context, conn *connpool.Conn, includeStats bool) (*sqltypes.Result, error) { diff --git a/go/vt/wrangler/switcher_dry_run.go b/go/vt/wrangler/switcher_dry_run.go index 0c1a1f1acbf..b4410add26f 100644 --- a/go/vt/wrangler/switcher_dry_run.go +++ b/go/vt/wrangler/switcher_dry_run.go @@ -24,7 +24,7 @@ import ( "strings" "time" - "vitess.io/vitess/go/maps2" + "golang.org/x/exp/maps" "vitess.io/vitess/go/mysql/replication" "vitess.io/vitess/go/vt/vtctl/workflow" @@ -399,7 +399,7 @@ func (dr *switcherDryRun) resetSequences(ctx context.Context) error { } func (dr *switcherDryRun) initializeTargetSequences(ctx context.Context, sequencesByBackingTable map[string]*sequenceMetadata) error { - sortedBackingTableNames := maps2.Keys(sequencesByBackingTable) + sortedBackingTableNames := maps.Keys(sequencesByBackingTable) slices.Sort(sortedBackingTableNames) dr.drLog.Log(fmt.Sprintf("The following sequence backing tables used by tables being moved will be initialized: %s", strings.Join(sortedBackingTableNames, ","))) diff --git a/go/vt/wrangler/traffic_switcher.go b/go/vt/wrangler/traffic_switcher.go index 2f75cadf06c..9cc0eea554c 100644 --- a/go/vt/wrangler/traffic_switcher.go +++ b/go/vt/wrangler/traffic_switcher.go @@ -26,12 +26,12 @@ import ( "sync" "time" + "golang.org/x/exp/maps" "golang.org/x/sync/errgroup" "vitess.io/vitess/go/mysql/collations" "vitess.io/vitess/go/json2" - "vitess.io/vitess/go/maps2" "vitess.io/vitess/go/sqlescape" "vitess.io/vitess/go/sqltypes" "vitess.io/vitess/go/vt/binlog/binlogplayer" @@ -2108,7 +2108,7 @@ func (ts *trafficSwitcher) getTargetSequenceMetadata(ctx context.Context) (map[s // error if any is seen. func (ts *trafficSwitcher) findSequenceUsageInKeyspace(vschema *vschemapb.Keyspace) (map[string]*sequenceMetadata, bool, error) { allFullyQualified := true - targets := maps2.Values(ts.Targets()) + targets := maps.Values(ts.Targets()) if len(targets) == 0 || targets[0].GetPrimary() == nil { // This should never happen return nil, false, vterrors.Errorf(vtrpcpb.Code_INTERNAL, "no primary tablet found for target keyspace %s", ts.targetKeyspace) }