expression

package
v0.0.0-...-815d2fd Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2016 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EvalBool

func EvalBool(expr Expression, row []types.Datum, ctx context.Context) (bool, error)

EvalBool evaluates expression to a boolean value.

Types

type AggregationFunction

type AggregationFunction interface {
	// Update during executing.
	Update(row []types.Datum, groupKey []byte, ctx context.Context) error

	// GetGroupResult will be called when all data have been processed.
	GetGroupResult(groupKey []byte) types.Datum

	// GetArgs stands for getting all arguments.
	GetArgs() []Expression

	// GetName gets the aggregation function name.
	GetName() string

	// SetArgs set argument by index.
	SetArgs(idx int, expr Expression)

	// Clear collects the mapper's memory.
	Clear()
}

AggregationFunction stands for aggregate functions.

func NewAggFunction

func NewAggFunction(funcType string, funcArgs []Expression, distinct bool) AggregationFunction

NewAggFunction creates a new AggregationFunction.

type Column

type Column struct {
	FromID  string
	ColName model.CIStr
	DBName  model.CIStr
	TblName model.CIStr
	RetType *types.FieldType
	// Position means the position of this column that appears in the select fields.
	// e.g. SELECT name as id , 1 - id as id , 1 + name as id, name as id from src having id = 1;
	// There are four ids in the same schema, so you can't identify the column through the FromID and ColName.
	Position int
	// IsAggOrSubq means if this column is referenced to a Aggregation column or a Subquery column.
	// If so, this column's name will be the plain sql text.
	IsAggOrSubq bool

	// only used during execution
	Index      int
	Correlated bool
	// contains filtered or unexported fields
}

Column represents a column.

func (*Column) DeepCopy

func (col *Column) DeepCopy() Expression

DeepCopy implements Expression interface.

func (*Column) Equal

func (col *Column) Equal(expr Expression) bool

Equal checks if two columns are equal

func (*Column) Eval

func (col *Column) Eval(row []types.Datum, _ context.Context) (types.Datum, error)

Eval implements Expression interface.

func (*Column) GetType

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

GetType implements Expression interface.

func (*Column) SetValue

func (col *Column) SetValue(d *types.Datum)

SetValue sets value for correlated columns.

func (*Column) ToString

func (col *Column) ToString() string

ToString implements Expression interface.

type Constant

type Constant struct {
	Value   types.Datum
	RetType *types.FieldType
}

Constant stands for a constant value.

func (*Constant) DeepCopy

func (c *Constant) DeepCopy() Expression

DeepCopy implements Expression interface.

func (*Constant) Eval

func (c *Constant) Eval(_ []types.Datum, _ context.Context) (types.Datum, error)

Eval implements Expression interface.

func (*Constant) GetType

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

GetType implements Expression interface.

func (*Constant) ToString

func (c *Constant) ToString() string

ToString implements Expression interface.

type Expression

type Expression interface {
	// Eval evaluates an expression through a row.
	Eval(row []types.Datum, ctx context.Context) (types.Datum, error)

	// Get the expression return type.
	GetType() *types.FieldType

	// DeepCopy copies an expression totally.
	DeepCopy() Expression

	// ToString converts an expression into a string.
	ToString() string
}

Expression represents all scalar expression in SQL.

func ComposeCNFCondition

func ComposeCNFCondition(conditions []Expression) Expression

ComposeCNFCondition composes CNF items into a balance deep CNF tree, which benefits a lot for pb decoder/encoder.

func ScalarFuncs2Exprs

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

ScalarFuncs2Exprs converts []*ScalarFunction to []Expression.

func Schema2Exprs

func Schema2Exprs(schema Schema) []Expression

Schema2Exprs converts []*Column to []Expression.

type ScalarFunction

type ScalarFunction struct {
	Args     []Expression
	FuncName model.CIStr
	// TODO: Implement type inference here, now we use ast's return type temporarily.
	RetType  *types.FieldType
	Function evaluator.BuiltinFunc
}

ScalarFunction is the function that returns a value.

func NewFunction

func NewFunction(funcName string, retType *types.FieldType, args ...Expression) (*ScalarFunction, error)

NewFunction creates a new scalar function.

func (*ScalarFunction) DeepCopy

func (sf *ScalarFunction) DeepCopy() Expression

DeepCopy implements Expression interface.

func (*ScalarFunction) Eval

func (sf *ScalarFunction) Eval(row []types.Datum, ctx context.Context) (types.Datum, error)

Eval implements Expression interface.

func (*ScalarFunction) GetType

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

GetType implements Expression interface.

func (*ScalarFunction) ToString

func (sf *ScalarFunction) ToString() string

ToString implements Expression interface.

type Schema

type Schema []*Column

Schema stands for the row schema get from input.

func (Schema) DeepCopy

func (s Schema) DeepCopy() Schema

DeepCopy copies the total schema.

func (Schema) FindColumn

func (s Schema) FindColumn(astCol *ast.ColumnName) (*Column, error)

FindColumn finds an Column from schema for a ast.ColumnName. It compares the db/table/column names. If there are more than one result, it will raise ambiguous error.

func (Schema) GetIndex

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

GetIndex finds the index for a column.

func (Schema) InitIndices

func (s Schema) InitIndices()

InitIndices sets indices for 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) ToString

func (s Schema) ToString() string

ToString output the contents of schema, for debug.

Jump to

Keyboard shortcuts

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