Skip to content

Commit

Permalink
fix tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
3AceShowHand committed Mar 19, 2024
1 parent 9bfbf57 commit 32a8192
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
17 changes: 10 additions & 7 deletions cdc/entry/mounter.go
Original file line number Diff line number Diff line change
Expand Up @@ -699,20 +699,23 @@ func formatColVal(datum types.Datum, col *timodel.ColumnInfo) (
// Supported type is: nil, basic type(Int, Int8,..., Float32, Float64, String), Slice(uint8), other types not support
// TODO: Check default expr support
func getDefaultOrZeroValue(col *timodel.ColumnInfo) (types.Datum, any, int, string, error) {
var d types.Datum
var (
d types.Datum
err error
)
// NOTICE: SHOULD use OriginDefaultValue here, more info pls ref to
// https://github.com/pingcap/tiflow/issues/4048
// FIXME: Too many corner cases may hit here, like type truncate, timezone
// (1) If this column is uk(no pk), will cause data inconsistency in Scenarios(2)
// (2) If not fix here, will cause data inconsistency in Scenarios(3) directly
// Ref: https://github.com/pingcap/tidb/blob/d2c352980a43bb593db81fd1db996f47af596d91/table/column.go#L489
if col.GetOriginDefaultValue() != nil {
d = types.NewDatum(col.GetOriginDefaultValue())
d, err := d.ConvertTo(types.DefaultStmtNoWarningContext, &col.FieldType)
return d, d.GetValue(), sizeOfDatum(d), "", errors.Trace(err)
}

if !mysql.HasNotNullFlag(col.GetFlag()) {
datum := types.NewDatum(col.GetOriginDefaultValue())
d, err = datum.ConvertTo(types.DefaultStmtNoWarningContext, &col.FieldType)
if err != nil {
return d, d.GetValue(), sizeOfDatum(d), "", errors.Trace(err)
}

Check warning on line 717 in cdc/entry/mounter.go

View check run for this annotation

Codecov / codecov/patch

cdc/entry/mounter.go#L716-L717

Added lines #L716 - L717 were not covered by tests
} else if !mysql.HasNotNullFlag(col.GetFlag()) {
// NOTICE: NotNullCheck need do after OriginDefaultValue check, as when TiDB meet "amend + add column default xxx",
// ref: https://github.com/pingcap/ticdc/issues/3929
// must use null if TiDB not write the column value when default value is null
Expand Down
12 changes: 6 additions & 6 deletions cdc/entry/mounter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ func TestGetDefaultZeroValue(t *testing.T) {
OriginDefaultValue: "e0",
FieldType: *ftTypeVarcharNotNull,
},
Res: "e0",
Res: []byte("e0"),
},
{
Name: "mysql.TypeTinyBlob",
Expand Down Expand Up @@ -886,7 +886,7 @@ func TestGetDefaultZeroValue(t *testing.T) {
decimal := new(types.MyDecimal)
err := decimal.FromString([]byte("-3.14"))
require.NoError(t, err)
require.Equal(t, decimal, val, "mysql.TypeNewDecimal + notnull + default")
require.Equal(t, decimal.String(), val, "mysql.TypeNewDecimal + notnull + default")

colInfo = timodel.ColumnInfo{
OriginDefaultValue: "2020-11-19 12:12:12",
Expand All @@ -897,7 +897,7 @@ func TestGetDefaultZeroValue(t *testing.T) {
types.DefaultStmtNoWarningContext,
"2020-11-19 12:12:12", colInfo.FieldType.GetType(), colInfo.FieldType.GetDecimal())
require.NoError(t, err)
require.Equal(t, expected, val, "mysql.TypeTimestamp + notnull + default")
require.Equal(t, expected.String(), val, "mysql.TypeTimestamp + notnull + default")

colInfo = timodel.ColumnInfo{
OriginDefaultValue: "2020-11-19 12:12:12",
Expand All @@ -908,7 +908,7 @@ func TestGetDefaultZeroValue(t *testing.T) {
types.DefaultStmtNoWarningContext,
"2020-11-19 12:12:12", colInfo.FieldType.GetType(), colInfo.FieldType.GetDecimal())
require.NoError(t, err)
require.Equal(t, expected, val, "mysql.TypeTimestamp + null + default")
require.Equal(t, expected.String(), val, "mysql.TypeTimestamp + null + default")

colInfo = timodel.ColumnInfo{
OriginDefaultValue: "e1",
Expand All @@ -917,7 +917,7 @@ func TestGetDefaultZeroValue(t *testing.T) {
_, val, _, _, _ = getDefaultOrZeroValue(&colInfo)
expectedEnum, err := types.ParseEnumName(colInfo.FieldType.GetElems(), "e1", colInfo.FieldType.GetCollate())
require.NoError(t, err)
require.Equal(t, expectedEnum, val, "mysql.TypeEnum + notnull + default")
require.Equal(t, expectedEnum.Value, val, "mysql.TypeEnum + notnull + default")

colInfo = timodel.ColumnInfo{
OriginDefaultValue: "1,e",
Expand All @@ -926,7 +926,7 @@ func TestGetDefaultZeroValue(t *testing.T) {
_, val, _, _, _ = getDefaultOrZeroValue(&colInfo)
expectedSet, err := types.ParseSetName(colInfo.FieldType.GetElems(), "1,e", colInfo.FieldType.GetCollate())
require.NoError(t, err)
require.Equal(t, expectedSet, val, "mysql.TypeSet + notnull + default")
require.Equal(t, expectedSet.Value, val, "mysql.TypeSet + notnull + default")
}

func TestE2ERowLevelChecksum(t *testing.T) {
Expand Down

0 comments on commit 32a8192

Please sign in to comment.