Skip to content

Commit

Permalink
table: export WritableCols (pingcap#1369)
Browse files Browse the repository at this point in the history
  • Loading branch information
coocood authored Jul 1, 2016
1 parent a6ed1e7 commit d1afacc
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
4 changes: 4 additions & 0 deletions table/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions table/tables/bounded_tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions table/tables/memory_tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 8 additions & 7 deletions table/tables/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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.
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit d1afacc

Please sign in to comment.