From 9bf6e03812fb549e05e655eb07f178af29d85ba7 Mon Sep 17 00:00:00 2001 From: Ewan Chou Date: Wed, 29 Jun 2016 14:29:20 +0800 Subject: [PATCH] table/table: set default value when write only column is null (#1357) The test cover this issue need some work, will be added in next PR. --- table/tables/tables.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/table/tables/tables.go b/table/tables/tables.go index c024db208b1c2..a30afbe46ef24 100644 --- a/table/tables/tables.go +++ b/table/tables/tables.go @@ -201,7 +201,14 @@ func (t *Table) UpdateRecord(ctx context.Context, h int64, oldData []types.Datum // Compose new row t.composeNewData(touched, currentData, oldData) colIDs := make([]int64, 0, len(t.writableCols())) - for _, col := range t.writableCols() { + for i, col := range t.writableCols() { + if col.State != model.StatePublic && currentData[i].IsNull() { + defaultVal, _, err := table.GetColDefaultValue(ctx, &col.ColumnInfo) + if err != nil { + return errors.Trace(err) + } + currentData[i] = defaultVal + } colIDs = append(colIDs, col.ID) } // Set new row data into KV.