Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*: replace compareDatum by compare #30060

Merged
merged 3 commits into from
Nov 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions executor/replace.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ import (
"github.com/pingcap/errors"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/meta/autoid"
"github.com/pingcap/tidb/parser/charset"
"github.com/pingcap/tidb/parser/mysql"
"github.com/pingcap/tidb/sessionctx/stmtctx"
"github.com/pingcap/tidb/tablecodec"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/chunk"
"github.com/pingcap/tidb/util/collate"
"github.com/pingcap/tidb/util/logutil"
"github.com/pingcap/tidb/util/memory"
"go.uber.org/zap"
Expand Down Expand Up @@ -99,11 +99,7 @@ func (e *ReplaceExec) EqualDatumsAsBinary(sc *stmtctx.StatementContext, a []type
return false, nil
}
for i, ai := range a {
collation := ai.Collation()
// We should use binary collation to compare datum, otherwise the result will be incorrect
ai.SetCollation(charset.CollationBin)
v, err := ai.CompareDatum(sc, &b[i])
ai.SetCollation(collation)
v, err := ai.Compare(sc, &b[i], collate.GetBinaryCollator())
if err != nil {
return false, errors.Trace(err)
}
Expand Down
3 changes: 2 additions & 1 deletion expression/builtin_compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/types/json"
"github.com/pingcap/tidb/util/chunk"
"github.com/pingcap/tidb/util/collate"
"github.com/pingcap/tipb/go-tipb"
)

Expand Down Expand Up @@ -1378,7 +1379,7 @@ func RefineComparedConstant(ctx sessionctx.Context, targetFieldType types.FieldT
}
return con, false
}
c, err := intDatum.CompareDatum(sc, &con.Value)
c, err := intDatum.Compare(sc, &con.Value, collate.GetBinaryCollator())
if err != nil {
return con, false
}
Expand Down
3 changes: 2 additions & 1 deletion expression/builtin_other_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/pingcap/tidb/sessionctx/stmtctx"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/chunk"
"github.com/pingcap/tidb/util/collate"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -198,7 +199,7 @@ func TestValues(t *testing.T) {
ret, err = evalBuiltinFunc(sig, chunk.Row{})
require.NoError(t, err)

cmp, err := ret.CompareDatum(nil, &currInsertValues[1])
cmp, err := ret.Compare(nil, &currInsertValues[1], collate.GetBinaryCollator())
require.NoError(t, err)
require.Equal(t, 0, cmp)
}
Expand Down
3 changes: 2 additions & 1 deletion expression/distsql_builtin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/pingcap/tidb/types/json"
"github.com/pingcap/tidb/util/chunk"
"github.com/pingcap/tidb/util/codec"
"github.com/pingcap/tidb/util/collate"
"github.com/pingcap/tipb/go-tipb"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -787,7 +788,7 @@ func TestEval(t *testing.T) {
result, err := expr.Eval(row)
require.NoError(t, err)
require.Equal(t, tt.result.Kind(), result.Kind())
cmp, err := result.CompareDatum(sc, &tt.result)
cmp, err := result.Compare(sc, &tt.result, collate.GetCollator(fieldTps[0].Collate))
require.NoError(t, err)
require.Equal(t, 0, cmp)
}
Expand Down
5 changes: 3 additions & 2 deletions store/mockstore/unistore/cophandler/cop_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"github.com/pingcap/tidb/tablecodec"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/codec"
"github.com/pingcap/tidb/util/collate"
"github.com/pingcap/tidb/util/rowcodec"
"github.com/pingcap/tipb/go-tipb"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -339,10 +340,10 @@ func TestPointGet(t *testing.T) {

// verify the returned rows value as input
expectedRow := data.rows[handle]
eq, err := returnedRow[0].CompareDatum(nil, &expectedRow[0])
eq, err := returnedRow[0].Compare(nil, &expectedRow[0], collate.GetBinaryCollator())
require.NoError(t, err)
require.Equal(t, 0, eq)
eq, err = returnedRow[1].CompareDatum(nil, &expectedRow[1])
eq, err = returnedRow[1].Compare(nil, &expectedRow[1], collate.GetBinaryCollator())
require.NoError(t, err)
require.Equal(t, 0, eq)
}
Expand Down
5 changes: 3 additions & 2 deletions table/column_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/pingcap/tidb/sessionctx/stmtctx"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/types/json"
"github.com/pingcap/tidb/util/collate"
"github.com/pingcap/tidb/util/mock"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -126,7 +127,7 @@ func TestHandleBadNull(t *testing.T) {
d := types.Datum{}
err := col.HandleBadNull(&d, sc)
require.NoError(t, err)
cmp, err := d.CompareDatum(sc, &types.Datum{})
cmp, err := d.Compare(sc, &types.Datum{}, collate.GetBinaryCollator())
require.NoError(t, err)
require.Equal(t, 0, cmp)

Expand Down Expand Up @@ -255,7 +256,7 @@ func TestGetZeroValue(t *testing.T) {
colInfo := &model.ColumnInfo{FieldType: *tt.ft}
zv := GetZeroValue(colInfo)
require.Equal(t, tt.value.Kind(), zv.Kind())
cmp, err := zv.CompareDatum(sc, &tt.value)
cmp, err := zv.Compare(sc, &tt.value, collate.GetCollator(tt.ft.Collate))
require.NoError(t, err)
require.Equal(t, 0, cmp)
})
Expand Down
5 changes: 3 additions & 2 deletions util/codec/codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/types/json"
"github.com/pingcap/tidb/util/chunk"
"github.com/pingcap/tidb/util/collate"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -987,7 +988,7 @@ func TestDecodeOneToChunk(t *testing.T) {
require.True(t, expect.IsNull())
} else {
if got.Kind() != types.KindMysqlDecimal {
cmp, err := got.CompareDatum(sc, &expect)
cmp, err := got.Compare(sc, &expect, collate.GetCollator(tp.Collate))
require.NoError(t, err)
require.Equalf(t, 0, cmp, "expect: %v, got %v", expect, got)
} else {
Expand Down Expand Up @@ -1110,7 +1111,7 @@ func TestDecodeRange(t *testing.T) {
datums1, _, err := DecodeRange(rowData, len(datums), nil, nil)
require.NoError(t, err)
for i, datum := range datums1 {
cmp, err := datum.CompareDatum(nil, &datums[i])
cmp, err := datum.Compare(nil, &datums[i], collate.GetBinaryCollator())
require.NoError(t, err)
require.Equal(t, 0, cmp)
}
Expand Down
3 changes: 2 additions & 1 deletion util/profile/flamegraph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"testing"

"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/collate"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -91,7 +92,7 @@ func TestProfileToDatum(t *testing.T) {
comment = fmt.Sprintf("row %2d, actual (%s), expected (%s)", i, rowStr, expectStr)
equal := true
for j, r := range row {
v, err := r.CompareDatum(nil, &datums[i][j])
v, err := r.Compare(nil, &datums[i][j], collate.GetBinaryCollator())
if v != 0 || err != nil {
equal = false
break
Expand Down