Help us shape the future of Go! Take the 2026 Go Developer Survey

table

package
v1.0.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 20, 2018 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrNoDefaultValue is used when insert a row, the column value is not given, and the column has not null flag
	// and it doesn't have a default value.
	ErrNoDefaultValue = terror.ClassTable.New(codeNoDefaultValue, "field doesn't have a default value")
	// ErrIndexOutBound returns for index column offset out of bound.
	ErrIndexOutBound = terror.ClassTable.New(codeIndexOutBound, "index column offset out of bound")
	// ErrUnsupportedOp returns for unsupported operation.
	ErrUnsupportedOp = terror.ClassTable.New(codeUnsupportedOp, "operation not supported")
	// ErrRowNotFound returns for row not found.
	ErrRowNotFound = terror.ClassTable.New(codeRowNotFound, "can not find the row")
	// ErrTableStateCantNone returns for table none state.
	ErrTableStateCantNone = terror.ClassTable.New(codeTableStateCantNone, "table can not be in none state")
	// ErrColumnStateCantNone returns for column none state.
	ErrColumnStateCantNone = terror.ClassTable.New(codeColumnStateCantNone, "column can not be in none state")
	// ErrColumnStateNonPublic returns for column non-public state.
	ErrColumnStateNonPublic = terror.ClassTable.New(codeColumnStateNonPublic, "can not use non-public column")
	// ErrIndexStateCantNone returns for index none state.
	ErrIndexStateCantNone = terror.ClassTable.New(codeIndexStateCantNone, "index can not be in none state")
	// ErrInvalidRecordKey returns for invalid record key.
	ErrInvalidRecordKey = terror.ClassTable.New(codeInvalidRecordKey, "invalid record key")
	// ErrTruncateWrongValue returns for truncate wrong value for field.
	ErrTruncateWrongValue = terror.ClassTable.New(codeTruncateWrongValue, "Incorrect value")
)
View Source
var MockTableFromMeta func(tableInfo *model.TableInfo) Table

MockTableFromMeta only serves for test.

View Source
var TableFromMeta func(alloc autoid.Allocator, tblInfo *model.TableInfo) (Table, error)

TableFromMeta builds a table.Table from *model.TableInfo. Currently, it is assigned to tables.TableFromMeta in tidb package's init function.

Functions

func CastValue

func CastValue(ctx context.Context, val types.Datum, col *model.ColumnInfo) (casted types.Datum, err error)

CastValue casts a value based on column type.

func CastValues

func CastValues(ctx context.Context, rec []types.Datum, cols []*Column, ignoreErr bool) (err error)

CastValues casts values based on columns type.

func CheckNotNull

func CheckNotNull(cols []*Column, row []types.Datum) error

CheckNotNull checks if row has nil value set to a column with NotNull flag set.

func CheckOnce

func CheckOnce(cols []*Column) error

CheckOnce checks if there are duplicated column names in cols.

func ColDescFieldNames

func ColDescFieldNames(full bool) []string

ColDescFieldNames returns the fields name in result set for desc and show columns.

func GetColDefaultValue

func GetColDefaultValue(ctx context.Context, col *model.ColumnInfo) (types.Datum, error)

GetColDefaultValue gets default value of the column.

func GetColOriginDefaultValue

func GetColOriginDefaultValue(ctx context.Context, col *model.ColumnInfo) (types.Datum, error)

GetColOriginDefaultValue gets default value of the column from original default value.

func GetZeroValue

func GetZeroValue(col *model.ColumnInfo) types.Datum

GetZeroValue gets zero value for given column type.

Types

type ColDesc

type ColDesc struct {
	Field        string
	Type         string
	Collation    string
	Null         string
	Key          string
	DefaultValue interface{}
	Extra        string
	Privileges   string
	Comment      string
}

ColDesc describes column information like MySQL desc and show columns do.

func NewColDesc

func NewColDesc(col *Column) *ColDesc

NewColDesc returns a new ColDesc for a column.

type Column

type Column struct {
	*model.ColumnInfo
	// If this column is a generated column, the expression will be stored here.
	GeneratedExpr ast.ExprNode
}

Column provides meta data describing a table column.

func FindCol

func FindCol(cols []*Column, name string) *Column

FindCol finds column in cols by name.

func FindCols

func FindCols(cols []*Column, names []string) ([]*Column, error)

FindCols finds columns in cols by names.

func FindOnUpdateCols

func FindOnUpdateCols(cols []*Column) []*Column

FindOnUpdateCols finds columns which have OnUpdateNow flag.

func ToColumn

func ToColumn(col *model.ColumnInfo) *Column

ToColumn converts a *model.ColumnInfo to *Column.

func (*Column) CheckNotNull

func (c *Column) CheckNotNull(data types.Datum) error

CheckNotNull checks if nil value set to a column with NotNull flag is set.

func (*Column) GetTypeDesc

func (c *Column) GetTypeDesc() string

GetTypeDesc gets the description for column type.

func (*Column) IsPKHandleColumn

func (c *Column) IsPKHandleColumn(tbInfo *model.TableInfo) bool

IsPKHandleColumn checks if the column is primary key handle column.

func (*Column) String

func (c *Column) String() string

String implements fmt.Stringer interface.

func (*Column) ToInfo

func (c *Column) ToInfo() *model.ColumnInfo

ToInfo casts Column to model.ColumnInfo NOTE: DONT modify return value.

type Index

type Index interface {
	// Meta returns IndexInfo.
	Meta() *model.IndexInfo
	// Create supports insert into statement.
	Create(ctx context.Context, rm kv.RetrieverMutator,
		indexedValues []types.Datum, h int64) (int64, error)
	// Delete supports delete from statement.
	Delete(m kv.Mutator, indexedValues []types.Datum, h int64) error
	// Drop supports drop table, drop index statements.
	Drop(rm kv.RetrieverMutator) error
	// Exist supports check index exists or not.
	Exist(rm kv.RetrieverMutator, indexedValues []types.Datum, h int64) (bool, int64, error)
	// GenIndexKey generates an index key.
	GenIndexKey(indexedValues []types.Datum, h int64) (key []byte, distinct bool, err error)
	// Seek supports where clause.
	Seek(r kv.Retriever, indexedValues []types.Datum) (iter IndexIterator, hit bool, err error)
	// SeekFirst supports aggregate min and ascend order by.
	SeekFirst(r kv.Retriever) (iter IndexIterator, err error)
	// FetchValues fetched index column values in a row.
	FetchValues(row []types.Datum) (columns []types.Datum, err error)
}

Index is the interface for index data on KV store.

type IndexIterator

type IndexIterator interface {
	Next() (k []types.Datum, h int64, err error)
	Close()
}

IndexIterator is the interface for iterator of index data on KV store.

type RecordIterFunc

type RecordIterFunc func(h int64, rec []types.Datum, cols []*Column) (more bool, err error)

RecordIterFunc is used for low-level record iteration.

type Slice

type Slice []Table

Slice is used for table sorting.

func (Slice) Len

func (s Slice) Len() int

func (Slice) Less

func (s Slice) Less(i, j int) bool

func (Slice) Swap

func (s Slice) Swap(i, j int)

type Table

type Table interface {
	// IterRecords iterates records in the table and calls fn.
	IterRecords(ctx context.Context, startKey kv.Key, cols []*Column, fn RecordIterFunc) error

	// RowWithCols returns a row that contains the given cols.
	RowWithCols(ctx context.Context, h int64, cols []*Column) ([]types.Datum, error)

	// Row returns a row for all columns.
	Row(ctx context.Context, h int64) ([]types.Datum, error)

	// 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

	// WritableIndices returns write-only and public indices of the table.
	WritableIndices() []Index

	// DeletableIndices returns delete-only, write-only and public indices of the table.
	DeletableIndices() []Index

	// RecordPrefix returns the record key prefix.
	RecordPrefix() kv.Key

	// IndexPrefix returns the index key prefix.
	IndexPrefix() kv.Key

	// FirstKey returns the first key.
	FirstKey() kv.Key

	// RecordKey returns the key in KV storage for the row.
	RecordKey(h int64) kv.Key

	// AddRecord inserts a row which should contain only public columns
	// skipHandleCheck indicate that recordID in r has been checked as not duplicate already.
	AddRecord(ctx context.Context, r []types.Datum, skipHandleCheck bool) (recordID int64, err error)

	// UpdateRecord updates a row which should contain only writable columns.
	UpdateRecord(ctx context.Context, h int64, currData, newData []types.Datum, touched []bool) error

	// RemoveRecord removes a row in the table.
	RemoveRecord(ctx context.Context, h int64, r []types.Datum) error

	// AllocAutoID allocates an auto_increment ID for a new row.
	AllocAutoID(ctx context.Context) (int64, error)

	// Allocator returns Allocator.
	Allocator() autoid.Allocator

	// RebaseAutoID rebases the auto_increment ID base.
	// If allocIDs is true, it will allocate some IDs and save to the cache.
	// If allocIDs is false, it will not allocate IDs.
	RebaseAutoID(newBase int64, allocIDs bool) error

	// Meta returns TableInfo.
	Meta() *model.TableInfo

	// Seek returns the handle greater or equal to h.
	Seek(ctx context.Context, h int64) (handle int64, found bool, err error)

	// Type returns the type of table
	Type() Type
}

Table is used to retrieve and modify rows in table.

type Type

type Type int16

Type , the type of table, store data in different ways.

const (
	// NormalTable , store data in tikv, mocktikv and so on.
	NormalTable Type = iota
	// VirtualTable , store no data, just extract data from the memory struct.
	VirtualTable
	// MemoryTable , store data only in local memory.
	MemoryTable
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL