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

sink(ticdc): fix incorrect default field (#12038) #12052

Open
wants to merge 3 commits into
base: release-8.1
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions cdc/entry/mounter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1679,13 +1679,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(cdcTableInfo.TableName.Table, cols, cdcTableInfo.IndexColumnsOffset)
Expand Down
11 changes: 0 additions & 11 deletions cdc/model/schema_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/pingcap/tidb/pkg/parser/mysql"
"github.com/pingcap/tidb/pkg/parser/types"
"github.com/pingcap/tidb/pkg/table/tables"
datumTypes "github.com/pingcap/tidb/pkg/types"
"github.com/pingcap/tidb/pkg/util/rowcodec"
"go.uber.org/zap"
)
Expand Down Expand Up @@ -501,13 +500,3 @@ func (ti *TableInfo) GetPrimaryKeyColumnNames() []string {
}
return result
}

// GetColumnDefaultValue returns the default definition of a column.
func GetColumnDefaultValue(col *model.ColumnInfo) interface{} {
defaultValue := col.GetDefaultValue()
if defaultValue == nil {
defaultValue = col.GetOriginDefaultValue()
}
defaultDatum := datumTypes.NewDatum(defaultValue)
return defaultDatum.GetValue()
}
2 changes: 1 addition & 1 deletion cdc/model/sink.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ func columnData2Column(col *ColumnData, tableInfo *TableInfo) *Column {
Collation: colInfo.GetCollate(),
Flag: tableInfo.ColumnsFlag[colID],
Value: col.Value,
Default: GetColumnDefaultValue(colInfo),
Default: colInfo.GetDefaultValue(),
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/sink/cloudstorage/table_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (t *TableCol) FromTiColumnInfo(col *timodel.ColumnInfo, outputColumnID bool
if mysql.HasNotNullFlag(col.GetFlag()) {
t.Nullable = "false"
}
t.Default = model.GetColumnDefaultValue(col)
t.Default = col.GetDefaultValue()

switch col.GetType() {
case mysql.TypeTimestamp, mysql.TypeDatetime, mysql.TypeDuration:
Expand Down
2 changes: 1 addition & 1 deletion pkg/sink/codec/simple/avro.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func newTableSchemaMap(tableInfo *model.TableInfo) interface{} {
"nullable": !mysql.HasNotNullFlag(col.GetFlag()),
"default": nil,
}
defaultValue := model.GetColumnDefaultValue(col)
defaultValue := col.GetDefaultValue()
if defaultValue != nil {
// according to TiDB source code, the default value is converted to string if not nil.
column["default"] = map[string]interface{}{
Expand Down
4 changes: 2 additions & 2 deletions pkg/sink/codec/simple/encoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1423,15 +1423,15 @@ func TestEncodeLargeEventsNormal(t *testing.T) {

obtainedDefaultValues := make(map[string]interface{}, len(obtainedDDL.TableInfo.Columns))
for _, col := range obtainedDDL.TableInfo.Columns {
obtainedDefaultValues[col.Name.O] = model.GetColumnDefaultValue(col)
obtainedDefaultValues[col.Name.O] = col.GetDefaultValue()
switch col.GetType() {
case mysql.TypeFloat, mysql.TypeDouble:
require.Equal(t, 0, col.GetDecimal())
default:
}
}
for _, col := range ddlEvent.TableInfo.Columns {
expected := model.GetColumnDefaultValue(col)
expected := col.GetDefaultValue()
obtained := obtainedDefaultValues[col.Name.O]
require.Equal(t, expected, obtained)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/sink/codec/simple/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func newColumnSchema(col *timodel.ColumnInfo) *columnSchema {
tp.Decimal = col.GetDecimal()
}

defaultValue := model.GetColumnDefaultValue(col)
defaultValue := col.GetDefaultValue()
if defaultValue != nil && col.GetType() == mysql.TypeBit {
defaultValue = common.MustBinaryLiteralToInt([]byte(defaultValue.(string)))
}
Expand Down
Loading