Documentation ¶
Index ¶
- Constants
- Variables
- func DefaultSessionConfig() map[string]TypedValue
- func HasAvailableMemory(r Reporter) bool
- func HasDefaultValue(s Session, key string) (bool, interface{})
- func IsArray(t Type) bool
- func IsChar(t Type) bool
- func IsDecimal(t Type) bool
- func IsInteger(t Type) bool
- func IsNumber(t Type) bool
- func IsSigned(t Type) bool
- func IsText(t Type) bool
- func IsTime(t Type) bool
- func IsTuple(t Type) bool
- func IsUnsigned(t Type) bool
- func IsVarChar(t Type) bool
- func MySQLTypeName(t Type) string
- func NumColumns(t Type) int
- func ValidateTime(t time.Time) interface{}
- type BaseSession
- func (s *BaseSession) Address() string
- func (s *BaseSession) ClearWarnings()
- func (s *BaseSession) Client() Client
- func (s *BaseSession) Get(key string) (Type, interface{})
- func (s *BaseSession) GetAll() map[string]TypedValue
- func (s *BaseSession) ID() uint32
- func (s *BaseSession) Set(key string, typ Type, value interface{})
- func (s *BaseSession) Warn(warn *Warning)
- func (s *BaseSession) WarningCount() uint16
- func (s *BaseSession) Warnings() []*Warning
- type Catalog
- type Client
- type Column
- type Context
- func (c *Context) Error(code int, msg string, args ...interface{})
- func (c *Context) Pid() uint64
- func (c *Context) Query() string
- func (c *Context) RootSpan() opentracing.Span
- func (c *Context) Span(opName string, opts ...opentracing.StartSpanOption) (opentracing.Span, *Context)
- func (c *Context) Warn(code int, msg string, args ...interface{})
- func (c *Context) WithContext(ctx context.Context) *Context
- type ContextOption
- type Database
- type Databaser
- type Databases
- type Disposable
- type DisposeFunc
- type Freeable
- type KeyValueCache
- type MemoryManager
- type Nameable
- type Node
- type PartitionProgress
- type Process
- type ProcessList
- func (pl *ProcessList) AddPartitionProgress(pid uint64, tableName, partitionName string, total int64)
- func (pl *ProcessList) AddProcess(ctx *Context, typ ProcessType, query string) (*Context, error)
- func (pl *ProcessList) AddTableProgress(pid uint64, name string, total int64)
- func (pl *ProcessList) Done(pid uint64)
- func (pl *ProcessList) Kill(connID uint32)
- func (pl *ProcessList) KillOnlyQueries(connID uint32)
- func (pl *ProcessList) Processes() []Process
- func (pl *ProcessList) RemovePartitionProgress(pid uint64, tableName, partitionName string)
- func (pl *ProcessList) RemoveTableProgress(pid uint64, name string)
- func (pl *ProcessList) UpdatePartitionProgress(pid uint64, tableName, partitionName string, delta int64)
- func (pl *ProcessList) UpdateTableProgress(pid uint64, name string, delta int64)
- type ProcessType
- type Progress
- type Reporter
- type Row
- type RowIter
- type RowsCache
- type Schema
- type Session
- type Table
- type TableProgress
- type Tableable
- type Type
- type TypedValue
- type Warning
Constants ¶
const DateLayout = "2006-01-02"
DateLayout is the layout of the MySQL date format in the representation Go understands.
const DatetimeLayout = "2006-01-02 15:04:05"
DatetimeLayout is the layout of the MySQL date format in the representation Go understands.
const ( // QueryKey to access query in the context. QueryKey key = iota )
const TimestampLayout = "2006-01-02 15:04:05"
TimestampLayout is the formatting string with the layout of the timestamp using the format of Go "time" package.
Variables ¶
var ( // ErrInvalidType is thrown when there is an unexpected type at some part of // the execution tree. ErrInvalidType = errors.NewKind("invalid type: %s") // ErrTableAlreadyExists is thrown when someone tries to create a // table with a name of an existing one ErrTableAlreadyExists = errors.NewKind("table with name %s already exists") // ErrTableNotFound is returned when the table is not available from the // current scope. ErrTableNotFound = errors.NewKind("table not found: %s") //ErrUnexpectedRowLength is thrown when the obtained row has more columns than the schema ErrUnexpectedRowLength = errors.NewKind("expected %d values, got %d") // ErrInvalidChildrenNumber is returned when the WithChildren method of a // node or expression is called with an invalid number of arguments. ErrInvalidChildrenNumber = errors.NewKind("%T: invalid children number, got %d, expected %d") // ErrDeleteRowNotFound ???? ErrDeleteRowNotFound = errors.NewKind("row was not found when attempting to delete").New() )
var ( // ErrTypeNotSupported is thrown when a specific type is not supported ErrTypeNotSupported = errors.NewKind("Type not supported: %s") // ErrUnexpectedType is thrown when a received type is not the expected ErrUnexpectedType = errors.NewKind("value at %d has unexpected type: %s") // ErrConvertingToTime is thrown when a value cannot be converted to a Time ErrConvertingToTime = errors.NewKind("value %q can't be converted to time.Time") // ErrCharTruncation is thrown when a Char value is textually longer than the destination capacity ErrCharTruncation = errors.NewKind("string value of %q is longer than destination capacity %d") // ErrVarCharTruncation is thrown when a VarChar value is textually longer than the destination capacity ErrVarCharTruncation = errors.NewKind("string value of %q is longer than destination capacity %d") // ErrValueNotNil is thrown when a value that was expected to be nil, is not ErrValueNotNil = errors.NewKind("value not nil: %#v") // ErrNotTuple is returned when the value is not a tuple. ErrNotTuple = errors.NewKind("value of type %T is not a tuple") // ErrInvalidColumnNumber is returned when a tuple has an invalid number of // arguments. ErrInvalidColumnNumber = errors.NewKind("tuple should contain %d column(s), but has %d") // ErrNotArray is returned when the value is not an array. ErrNotArray = errors.NewKind("value of type %T is not an array") // ErrConvertToSQL is returned when Convert failed. // It makes an error less verbose comparingto what spf13/cast returns. ErrConvertToSQL = errors.NewKind("incompatible conversion to SQL type: %s") )
var ( // Null represents the null type. Null nullT // Int8 is an integer of 8 bits Int8 = numberT{/* contains filtered or unexported fields */} // Uint8 is an unsigned integer of 8 bits Uint8 = numberT{/* contains filtered or unexported fields */} // Int16 is an integer of 16 bits Int16 = numberT{/* contains filtered or unexported fields */} // Uint16 is an unsigned integer of 16 bits Uint16 = numberT{/* contains filtered or unexported fields */} // Int24 is an integer of 24 bits. Int24 = numberT{/* contains filtered or unexported fields */} // Uint24 is an unsigned integer of 24 bits. Uint24 = numberT{/* contains filtered or unexported fields */} // Int32 is an integer of 32 bits. Int32 = numberT{/* contains filtered or unexported fields */} // Uint32 is an unsigned integer of 32 bits. Uint32 = numberT{/* contains filtered or unexported fields */} // Int64 is an integer of 64 bytes. Int64 = numberT{/* contains filtered or unexported fields */} // Uint64 is an unsigned integer of 64 bits. Uint64 = numberT{/* contains filtered or unexported fields */} // Float32 is a floating point number of 32 bits. Float32 = numberT{/* contains filtered or unexported fields */} // Float64 is a floating point number of 64 bits. Float64 = numberT{/* contains filtered or unexported fields */} // Timestamp is an UNIX timestamp. Timestamp timestampT // Date is a date with day, month and year. Date dateT // Datetime is a date and a time Datetime datetimeT // Text is a string type. Text textT // Boolean is a boolean type. Boolean booleanT // JSON is a type that holds any valid JSON object. JSON jsonT // Blob is a type that holds a chunk of binary data. Blob blobT )
var ErrDatabaseNotFound = errors.NewKind("database not found: %s")
ErrDatabaseNotFound is thrown when a database is not found
var ErrNoMemoryAvailable = errors.NewKind("no memory available")
ErrNoMemoryAvailable is returned when there is no more available memory.
var ErrPidAlreadyUsed = errors.NewKind("pid %d is already in use")
ErrPidAlreadyUsed is returned when the pid is already registered.
var TimestampLayouts = []string{ "2006-01-02", time.RFC3339, "20060102150405", "20060102", }
TimestampLayouts hold extra timestamps allowed for parsing. It does not have all the layouts supported by mysql. Missing are two digit year versions of common cases and dates that use non common separators.
https://github.com/MariaDB/server/blob/mysql-5.5.36/sql-common/my_time.c#L124
Functions ¶
func DefaultSessionConfig ¶
func DefaultSessionConfig() map[string]TypedValue
DefaultSessionConfig returns default values for session variables
func HasAvailableMemory ¶
HasAvailableMemory reports whether more memory is available to the program if it hasn't reached the max memory limit.
func HasDefaultValue ¶
HasDefaultValue checks if session variable value is the default one.
func IsTuple ¶
IsTuple checks if t is a tuple type. Note that tupleT instances with just 1 value are not considered as a tuple, but a parenthesized value.
func MySQLTypeName ¶
MySQLTypeName returns the MySQL display name for the given type.
func NumColumns ¶
NumColumns returns the number of columns in a type. This is one for all types, except tuples.
func ValidateTime ¶
ValidateTime receives a time and returns either that time or nil if it's not a valid time.
Types ¶
type BaseSession ¶
type BaseSession struct {
// contains filtered or unexported fields
}
BaseSession is the basic session type.
func (*BaseSession) Address ¶
func (s *BaseSession) Address() string
Address returns the server address.
func (*BaseSession) ClearWarnings ¶
func (s *BaseSession) ClearWarnings()
ClearWarnings cleans up session warnings
func (*BaseSession) Client ¶
func (s *BaseSession) Client() Client
Client returns session's client information.
func (*BaseSession) Get ¶
func (s *BaseSession) Get(key string) (Type, interface{})
Get implements the Session interface.
func (*BaseSession) GetAll ¶
func (s *BaseSession) GetAll() map[string]TypedValue
GetAll returns a copy of session configuration
func (*BaseSession) Set ¶
func (s *BaseSession) Set(key string, typ Type, value interface{})
Set implements the Session interface.
func (*BaseSession) Warn ¶
func (s *BaseSession) Warn(warn *Warning)
Warn stores the warning in the session.
func (*BaseSession) WarningCount ¶
func (s *BaseSession) WarningCount() uint16
WarningCount returns a number of session warnings
func (*BaseSession) Warnings ¶
func (s *BaseSession) Warnings() []*Warning
Warnings returns a copy of session warnings (from the most recent - the last one) The function implements sql.Session interface
type Catalog ¶
type Catalog struct { // FunctionRegistry // *IndexRegistry *ProcessList *MemoryManager // contains filtered or unexported fields }
Catalog holds databases, tables and functions.
func (*Catalog) AddDatabase ¶
AddDatabase adds a new database to the catalog.
func (*Catalog) AllDatabases ¶
AllDatabases returns all databases in the catalog.
func (*Catalog) CurrentDatabase ¶
CurrentDatabase returns the current database.
func (*Catalog) SetCurrentDatabase ¶
SetCurrentDatabase changes the current database.
type Column ¶
type Column struct { // Name is the name of the column. Name string // Type is the data type of the column. Type Type // Default contains the default value of the column or nil if it is NULL. Default interface{} // Nullable is true if the column can contain NULL values, or false // otherwise. Nullable bool // Source is the name of the table this column came from. Source string // PrimaryKey is true if the column is part of the primary key for its table. PrimaryKey bool }
Column is the definition of a table column. As SQL:2016 puts it:
A column is a named component of a table. It has a data type, a default, and a nullability characteristic.
type Context ¶
type Context struct { context.Context Session Memory *MemoryManager // contains filtered or unexported fields }
Context of the query execution.
func NewContext ¶
func NewContext( ctx context.Context, opts ...ContextOption, ) *Context
NewContext creates a new query context. Options can be passed to configure the context. If some aspect of the context is not configure, the default value will be used. By default, the context will have an empty base session, a noop tracer and a memory manager using the process reporter.
func NewEmptyContext ¶
func NewEmptyContext() *Context
NewEmptyContext returns a default context with default values.
func (*Context) RootSpan ¶
func (c *Context) RootSpan() opentracing.Span
RootSpan returns the root span, if any.
func (*Context) Span ¶
func (c *Context) Span( opName string, opts ...opentracing.StartSpanOption, ) (opentracing.Span, *Context)
Span creates a new tracing span with the given context. It will return the span and a new context that should be passed to all childrens of this span.
type ContextOption ¶
type ContextOption func(*Context)
ContextOption is a function to configure the context.
func WithMemoryManager ¶
func WithMemoryManager(m *MemoryManager) ContextOption
WithMemoryManager adds the given memory manager to the context.
func WithQuery ¶
func WithQuery(q string) ContextOption
WithQuery adds the given query to the context.
func WithRootSpan ¶
func WithRootSpan(s opentracing.Span) ContextOption
WithRootSpan sets the root span of the context.
func WithSession ¶
func WithSession(s Session) ContextOption
WithSession adds the given session to the context.
func WithTracer ¶
func WithTracer(t opentracing.Tracer) ContextOption
WithTracer adds the given tracer to the context.
type Database ¶
type Database interface { Nameable // Tables returns the information of all tables. Tables() map[string]Table }
Database represents the database.
type Databaser ¶
type Databaser interface { // Database the current database. Database() Database // WithDatabase returns a new node instance with the database replaced with // the one given as parameter. WithDatabase(Database) (Node, error) }
Databaser is a node that contains a reference to a database.
type Databases ¶
type Databases []Database
Databases is a collection of Database.
type Disposable ¶
type Disposable interface {
// Dispose the contents.
Dispose()
}
Disposable objects can erase all their content when they're no longer in use. They should not be used again after they've been disposed.
type DisposeFunc ¶
type DisposeFunc func()
DisposeFunc is a function to completely erase a cache and remove it from the manager.
type Freeable ¶
type Freeable interface {
// Free the memory.
Free()
}
Freeable objects can free their memory.
type KeyValueCache ¶
type KeyValueCache interface { // Put a new value in the cache. Put(uint64, interface{}) error // Get the value with the given key. Get(uint64) (interface{}, error) }
KeyValueCache is a cache of key value pairs.
type MemoryManager ¶
type MemoryManager struct {
// contains filtered or unexported fields
}
MemoryManager is in charge of keeping track and managing all the components that operate in memory. There should only be one instance of a memory manager running at the same time in each process.
func NewMemoryManager ¶
func NewMemoryManager(r Reporter) *MemoryManager
NewMemoryManager creates a new manager with the given memory reporter. If nil is given, then the Process reporter will be used by default.
func (*MemoryManager) HasAvailable ¶
func (m *MemoryManager) HasAvailable() bool
HasAvailable reports whether the memory manager has any available memory.
type Nameable ¶
type Nameable interface { // Name returns the name. Name() string }
Nameable is something that has a name.
type Node ¶
type Node interface { // Resolvable fmt.Stringer // Schema of the node. Schema() Schema // // Children nodes. // Children() []Node // RowIter produces a row iterator from this node. RowIter(*Context) (RowIter, error) }
Node is a node in the execution plan tree.
type PartitionProgress ¶
type PartitionProgress struct {
Progress
}
PartitionProgress keeps track of a partition progress
func (PartitionProgress) String ¶
func (p PartitionProgress) String() string
type Process ¶
type Process struct { Pid uint64 Connection uint32 User string Type ProcessType Query string Progress map[string]TableProgress StartedAt time.Time Kill context.CancelFunc }
Process represents a process in the SQL server.
type ProcessList ¶
type ProcessList struct {
// contains filtered or unexported fields
}
ProcessList is a structure that keeps track of all the processes and their status.
func (*ProcessList) AddPartitionProgress ¶
func (pl *ProcessList) AddPartitionProgress(pid uint64, tableName, partitionName string, total int64)
AddPartitionProgress adds a new item to track progress from to the process with the given pid. If the pid or the table does not exist, it will do nothing.
func (*ProcessList) AddProcess ¶
func (pl *ProcessList) AddProcess( ctx *Context, typ ProcessType, query string, ) (*Context, error)
AddProcess adds a new process to the list given a process type and a query. Steps is a map between the name of the items that need to be completed and the total amount in these items. -1 means unknown. It returns a new context that should be passed around from now on. That context will be cancelled if the process is killed.
func (*ProcessList) AddTableProgress ¶
func (pl *ProcessList) AddTableProgress(pid uint64, name string, total int64)
AddTableProgress adds a new item to track progress from to the process with the given pid. If the pid does not exist, it will do nothing.
func (*ProcessList) Done ¶
func (pl *ProcessList) Done(pid uint64)
Done removes the finished process with the given pid from the process list. If the process does not exist, it will do nothing.
func (*ProcessList) Kill ¶
func (pl *ProcessList) Kill(connID uint32)
Kill terminates all queries for a given connection id.
func (*ProcessList) KillOnlyQueries ¶
func (pl *ProcessList) KillOnlyQueries(connID uint32)
KillOnlyQueries kills all queries, but not index creation queries, for a given connection id.
func (*ProcessList) Processes ¶
func (pl *ProcessList) Processes() []Process
Processes returns the list of current running processes.
func (*ProcessList) RemovePartitionProgress ¶
func (pl *ProcessList) RemovePartitionProgress(pid uint64, tableName, partitionName string)
RemovePartitionProgress removes an existing item tracking progress from the process with the given pid, if it exists.
func (*ProcessList) RemoveTableProgress ¶
func (pl *ProcessList) RemoveTableProgress(pid uint64, name string)
RemoveTableProgress removes an existing item tracking progress from the process with the given pid, if it exists.
func (*ProcessList) UpdatePartitionProgress ¶
func (pl *ProcessList) UpdatePartitionProgress(pid uint64, tableName, partitionName string, delta int64)
UpdatePartitionProgress updates the progress of the table partition with the given name for the process with the given pid.
func (*ProcessList) UpdateTableProgress ¶
func (pl *ProcessList) UpdateTableProgress(pid uint64, name string, delta int64)
UpdateTableProgress updates the progress of the table with the given name for the process with the given pid.
type ProcessType ¶
type ProcessType byte
ProcessType is the type of process.
const ( // QueryProcess is a query process. QueryProcess ProcessType = iota // CreateIndexProcess is a process to create an index. CreateIndexProcess )
func (ProcessType) String ¶
func (p ProcessType) String() string
type Reporter ¶
type Reporter interface { // MaxMemory returns the maximum number of memory allowed in bytes. MaxMemory() uint64 // UsedMemory returns the memory in use in bytes. UsedMemory() uint64 }
Reporter is a component that gives information about the memory usage.
type Row ¶
type Row []interface{}
Row is a tuple of values.
func NodeToRows ¶
NodeToRows converts a node to a slice of rows.
func RowIterToRows ¶
RowIterToRows converts a row iterator to a slice of rows.
type RowIter ¶
type RowIter interface { // Next retrieves the next row. It will return io.EOF if it's the last row. // After retrieving the last row, Close will be automatically closed. Next() (Row, error) // Close the iterator. Close() error }
RowIter is an iterator that produces rows.
func NewSpanIter ¶
func NewSpanIter(span opentracing.Span, iter RowIter) RowIter
NewSpanIter creates a RowIter executed in the given span.
func RowsToRowIter ¶
RowsToRowIter creates a RowIter that iterates over the given rows.
type RowsCache ¶
type RowsCache interface { // Add a new row to the cache. If there is no memory available, it will try to // free some memory. If after that there is still no memory available, it // will return an error and erase all the content of the cache. Add(Row) error // Get all rows. Get() []Row }
RowsCache is a cache of rows.
type Schema ¶
type Schema []*Column
Schema is the definition of a table.
type Session ¶
type Session interface { // Address of the server. Address() string // User of the session. Client() Client // Set session configuration. Set(key string, typ Type, value interface{}) // Get session configuration. Get(key string) (Type, interface{}) // GetAll returns a copy of session configuration GetAll() map[string]TypedValue // ID returns the unique ID of the connection. ID() uint32 // Warn stores the warning in the session. Warn(warn *Warning) // Warnings returns a copy of session warnings (from the most recent). Warnings() []*Warning // ClearWarnings cleans up session warnings. ClearWarnings() // WarningCount returns a number of session warnings WarningCount() uint16 }
Session holds the session data.
func NewSession ¶
NewSession creates a new session with data.
type TableProgress ¶
type TableProgress struct { Progress PartitionsProgress map[string]PartitionProgress }
TableProgress keeps track of a table progress, and for each of its partitions
func NewTableProgress ¶
func NewTableProgress(name string, total int64) TableProgress
NewTableProgress ??????
func (TableProgress) String ¶
func (p TableProgress) String() string
type Tableable ¶
type Tableable interface { // Table returns the table name. Table() string }
Tableable is something that has a table.
type Type ¶
type Type interface { // Type returns the query.Type for the given Type. Type() query.Type // Covert a value of a compatible type to a most accurate type. Convert(interface{}) (interface{}, error) // Compare returns an integer comparing two values. // The result will be 0 if a==b, -1 if a < b, and +1 if a > b. Compare(interface{}, interface{}) (int, error) // SQL returns the sqltypes.Value for the given value. SQL(interface{}) (sqltypes.Value, error) fmt.Stringer }
Type represent a SQL type.
func MysqlTypeToType ¶
MysqlTypeToType gets the column type using the mysql type
func UnderlyingType ¶
UnderlyingType returns the underlying type of an array if the type is an array, or the type itself in any other case.
type TypedValue ¶
type TypedValue struct { Typ Type Value interface{} }
TypedValue is a value along with its type.