Skip to content

Commit

Permalink
sink(ticdc): fix incorrect default field (#12038) (#12049)
Browse files Browse the repository at this point in the history
close #12037
  • Loading branch information
ti-chi-bot authored Feb 8, 2025
1 parent bdaa449 commit 3a018e7
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 16 deletions.
12 changes: 1 addition & 11 deletions cdc/entry/mounter.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ func datum2Column(
if warn != "" {
log.Warn(warn, zap.String("table", tableInfo.TableName.String()), zap.String("column", colInfo.Name.String()))
}
defaultValue := GetDDLDefaultDefinition(colInfo)
defaultValue := colInfo.GetDefaultValue()
offset := tableInfo.RowColumnsOffset[colInfo.ID]
rawCols[offset] = colDatums
cols[offset] = &model.Column{
Expand Down Expand Up @@ -552,16 +552,6 @@ func getDefaultOrZeroValue(col *timodel.ColumnInfo, tz *time.Location) (types.Da
return d, v, size, warn, err
}

// GetDDLDefaultDefinition returns the default definition of a column.
func GetDDLDefaultDefinition(col *timodel.ColumnInfo) interface{} {
defaultValue := col.GetDefaultValue()
if defaultValue == nil {
defaultValue = col.GetOriginDefaultValue()
}
defaultDatum := types.NewDatum(defaultValue)
return defaultDatum.GetValue()
}

// DecodeTableID decodes the raw key to a table ID
func DecodeTableID(key []byte) (model.TableID, error) {
_, physicalTableID, err := decodeTableID(key)
Expand Down
6 changes: 3 additions & 3 deletions cdc/entry/mounter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1221,13 +1221,13 @@ func TestNewDMRowChange(t *testing.T) {
cdcTableInfo := model.WrapTableInfo(0, "test", 0, originTI)
cols := []*model.Column{
{
Name: "id", Type: 3, Charset: "binary", Flag: 65, Value: 1, Default: nil,
Name: "id", Type: 3, Charset: "binary", Flag: 65, Value: 1,
},
{
Name: "a1", Type: 3, Charset: "binary", Flag: 51, Value: 1, Default: nil,
Name: "a1", Type: 3, Charset: "binary", Flag: 51, Value: 1,
},
{
Name: "a3", Type: 3, Charset: "binary", Flag: 51, Value: 2, Default: nil,
Name: "a3", Type: 3, Charset: "binary", Flag: 51, Value: 2,
},
}
recoveredTI := model.BuildTiDBTableInfo(cols, cdcTableInfo.IndexColumnsOffset)
Expand Down
3 changes: 1 addition & 2 deletions pkg/sink/cloudstorage/table_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
timodel "github.com/pingcap/tidb/parser/model"
"github.com/pingcap/tidb/parser/mysql"
"github.com/pingcap/tidb/parser/types"
"github.com/pingcap/tiflow/cdc/entry"
"github.com/pingcap/tiflow/cdc/model"
"github.com/pingcap/tiflow/pkg/errors"
"github.com/pingcap/tiflow/pkg/hash"
Expand Down Expand Up @@ -73,7 +72,7 @@ func (t *TableCol) FromTiColumnInfo(col *timodel.ColumnInfo) {
if mysql.HasNotNullFlag(col.GetFlag()) {
t.Nullable = "false"
}
t.Default = entry.GetDDLDefaultDefinition(col)
t.Default = col.GetDefaultValue()

switch col.GetType() {
case mysql.TypeTimestamp, mysql.TypeDatetime, mysql.TypeDuration:
Expand Down

0 comments on commit 3a018e7

Please sign in to comment.