expression

package
v0.0.0-...-3903214 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2021 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// All the exported errors are defined here:
	ErrIncorrectParameterCount = terror.ClassExpression.New(mysql.ErrWrongParamcountToNativeFct, mysql.MySQLErrName[mysql.ErrWrongParamcountToNativeFct])
	ErrDivisionByZero          = terror.ClassExpression.New(mysql.ErrDivisionByZero, mysql.MySQLErrName[mysql.ErrDivisionByZero])
	ErrRegexp                  = terror.ClassExpression.New(mysql.ErrRegexp, mysql.MySQLErrName[mysql.ErrRegexp])
	ErrOperandColumns          = terror.ClassExpression.New(mysql.ErrOperandColumns, mysql.MySQLErrName[mysql.ErrOperandColumns])
	ErrCutValueGroupConcat     = terror.ClassExpression.New(mysql.ErrCutValueGroupConcat, mysql.MySQLErrName[mysql.ErrCutValueGroupConcat])
	ErrFunctionsNoopImpl       = terror.ClassExpression.New(mysql.ErrNotSupportedYet, "function %s has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions")
	ErrIncorrectType           = terror.ClassExpression.New(mysql.ErrIncorrectType, mysql.MySQLErrName[mysql.ErrIncorrectType])
)

Error instances.

View Source
var (

	// CollationStrictness indicates the strictness of comparison of the collation. The unequal order in a weak collation also holds in a strict collation.
	// For example, if a < b in a weak collation(e.g. general_ci), then there must be a < b in a strict collation(e.g. _bin).
	CollationStrictness = map[string]int{
		"utf8_general_ci":        0,
		"utf8mb4_general_ci":     0,
		charset.CollationASCII:   1,
		charset.CollationLatin1:  1,
		charset.CollationUTF8:    1,
		charset.CollationUTF8MB4: 1,
		charset.CollationBin:     2,
	}
)

error definitions.

Functions

func CompareInt

func CompareInt(sctx sctx.Context, lhsArg, rhsArg Expression, lhsRow, rhsRow chunk.Row) (int64, bool, error)

CompareInt compares two integers.

func CompareStringWithCollationInfo

func CompareStringWithCollationInfo(sctx sctx.Context, lhsArg, rhsArg Expression, lhsRow, rhsRow chunk.Row, collation string) (int64, bool, error)

CompareStringWithCollationInfo compares two strings with the specified collation information.

func EvalBool

func EvalBool(ctx sctx.Context, exprList CNFExprs, row chunk.Row) (bool, bool, error)

EvalBool evaluates expression list to a boolean value. The first returned value indicates bool result of the expression list, the second returned value indicates whether the result of the expression list is null, it can only be true when the first returned values is false.

func FindFieldName

func FindFieldName(names types.NameSlice, astCol *ast.ColumnName) (int, error)

FindFieldName finds the column name from NameSlice.

func GetAccurateCmpType

func GetAccurateCmpType(lhs, rhs Expression) types.EvalType

GetAccurateCmpType uses a more complex logic to decide the EvalType of the two args when compare with each other than getBaseCmpType does.

func GetBuiltinList

func GetBuiltinList() []string

GetBuiltinList returns a list of builtin functions

func GetRowLen

func GetRowLen(e Expression) int

GetRowLen gets the length if the func is row, returns 1 if not row.

func GetUsedList

func GetUsedList(usedCols []*Column, schema *Schema) []bool

GetUsedList shows whether each column in schema is contained in usedCols.

func IsFunctionSupported

func IsFunctionSupported(name string) bool

IsFunctionSupported check if given function name is a builtin sql function.

Types

type CNFExprs

type CNFExprs []Expression

CNFExprs stands for a CNF expression.

func (CNFExprs) Clone

func (e CNFExprs) Clone() CNFExprs

Clone clones itself.

func (CNFExprs) Shallow

func (e CNFExprs) Shallow() CNFExprs

Shallow makes a shallow copy of itself.

type Coercibility

type Coercibility int

Coercibility values are used to check whether the collation of one item can be coerced to the collation of other. See https://dev.mysql.com/doc/refman/8.0/en/charset-collation-coercibility.html

const (
	// CoercibilityExplicit is derived from an explicit COLLATE clause.
	CoercibilityExplicit Coercibility = 0
	// CoercibilityNone is derived from the concatenation of two strings with different collations.
	CoercibilityNone Coercibility = 1
	// CoercibilityImplicit is derived from a column or a stored routine parameter or local variable.
	CoercibilityImplicit Coercibility = 2
	// CoercibilitySysconst is derived from a “system constant” (the string returned by functions such as USER() or VERSION()).
	CoercibilitySysconst Coercibility = 3
	// CoercibilityCoercible is derived from a literal.
	CoercibilityCoercible Coercibility = 4
	// CoercibilityNumeric is derived from a numeric or temporal value.
	CoercibilityNumeric Coercibility = 5
	// CoercibilityIgnorable is derived from NULL or an expression that is derived from NULL.
	CoercibilityIgnorable Coercibility = 6
)

type CollationInfo

type CollationInfo interface {
	// HasCoercibility returns if the Coercibility value is initialized.
	HasCoercibility() bool

	// Coercibility returns the coercibility value which is used to check collations.
	Coercibility() Coercibility

	// SetCoercibility sets a specified coercibility for this expression.
	SetCoercibility(val Coercibility)

	// CharsetAndCollation ...
	CharsetAndCollation(ctx sessionctx.Context) (string, string)

	// SetCharsetAndCollation ...
	SetCharsetAndCollation(chs, coll string)
}

CollationInfo contains all interfaces about dealing with collation.

type Column

type Column struct {
	RetType *types.FieldType
	// ID is used to specify whether this column is ExtraHandleColumn or to access histogram.
	// We'll try to remove it in the future.
	ID int64
	// UniqueID is the unique id of this column.
	UniqueID int64

	// Index is used for execution, to tell the column's position in the given row.
	Index int

	OrigName string
	IsHidden bool

	//collationInfo
	Family string
	// contains filtered or unexported fields
}

Column represents a column.

func ExtractColumns

func ExtractColumns(expr Expression) []*Column

ExtractColumns extracts all columns from an expression.

func (*Column) Clone

func (col *Column) Clone() Expression

Clone implements Expression interface.

func (*Column) Equal

func (col *Column) Equal(_ sctx.Context, expr Expression) bool

Equal implements Expression interface.

func (*Column) Eval

func (col *Column) Eval(row chunk.Row) (types.Datum, error)

Eval implements Expression interface.

func (*Column) EvalInt

func (col *Column) EvalInt(ctx sctx.Context, row chunk.Row) (int64, bool, error)

EvalInt returns int representation of Column.

func (*Column) EvalString

func (col *Column) EvalString(ctx sctx.Context, row chunk.Row) (string, bool, error)

EvalString returns string representation of Column.

func (*Column) GetType

func (col *Column) GetType() *types.FieldType

GetType implements Expression interface.

func (*Column) String

func (col *Column) String() string

String implements Stringer interface.

func (*Column) ToColumnMeta

func (col *Column) ToColumnMeta() *model.ColumnMeta

type CompareFunc

type CompareFunc = func(sctx sctx.Context, lhsArg, rhsArg Expression, lhsRow, rhsRow chunk.Row) (int64, bool, error)

CompareFunc defines the compare function prototype.

type Constant

type Constant struct {
	Value   types.Datum
	RetType *types.FieldType
	// contains filtered or unexported fields
}

Constant stands for a constant value.

func DatumToConstant

func DatumToConstant(d types.Datum, tp byte) *Constant

DatumToConstant generates a Constant expression from a Datum.

func (*Constant) Clone

func (c *Constant) Clone() Expression

Clone implements Expression interface.

func (*Constant) Equal

func (c *Constant) Equal(ctx sctx.Context, b Expression) bool

Equal implements Expression interface.

func (*Constant) Eval

func (c *Constant) Eval(row chunk.Row) (types.Datum, error)

Eval implements Expression interface.

func (*Constant) EvalInt

func (c *Constant) EvalInt(ctx sctx.Context, row chunk.Row) (int64, bool, error)

EvalInt returns int representation of Constant.

func (*Constant) EvalString

func (c *Constant) EvalString(ctx sctx.Context, row chunk.Row) (string, bool, error)

EvalString returns string representation of Constant.

func (*Constant) GetType

func (c *Constant) GetType() *types.FieldType

GetType implements Expression interface.

type Expression

type Expression interface {
	// Eval evaluates an expression through a row.
	Eval(row chunk.Row) (types.Datum, error)

	// EvalInt returns the int64 representation of expression.
	EvalInt(ctx sctx.Context, row chunk.Row) (val int64, isNull bool, err error)

	// EvalString returns the string representation of expression.
	EvalString(ctx sctx.Context, row chunk.Row) (val string, isNull bool, err error)

	// GetType gets the type that the expression returns.
	GetType() *types.FieldType

	// Equal checks whether two expressions are equal.
	Equal(ctx sctx.Context, e Expression) bool

	// Clone copies an expression totally.
	Clone() Expression
}

Expression represents all scalar expression in SQL.

func NewFunction

func NewFunction(ctx sctx.Context, funcName string, retType *types.FieldType, args ...Expression) (Expression, error)

NewFunction creates a new scalar function or constant via a constant folding.

func NewFunctionBase

func NewFunctionBase(ctx sctx.Context, funcName string, retType *types.FieldType, args ...Expression) (Expression, error)

NewFunctionBase creates a new scalar function with no constant folding.

func NewFunctionInternal

func NewFunctionInternal(ctx sctx.Context, funcName string, retType *types.FieldType, args ...Expression) Expression

NewFunctionInternal is similar to NewFunction, but do not returns error, should only be used internally.

func ScalarFuncs2Exprs

func ScalarFuncs2Exprs(funcs []*ScalarFunction) []Expression

ScalarFuncs2Exprs converts []*ScalarFunction to []Expression.

type KeyInfo

type KeyInfo []*Column

KeyInfo stores the columns of one unique key or primary key.

func (KeyInfo) Clone

func (ki KeyInfo) Clone() KeyInfo

Clone copies the entire UniqueKey.

type ScalarFunction

type ScalarFunction struct {
	FuncName model.CIStr
	// RetType is the type that ScalarFunction returns.
	// TODO: Implement type inference here, now we use ast's return type temporarily.
	RetType  *types.FieldType
	Function builtinFunc
}

ScalarFunction is the function that returns a value.

func (*ScalarFunction) Clone

func (sf *ScalarFunction) Clone() Expression

Clone implements Expression interface.

func (*ScalarFunction) Equal

func (sf *ScalarFunction) Equal(ctx sctx.Context, e Expression) bool

Equal implements Expression interface.

func (*ScalarFunction) Eval

func (sf *ScalarFunction) Eval(row chunk.Row) (d types.Datum, err error)

Eval implements Expression interface.

func (*ScalarFunction) EvalInt

func (sf *ScalarFunction) EvalInt(ctx sctx.Context, row chunk.Row) (int64, bool, error)

EvalInt implements Expression interface.

func (*ScalarFunction) EvalString

func (sf *ScalarFunction) EvalString(ctx sctx.Context, row chunk.Row) (string, bool, error)

EvalString implements Expression interface.

func (*ScalarFunction) GetArgs

func (sf *ScalarFunction) GetArgs() []Expression

GetArgs gets arguments of function.

func (*ScalarFunction) GetCtx

func (sf *ScalarFunction) GetCtx() sctx.Context

GetCtx gets the context of function.

func (*ScalarFunction) GetType

func (sf *ScalarFunction) GetType() *types.FieldType

GetType implements Expression interface.

func (*ScalarFunction) MarshalJSON

func (sf *ScalarFunction) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler interface.

type Schema

type Schema struct {
	Columns []*Column
	Keys    []KeyInfo
}

Schema stands for the row schema and unique key information get from input.

func MergeSchema

func MergeSchema(lSchema, rSchema *Schema) *Schema

MergeSchema will merge two schema into one schema. We shouldn't need to consider unique keys. That will be processed in build_key_info.go.

func NewSchema

func NewSchema(cols ...*Column) *Schema

NewSchema returns a schema made by its parameter.

func (*Schema) Append

func (s *Schema) Append(col ...*Column)

Append append new column to the columns stored in schema.

func (*Schema) Clone

func (s *Schema) Clone() *Schema

Clone copies the total schema.

func (*Schema) ColumnIndex

func (s *Schema) ColumnIndex(col *Column) int

ColumnIndex finds the index for a column.

func (*Schema) ColumnsByIndices

func (s *Schema) ColumnsByIndices(offsets []int) []*Column

ColumnsByIndices returns columns by multiple offsets. Callers should guarantee that all the offsets provided should be valid, which means offset should: 1. not smaller than 0, and 2. not exceed len(s.Columns)

func (*Schema) ColumnsIndices

func (s *Schema) ColumnsIndices(cols []*Column) (ret []int)

ColumnsIndices will return a slice which contains the position of each column in schema. If there is one column that doesn't match, nil will be returned.

func (*Schema) Contains

func (s *Schema) Contains(col *Column) bool

Contains checks if the schema contains the column.

func (*Schema) Len

func (s *Schema) Len() int

Len returns the number of columns in schema.

func (*Schema) RetrieveColumn

func (s *Schema) RetrieveColumn(col *Column) *Column

RetrieveColumn retrieves column in expression from the columns in schema.

func (*Schema) SetUniqueKeys

func (s *Schema) SetUniqueKeys(keys []KeyInfo)

SetUniqueKeys will set the value of Schema.Keys.

func (*Schema) String

func (s *Schema) String() string

String implements fmt.Stringer interface.

type VarAssignment

type VarAssignment struct {
	Name        string
	Expr        Expression
	IsDefault   bool
	IsGlobal    bool
	IsSystem    bool
	ExtendValue *Constant
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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