expression

package
v0.0.0-...-3056823 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2016 License: Apache-2.0 Imports: 13 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 AggFunctionMode

type AggFunctionMode int

AggFunctionMode stands for the aggregation function's mode.

const (
	// CompleteMode function accepts origin data.
	CompleteMode AggFunctionMode = iota
	// FinalMode function accepts partial data.
	FinalMode
)

type AggregationFunction

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

	// StreamUpdate updates data using streaming algo.
	StreamUpdate(row []types.Datum, ctx context.Context) error

	// SetMode sets aggFunctionMode for aggregate function
	SetMode(mode AggFunctionMode)

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

	// GetStreamResult gets a result using streaming agg.
	GetStreamResult() types.Datum

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

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

	// SetArgs set argument by index.
	SetArgs(args []Expression)

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

	// IsDistinct indicates if the aggregate function contains distinct attribute.
	IsDistinct() bool

	// SetContext sets the aggregate evaluation context.
	SetContext(ctx map[string](*ast.AggEvaluateContext))

	// Equal checks whether two aggregation functions are equal.
	Equal(agg AggregationFunction) bool
}

AggregationFunction stands for aggregate functions.

func NewAggFunction

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

NewAggFunction creates a new AggregationFunction.

type Assignment

type Assignment struct {
	Col  *Column
	Expr Expression
}

Assignment represents a set assignment in Update, such as Update t set c1 = hex(12), c2 = c3 where c2 = 1

type Column

type Column struct {
	FromID  string
	ColName model.CIStr
	DBName  model.CIStr
	TblName model.CIStr
	RetType *types.FieldType
	ID      int64
	// 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 implements Expression interface.

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) HashCode

func (col *Column) HashCode() []byte

HashCode implements Expression interface.

func (*Column) MarshalJSON

func (col *Column) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler interface.

func (*Column) SetValue

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

SetValue sets value for correlated columns.

func (*Column) String

func (col *Column) String() string

String implements Stringer 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) Equal

func (c *Constant) Equal(b Expression) bool

Equal 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) HashCode

func (c *Constant) HashCode() []byte

HashCode implements Expression interface.

func (*Constant) MarshalJSON

func (c *Constant) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler interface.

func (*Constant) String

func (c *Constant) String() string

String implements fmt.Stringer interface.

type Expression

type Expression interface {
	fmt.Stringer
	json.Marshaler
	// 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

	// HashCode create the hashcode for expression
	HashCode() []byte

	// Equal checks whether two expressions are equal.
	Equal(e Expression) bool
}

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 ComposeDNFCondition

func ComposeDNFCondition(conditions []Expression) Expression

ComposeDNFCondition composes DNF items into a balance deep DNF tree.

func NewFunction

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

NewFunction creates a new scalar function or constant.

func ScalarFuncs2Exprs

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

ScalarFuncs2Exprs converts []*ScalarFunction to []Expression.

func Schema2Exprs

func Schema2Exprs(schema Schema) []Expression

Schema2Exprs converts []*Column to []Expression.

func SplitCNFItems

func SplitCNFItems(onExpr Expression) []Expression

SplitCNFItems splits CNF items. CNF means conjunctive normal form, e.g. "a and b and c".

func SplitDNFItems

func SplitDNFItems(onExpr Expression) []Expression

SplitDNFItems splits DNF items. DNF means disjunctive normal form, e.g. "a or b or c".

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
	ArgValues []types.Datum
}

ScalarFunction is the function that returns a value.

func (*ScalarFunction) DeepCopy

func (sf *ScalarFunction) DeepCopy() Expression

DeepCopy implements Expression interface.

func (*ScalarFunction) Equal

func (sf *ScalarFunction) Equal(e Expression) bool

Equal 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) HashCode

func (sf *ScalarFunction) HashCode() []byte

HashCode implements Expression interface.

func (*ScalarFunction) MarshalJSON

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

MarshalJSON implements json.Marshaler interface.

func (*ScalarFunction) String

func (sf *ScalarFunction) String() string

String implements fmt.Stringer 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) String

func (s Schema) String() string

String implements fmt.Stringer interface.

Jump to

Keyboard shortcuts

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