Skip to content

Commit

Permalink
sink(ticdc): fix incorrect default field (#12038) (#12050)
Browse files Browse the repository at this point in the history
close #12037
  • Loading branch information
ti-chi-bot authored Feb 12, 2025
1 parent f044636 commit 8727f05
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 17 deletions.
13 changes: 1 addition & 12 deletions cdc/entry/mounter.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,6 @@ func datum2Column(
zap.String("column", colInfo.Name.String()))
}

defaultValue := GetDDLDefaultDefinition(colInfo)
offset := tableInfo.RowColumnsOffset[colID]
rawCols[offset] = colDatums
cols[offset] = &model.Column{
Expand All @@ -393,7 +392,7 @@ func datum2Column(
Charset: colInfo.GetCharset(),
Collation: colInfo.GetCollate(),
Value: colValue,
Default: defaultValue,
Default: colInfo.GetDefaultValue(),
Flag: tableInfo.ColumnsFlag[colID],
// ApproximateBytes = column data size + column struct size
ApproximateBytes: size + sizeOfEmptyColumn,
Expand Down Expand Up @@ -775,16 +774,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 @@ -1384,13 +1384,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 8727f05

Please sign in to comment.