From d1afacc451cc9e8cd9d78dab4e38257191d38357 Mon Sep 17 00:00:00 2001 From: Ewan Chou Date: Fri, 1 Jul 2016 12:55:04 +0800 Subject: [PATCH] table: export `WritableCols` (#1369) --- table/table.go | 4 ++++ table/tables/bounded_tables.go | 5 +++++ table/tables/memory_tables.go | 5 +++++ table/tables/tables.go | 15 ++++++++------- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/table/table.go b/table/table.go index 6b36a47c80586..6fb91670f18b5 100644 --- a/table/table.go +++ b/table/table.go @@ -72,6 +72,10 @@ type Table interface { // Cols returns the columns of the table which is used in select. Cols() []*Column + // WritableCols returns columns of the table in writable states. + // Writable states includes Public, WriteOnly, WriteOnlyReorganization. + WritableCols() []*Column + // Indices returns the indices of the table. Indices() []Index diff --git a/table/tables/bounded_tables.go b/table/tables/bounded_tables.go index 91444bf33145b..2a822383b96df 100644 --- a/table/tables/bounded_tables.go +++ b/table/tables/bounded_tables.go @@ -145,6 +145,11 @@ func (t *BoundedTable) Cols() []*table.Column { return t.Columns } +// WritableCols implements table.Table WritableCols interface. +func (t *BoundedTable) WritableCols() []*table.Column { + return t.Columns +} + // RecordPrefix implements table.Table RecordPrefix interface. func (t *BoundedTable) RecordPrefix() kv.Key { return t.recordPrefix diff --git a/table/tables/memory_tables.go b/table/tables/memory_tables.go index 03c6311d2b68e..8b912ca13a026 100644 --- a/table/tables/memory_tables.go +++ b/table/tables/memory_tables.go @@ -132,6 +132,11 @@ func (t *MemoryTable) Cols() []*table.Column { return t.Columns } +// WritableCols implements table.Table WritableCols interface. +func (t *MemoryTable) WritableCols() []*table.Column { + return t.Columns +} + // RecordPrefix implements table.Table RecordPrefix interface. func (t *MemoryTable) RecordPrefix() kv.Key { return t.recordPrefix diff --git a/table/tables/tables.go b/table/tables/tables.go index b9053b8da9989..52527bf0b8a12 100644 --- a/table/tables/tables.go +++ b/table/tables/tables.go @@ -98,7 +98,7 @@ func newTable(tableID int64, cols []*table.Column, alloc autoid.Allocator) *Tabl } t.publicColumns = t.Cols() - t.writableColumns = t.writableCols() + t.writableColumns = t.WritableCols() return t } @@ -128,7 +128,8 @@ func (t *Table) Cols() []*table.Column { return t.publicColumns } -func (t *Table) writableCols() []*table.Column { +// WritableCols implements table WritableCols interface. +func (t *Table) WritableCols() []*table.Column { if len(t.writableColumns) > 0 { return t.writableColumns } @@ -181,7 +182,7 @@ func (t *Table) Truncate(ctx context.Context) error { // UpdateRecord implements table.Table UpdateRecord interface. func (t *Table) UpdateRecord(ctx context.Context, h int64, oldData []types.Datum, newData []types.Datum, touched map[int]bool) error { // We should check whether this table has on update column which state is write only. - currentData := make([]types.Datum, len(t.writableCols())) + currentData := make([]types.Datum, len(t.WritableCols())) copy(currentData, newData) // If they are not set, and other data are changed, they will be updated by current timestamp too. @@ -200,8 +201,8 @@ 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 i, col := range t.writableCols() { + colIDs := make([]int64, 0, len(t.WritableCols())) + for i, col := range t.WritableCols() { if col.State != model.StatePublic && currentData[i].IsNull() { defaultVal, _, err1 := table.GetColDefaultValue(ctx, &col.ColumnInfo) if err1 != nil { @@ -235,7 +236,7 @@ func (t *Table) UpdateRecord(ctx context.Context, h int64, oldData []types.Datum } func (t *Table) setOnUpdateData(ctx context.Context, touched map[int]bool, data []types.Datum) error { - ucols := table.FindOnUpdateCols(t.writableCols()) + ucols := table.FindOnUpdateCols(t.WritableCols()) for _, col := range ucols { if !touched[col.Offset] { value, err := evaluator.GetTimeValue(ctx, evaluator.CurrentTimestamp, col.Tp, col.Decimal) @@ -326,7 +327,7 @@ func (t *Table) AddRecord(ctx context.Context, r []types.Datum) (recordID int64, colIDs := make([]int64, 0, len(r)) row := make([]types.Datum, 0, len(r)) // Set public and write only column value. - for _, col := range t.writableCols() { + for _, col := range t.WritableCols() { if col.IsPKHandleColumn(t.meta) { continue }