From f95d3c1651a55c52e61e8fe42060356c3954556f Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Thu, 10 Aug 2023 22:27:30 +0800 Subject: [PATCH] *: replace exp/slices with std Signed-off-by: Weizhen Wang --- ddl/ddl_api.go | 2 +- executor/BUILD.bazel | 1 - executor/builder.go | 27 ++++++++++++++------------- executor/cte_test.go | 2 +- executor/metrics_reader.go | 2 +- executor/show.go | 2 +- executor/slow_query.go | 6 +++--- executor/table_reader.go | 9 +++++---- executor/trace.go | 6 +++--- planner/core/util.go | 2 +- sessionctx/variable/BUILD.bazel | 1 - sessionctx/variable/session.go | 2 +- sessionctx/variable/varsutil.go | 2 +- statistics/table.go | 7 ++++--- telemetry/BUILD.bazel | 1 - telemetry/data_cluster_hardware.go | 2 +- 16 files changed, 37 insertions(+), 37 deletions(-) diff --git a/ddl/ddl_api.go b/ddl/ddl_api.go index fc0e16f91bcaa..0f68364ef3ed0 100644 --- a/ddl/ddl_api.go +++ b/ddl/ddl_api.go @@ -23,6 +23,7 @@ import ( "context" "fmt" "math" + "slices" "strconv" "strings" "sync/atomic" @@ -73,7 +74,6 @@ import ( "github.com/tikv/client-go/v2/oracle" kvutil "github.com/tikv/client-go/v2/util" "go.uber.org/zap" - "golang.org/x/exp/slices" ) const ( diff --git a/executor/BUILD.bazel b/executor/BUILD.bazel index 83f6a577bed49..855d4a05f949c 100644 --- a/executor/BUILD.bazel +++ b/executor/BUILD.bazel @@ -469,7 +469,6 @@ go_test( "@com_github_tikv_client_go_v2//tikvrpc", "@com_github_tikv_client_go_v2//util", "@org_golang_google_grpc//:grpc", - "@org_golang_x_exp//slices", "@org_uber_go_atomic//:atomic", "@org_uber_go_goleak//:goleak", "@org_uber_go_zap//zapcore", diff --git a/executor/builder.go b/executor/builder.go index a394d95a23f57..4684cc649cc1a 100644 --- a/executor/builder.go +++ b/executor/builder.go @@ -16,9 +16,11 @@ package executor import ( "bytes" + "cmp" "context" "fmt" "math" + "slices" "strconv" "strings" "sync" @@ -80,7 +82,6 @@ import ( "github.com/tikv/client-go/v2/txnkv" "github.com/tikv/client-go/v2/txnkv/txnsnapshot" clientutil "github.com/tikv/client-go/v2/util" - "golang.org/x/exp/slices" ) // executorBuilder builds an Executor from a Plan. @@ -3671,8 +3672,8 @@ func (b *executorBuilder) buildTableReader(v *plannercore.PhysicalTableReader) e } // Sort the partition is necessary to make the final multiple partition key ranges ordered. - slices.SortFunc(partitions, func(i, j table.PhysicalTable) bool { - return i.GetPhysicalID() < j.GetPhysicalID() + slices.SortFunc(partitions, func(i, j table.PhysicalTable) int { + return cmp.Compare(i.GetPhysicalID(), j.GetPhysicalID()) }) ret.kvRangeBuilder = kvRangeBuilderFromRangeAndPartition{ sctx: b.ctx, @@ -3795,8 +3796,8 @@ func (builder *dataReaderBuilder) prunePartitionForInnerExecutor(tbl table.Table } // To make the final key ranges involving multiple partitions ordered. - slices.SortFunc(usedPartition, func(i, j table.PhysicalTable) bool { - return i.GetPhysicalID() < j.GetPhysicalID() + slices.SortFunc(usedPartition, func(i, j table.PhysicalTable) int { + return cmp.Compare(i.GetPhysicalID(), j.GetPhysicalID()) }) return usedPartition, true, contentPos, nil } @@ -4464,8 +4465,8 @@ func (builder *dataReaderBuilder) buildTableReaderForIndexJoin(ctx context.Conte } } // The key ranges should be ordered. - slices.SortFunc(kvRanges, func(i, j kv.KeyRange) bool { - return bytes.Compare(i.StartKey, j.StartKey) < 0 + slices.SortFunc(kvRanges, func(i, j kv.KeyRange) int { + return bytes.Compare(i.StartKey, j.StartKey) }) return builder.buildTableReaderFromKvRanges(ctx, e, kvRanges) } @@ -4502,8 +4503,8 @@ func (builder *dataReaderBuilder) buildTableReaderForIndexJoin(ctx context.Conte } // The key ranges should be ordered. - slices.SortFunc(kvRanges, func(i, j kv.KeyRange) bool { - return bytes.Compare(i.StartKey, j.StartKey) < 0 + slices.SortFunc(kvRanges, func(i, j kv.KeyRange) int { + return bytes.Compare(i.StartKey, j.StartKey) }) return builder.buildTableReaderFromKvRanges(ctx, e, kvRanges) } @@ -4624,8 +4625,8 @@ func (builder *dataReaderBuilder) buildTableReaderBase(ctx context.Context, e *T func (builder *dataReaderBuilder) buildTableReaderFromHandles(ctx context.Context, e *TableReaderExecutor, handles []kv.Handle, canReorderHandles bool) (*TableReaderExecutor, error) { if canReorderHandles { - slices.SortFunc(handles, func(i, j kv.Handle) bool { - return i.Compare(j) < 0 + slices.SortFunc(handles, func(i, j kv.Handle) int { + return i.Compare(j) }) } var b distsql.RequestBuilder @@ -4928,8 +4929,8 @@ func buildKvRangesForIndexJoin(ctx sessionctx.Context, tableID, indexID int64, l memTracker.Consume(2 * int64(len(tmpDatumRanges)) * types.EstimatedMemUsage(tmpDatumRanges[0].LowVal, len(tmpDatumRanges))) } if cwc == nil { - slices.SortFunc(kvRanges, func(i, j kv.KeyRange) bool { - return bytes.Compare(i.StartKey, j.StartKey) < 0 + slices.SortFunc(kvRanges, func(i, j kv.KeyRange) int { + return bytes.Compare(i.StartKey, j.StartKey) }) return kvRanges, nil } diff --git a/executor/cte_test.go b/executor/cte_test.go index fd556e133b517..fc8805d07b7dc 100644 --- a/executor/cte_test.go +++ b/executor/cte_test.go @@ -17,6 +17,7 @@ package executor_test import ( "fmt" "math/rand" + "slices" "testing" "github.com/pingcap/failpoint" @@ -24,7 +25,6 @@ import ( "github.com/pingcap/tidb/testkit" "github.com/pingcap/tidb/types" "github.com/stretchr/testify/require" - "golang.org/x/exp/slices" ) func TestBasicCTE(t *testing.T) { diff --git a/executor/metrics_reader.go b/executor/metrics_reader.go index 454e46989592e..1d1d6f4a2931d 100644 --- a/executor/metrics_reader.go +++ b/executor/metrics_reader.go @@ -18,6 +18,7 @@ import ( "context" "fmt" "math" + "slices" "strings" "time" @@ -36,7 +37,6 @@ import ( "github.com/prometheus/client_golang/api" promv1 "github.com/prometheus/client_golang/api/prometheus/v1" pmodel "github.com/prometheus/common/model" - "golang.org/x/exp/slices" ) const promReadTimeout = time.Second * 10 diff --git a/executor/show.go b/executor/show.go index 2c5cb941cd42b..53bd8cddccbbe 100644 --- a/executor/show.go +++ b/executor/show.go @@ -20,6 +20,7 @@ import ( gjson "encoding/json" "fmt" "math" + "slices" "sort" "strconv" "strings" @@ -81,7 +82,6 @@ import ( "github.com/pingcap/tidb/util/sqlexec" "github.com/pingcap/tidb/util/stringutil" "github.com/tikv/client-go/v2/oracle" - "golang.org/x/exp/slices" ) var etcdDialTimeout = 5 * time.Second diff --git a/executor/slow_query.go b/executor/slow_query.go index 1e70bee8fd3db..695d9dad52147 100644 --- a/executor/slow_query.go +++ b/executor/slow_query.go @@ -23,6 +23,7 @@ import ( "path/filepath" "regexp" "runtime" + "slices" "strconv" "strings" "sync" @@ -49,7 +50,6 @@ import ( "github.com/pingcap/tidb/util/memory" "github.com/pingcap/tidb/util/plancodec" "go.uber.org/zap" - "golang.org/x/exp/slices" ) type signalsKey struct{} @@ -941,8 +941,8 @@ func (e *slowQueryRetriever) getAllFiles(ctx context.Context, sctx sessionctx.Co } } // Sort by start time - slices.SortFunc(logFiles, func(i, j logFile) bool { - return i.start.Before(j.start) + slices.SortFunc(logFiles, func(i, j logFile) int { + return i.start.Compare(j.start) }) return logFiles, err } diff --git a/executor/table_reader.go b/executor/table_reader.go index 63f2d274348a4..bb5cb867a19f3 100644 --- a/executor/table_reader.go +++ b/executor/table_reader.go @@ -16,7 +16,9 @@ package executor import ( "bytes" + "cmp" "context" + "slices" "time" "github.com/pingcap/failpoint" @@ -44,7 +46,6 @@ import ( "github.com/pingcap/tidb/util/stringutil" "github.com/pingcap/tidb/util/tracing" "github.com/pingcap/tipb/go-tipb" - "golang.org/x/exp/slices" ) // make sure `TableReaderExecutor` implements `Executor`. @@ -484,9 +485,9 @@ func buildVirtualColumnIndex(schema *expression.Schema, columns []*model.ColumnI virtualColumnIndex = append(virtualColumnIndex, i) } } - slices.SortFunc(virtualColumnIndex, func(i, j int) bool { - return plannercore.FindColumnInfoByID(columns, schema.Columns[i].ID).Offset < - plannercore.FindColumnInfoByID(columns, schema.Columns[j].ID).Offset + slices.SortFunc(virtualColumnIndex, func(i, j int) int { + return cmp.Compare(plannercore.FindColumnInfoByID(columns, schema.Columns[i].ID).Offset, + plannercore.FindColumnInfoByID(columns, schema.Columns[j].ID).Offset) }) return virtualColumnIndex } diff --git a/executor/trace.go b/executor/trace.go index 9006717c802ca..3798559d4a356 100644 --- a/executor/trace.go +++ b/executor/trace.go @@ -23,6 +23,7 @@ import ( "fmt" "os" "path/filepath" + "slices" "strings" "time" @@ -44,7 +45,6 @@ import ( "github.com/pingcap/tidb/util/sqlexec" "github.com/tikv/client-go/v2/util" "go.uber.org/zap" - "golang.org/x/exp/slices" "sourcegraph.com/sourcegraph/appdash" traceImpl "sourcegraph.com/sourcegraph/appdash/opentracing" ) @@ -345,7 +345,7 @@ func dfsTree(t *appdash.Trace, prefix string, isLast bool, chk *chunk.Chunk) { chk.AppendString(2, duration.String()) // Sort events by their start time - slices.SortFunc(t.Sub, func(i, j *appdash.Trace) bool { + slices.SortFunc(t.Sub, func(i, j *appdash.Trace) int { var istart, jstart time.Time if ievent, err := i.TimespanEvent(); err == nil { istart = ievent.Start() @@ -353,7 +353,7 @@ func dfsTree(t *appdash.Trace, prefix string, isLast bool, chk *chunk.Chunk) { if jevent, err := j.TimespanEvent(); err == nil { jstart = jevent.Start() } - return istart.Before(jstart) + return istart.Compare(jstart) }) for i, sp := range t.Sub { diff --git a/planner/core/util.go b/planner/core/util.go index ad93a0fda6fa5..48a12f7cdc04c 100644 --- a/planner/core/util.go +++ b/planner/core/util.go @@ -16,6 +16,7 @@ package core import ( "fmt" + "slices" "sort" "strings" @@ -31,7 +32,6 @@ import ( "github.com/pingcap/tidb/util/mathutil" "github.com/pingcap/tidb/util/set" "github.com/pingcap/tidb/util/size" - "golang.org/x/exp/slices" ) // AggregateFuncExtractor visits Expr tree. diff --git a/sessionctx/variable/BUILD.bazel b/sessionctx/variable/BUILD.bazel index 41bebd18e955a..a8256c4263e5b 100644 --- a/sessionctx/variable/BUILD.bazel +++ b/sessionctx/variable/BUILD.bazel @@ -73,7 +73,6 @@ go_library( "@com_github_tikv_client_go_v2//util", "@com_github_twmb_murmur3//:murmur3", "@org_golang_x_exp//maps", - "@org_golang_x_exp//slices", "@org_uber_go_atomic//:atomic", "@org_uber_go_zap//:zap", ], diff --git a/sessionctx/variable/session.go b/sessionctx/variable/session.go index 88fdeaba32040..c7bc968812478 100644 --- a/sessionctx/variable/session.go +++ b/sessionctx/variable/session.go @@ -24,6 +24,7 @@ import ( "math" "math/rand" "net" + "slices" "strconv" "strings" "sync" @@ -65,7 +66,6 @@ import ( "github.com/twmb/murmur3" atomic2 "go.uber.org/atomic" "golang.org/x/exp/maps" - "golang.org/x/exp/slices" ) var ( diff --git a/sessionctx/variable/varsutil.go b/sessionctx/variable/varsutil.go index 5f8710b7680da..a48763ec0f36a 100644 --- a/sessionctx/variable/varsutil.go +++ b/sessionctx/variable/varsutil.go @@ -18,6 +18,7 @@ import ( "context" "fmt" "io" + "slices" "strconv" "strings" "sync/atomic" @@ -32,7 +33,6 @@ import ( "github.com/pingcap/tidb/util/memory" "github.com/pingcap/tidb/util/timeutil" "github.com/tikv/client-go/v2/oracle" - "golang.org/x/exp/slices" ) // secondsPerYear represents seconds in a normal year. Leap year is not considered here. diff --git a/statistics/table.go b/statistics/table.go index 8f5b7f08b0c3d..d9c7579721a51 100644 --- a/statistics/table.go +++ b/statistics/table.go @@ -15,8 +15,10 @@ package statistics import ( + "cmp" "fmt" "math" + "slices" "strings" "sync" @@ -39,7 +41,6 @@ import ( "github.com/pingcap/tidb/util/tracing" "go.uber.org/atomic" "go.uber.org/zap" - "golang.org/x/exp/slices" ) const ( @@ -323,7 +324,7 @@ func (t *Table) String() string { for _, col := range t.Columns { cols = append(cols, col) } - slices.SortFunc(cols, func(i, j *Column) bool { return i.ID < j.ID }) + slices.SortFunc(cols, func(i, j *Column) int { return cmp.Compare(i.ID, j.ID) }) for _, col := range cols { strs = append(strs, col.String()) } @@ -331,7 +332,7 @@ func (t *Table) String() string { for _, idx := range t.Indices { idxs = append(idxs, idx) } - slices.SortFunc(idxs, func(i, j *Index) bool { return i.ID < j.ID }) + slices.SortFunc(idxs, func(i, j *Index) int { return cmp.Compare(i.ID, j.ID) }) for _, idx := range idxs { strs = append(strs, idx.String()) } diff --git a/telemetry/BUILD.bazel b/telemetry/BUILD.bazel index 81da8e6700adb..dacd85c8b394c 100644 --- a/telemetry/BUILD.bazel +++ b/telemetry/BUILD.bazel @@ -43,7 +43,6 @@ go_library( "@com_github_shirou_gopsutil_v3//host", "@com_github_tikv_client_go_v2//metrics", "@io_etcd_go_etcd_client_v3//:client", - "@org_golang_x_exp//slices", "@org_uber_go_atomic//:atomic", "@org_uber_go_zap//:zap", ], diff --git a/telemetry/data_cluster_hardware.go b/telemetry/data_cluster_hardware.go index 659fceb00eac3..664fb4153c15a 100644 --- a/telemetry/data_cluster_hardware.go +++ b/telemetry/data_cluster_hardware.go @@ -17,13 +17,13 @@ package telemetry import ( "context" "regexp" + "slices" "strings" "github.com/iancoleman/strcase" "github.com/pingcap/errors" "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/util/sqlexec" - "golang.org/x/exp/slices" ) var (