expr

package
v0.0.0-...-c484601 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2015 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// Standard errors
	ErrNotSupported   = fmt.Errorf("qlbridge Not supported")
	ErrNotImplemented = fmt.Errorf("qlbridge Not implemented")
	ErrUnknownCommand = fmt.Errorf("qlbridge Unknown Command")
	ErrInternalError  = fmt.Errorf("qlbridge Internal Error")
)

We have a default Dialect, which is the "Language" or rule-set of ql

Functions

func CountFunc

func CountFunc(ctx EvalContext, val value.Value) (value.IntValue, bool)

Count

func FindAllIdentityField

func FindAllIdentityField(node Node) []string

Recursively descend down a node looking for all Identity Fields

min(year)                 == {year}
eq(min(item), max(month)) == {item, month}

func FindIdentityField

func FindIdentityField(node Node) string

Recursively descend down a node looking for first Identity Field

min(year)                 == year
eq(min(item), max(month)) == item

func FindIdentityName

func FindIdentityName(depth int, node Node, prefix string) string

Recursively descend down a node looking for first Identity Field

and combine with outermost expression to create an alias

  min(year)                 == min_year
  eq(min(year), max(month)) == eq_year

func FuncAdd

func FuncAdd(name string, fn interface{})

Adding Functions to the VM occurs here. Functions have the following

pseudo interface.

   1.  They must have expr.ContextReader as first argument
   2.  They must accept 1 OR variadic number of value.Value arguments
   3.  Return must be a value.Value, or anything that implements value Interface
        and bool

   func(ctx expr.ContextReader, value.Value...) (value.Value, bool) {
       // function
   }
   func(ctx expr.ContextReader, value.Value...) (value.StringValue, bool) {
       // function
   }
   func(ctx expr.ContextReader, value.Value, value.Value) (value.NumberValue, bool) {
       // function
   }

func FuncsGet

func FuncsGet() map[string]Func

func PowFunc

func PowFunc(ctx EvalContext, val, toPower value.Value) (value.NumberValue, bool)

Pow

func SqrtFunc

func SqrtFunc(ctx EvalContext, val value.Value) (value.NumberValue, bool)

Sqrt

func ValueTypeFromNode

func ValueTypeFromNode(n Node) value.ValueType

Infer Value type from Node

Types

type BinaryNode

type BinaryNode struct {
	Paren    bool
	Args     [2]Node
	Operator lex.Token
}

Binary node is x op y, two nodes (left, right) and an operator operators can be a variety of:

+, -, *, %, /,

Also, parenthesis may wrap these

func NewBinaryNode

func NewBinaryNode(operator lex.Token, lhArg, rhArg Node) *BinaryNode

Create a Binary node

 @operator = * + - %/ / && || = ==
 @operator =  and, or, "is not"
@lhArg, rhArg the left, right side of binary

func (*BinaryNode) Check

func (m *BinaryNode) Check() error

func (*BinaryNode) FingerPrint

func (m *BinaryNode) FingerPrint(r rune) string

func (*BinaryNode) IsSimple

func (m *BinaryNode) IsSimple() bool

A simple binary function is one who does not have nested expressions

underneath it, ie just value = y

func (*BinaryNode) NodeType

func (m *BinaryNode) NodeType() NodeType

func (*BinaryNode) String

func (m *BinaryNode) String() string

func (*BinaryNode) Type

func (m *BinaryNode) Type() reflect.Value

type Column

type Column struct {
	ParentIndex int    // slice idx position in parent query cols
	Index       int    // slice idx position in original query cols
	SourceIndex int    // slice idx position in source []driver.Value
	SourceField string // field name of underlying field
	As          string // As field, auto-populate the Field Name if exists
	Comment     string // optional in-line comments
	Order       string // (ASC | DESC)
	Star        bool   // *
	Expr        Node   // Expression, optional, often Identity.Node
	Guard       Node   // column If guard, non-standard sql column guard
	// contains filtered or unexported fields
}

Column represents the Column as expressed in a [SELECT] expression

func NewColumn

func NewColumn(col string) *Column

func NewColumnFromToken

func NewColumnFromToken(tok lex.Token) *Column

func (*Column) Copy

func (m *Column) Copy() *Column

func (*Column) CopyRewrite

func (m *Column) CopyRewrite(alias string) *Column

Create a new copy of this column for rewrite purposes re-alias

func (*Column) CountStar

func (m *Column) CountStar() bool

Is this a select count(*) column

func (*Column) FingerPrint

func (m *Column) FingerPrint(r rune) string

func (*Column) Key

func (m *Column) Key() string

func (*Column) LeftRight

func (m *Column) LeftRight() (string, string, bool)

Return left, right values if is of form `table.column` and also return true/false for if it even has left/right

func (*Column) String

func (m *Column) String() string

type Columns

type Columns []*Column

List of Columns in SELECT [columns]

func (*Columns) AliasedFieldNames

func (m *Columns) AliasedFieldNames() []string

func (*Columns) ByAs

func (m *Columns) ByAs(as string) (*Column, bool)

func (*Columns) ByName

func (m *Columns) ByName(name string) (*Column, bool)

func (*Columns) FieldNames

func (m *Columns) FieldNames() []string

func (*Columns) FingerPrint

func (m *Columns) FingerPrint(r rune) string

func (*Columns) String

func (m *Columns) String() string

func (*Columns) UnAliasedFieldNames

func (m *Columns) UnAliasedFieldNames() []string

type CommandColumn

type CommandColumn struct {
	Expr Node   // column expression
	Name string // Original path/name for command field
}

func (*CommandColumn) FingerPrint

func (m *CommandColumn) FingerPrint(r rune) string

func (*CommandColumn) String

func (m *CommandColumn) String() string

type CommandColumns

type CommandColumns []*CommandColumn

SQL commands such as:

set autocommit
SET @@local.sort_buffer_size=10000;
USE myschema;

func (*CommandColumns) FingerPrint

func (m *CommandColumns) FingerPrint(r rune) string

func (*CommandColumns) String

func (m *CommandColumns) String() string

type Context

type Context struct {
	context.Context
	DisableRecover bool
	Errors         []error
	// contains filtered or unexported fields
}

Context for Plan/Execution

func NewContext

func NewContext() *Context

func (*Context) Recover

func (m *Context) Recover()

type ContextReader

type ContextReader interface {
	Get(key string) (value.Value, bool)
	Row() map[string]value.Value
	Ts() time.Time
}

Context Reader is interface to read the context of message/row/command

being evaluated

type ContextWriter

type ContextWriter interface {
	Put(col SchemaInfo, readCtx ContextReader, v value.Value) error
	Delete(row map[string]value.Value) error
}

For evaluation storage

type EvalContext

type EvalContext interface {
	ContextReader
}

Eval context, used to contain info for usage/lookup at runtime evaluation

type FilterExpr

type FilterExpr struct {
	// Exactly one of these will be non-nil
	Include string   // name of foregin named alias filter to embed
	Expr    Node     // Node might be nil in which case must have filter
	Filter  *Filters // might be nil, must have expr
}

func NewFilterExpr

func NewFilterExpr() *FilterExpr

func (*FilterExpr) String

func (fe *FilterExpr) String() string

String representation of FilterExpression for diagnostic purposes.

type FilterQLParser

type FilterQLParser struct {
	*FilterTokenPager
	// contains filtered or unexported fields
}

generic Filter QL parser

type FilterStatement

type FilterStatement struct {
	Keyword lex.TokenType // Keyword SELECT or FILTER
	Raw     string        // full original raw statement
	Filter  *Filters      // A top level filter
	From    string        // From is optional
	Limit   int           // Limit
	Offset  int           // Offset
	Alias   string        // Non-Standard sql, alias/name of sql another way of expression Prepared Statement
	With    u.JsonHelper  // Non-Standard SQL for properties/config info, similar to Cassandra with, purse json
}

func NewFilterStatement

func NewFilterStatement() *FilterStatement

func ParseFilterQL

func ParseFilterQL(filter string) (*FilterStatement, error)

Parses Tokens and returns an request.

func ParseFilterQLVm

func ParseFilterQLVm(filter string) (*FilterStatement, error)

type FilterTokenPager

type FilterTokenPager struct {
	*LexTokenPager
	// contains filtered or unexported fields
}

TokenPager is responsible for determining end of current clause

An interface used to allow Parser to be neutral to dialect

func NewFilterTokenPager

func NewFilterTokenPager(lex *lex.Lexer) *FilterTokenPager

func (*FilterTokenPager) ClauseEnd

func (m *FilterTokenPager) ClauseEnd() bool

func (*FilterTokenPager) IsEnd

func (m *FilterTokenPager) IsEnd() bool

type Filters

type Filters struct {
	Op      lex.TokenType // OR, AND
	Filters []*FilterExpr
}

func NewFilters

func NewFilters(tok lex.Token) *Filters

func (*Filters) String

func (f *Filters) String() string

String representation of Filters for diagnostic purposes.

type Func

type Func struct {
	Name string
	// The arguments we expect
	Args            []reflect.Value
	VariadicArgs    bool
	Return          reflect.Value
	ReturnValueType value.ValueType
	// The actual Go Function
	F reflect.Value
}

Describes a function which wraps and allows native go functions

to be called (via reflection) via scripting

type FuncNode

type FuncNode struct {
	Name string // Name of func
	F    Func   // The actual function that this AST maps to
	Args []Node // Arguments are them-selves nodes
}

FuncNode holds a Func, which desribes a go Function as well as fulfilling the Pos, String() etc for a Node

interfaces: Node

func NewFuncNode

func NewFuncNode(name string, f Func) *FuncNode

func (*FuncNode) Check

func (c *FuncNode) Check() error

func (*FuncNode) FingerPrint

func (c *FuncNode) FingerPrint(r rune) string

func (*FuncNode) NodeType

func (f *FuncNode) NodeType() NodeType

func (*FuncNode) String

func (c *FuncNode) String() string

func (*FuncNode) Type

func (f *FuncNode) Type() reflect.Value

type IdentityNode

type IdentityNode struct {
	Quote byte
	Text  string
	// contains filtered or unexported fields
}

IdentityNode will look up a value out of a env bag

also identities of sql objects (tables, columns, etc)
we often need to rewrite these as in sql it is `table.column`

func NewIdentityNode

func NewIdentityNode(tok *lex.Token) *IdentityNode

func (*IdentityNode) Bool

func (m *IdentityNode) Bool() bool

func (*IdentityNode) Check

func (m *IdentityNode) Check() error

func (*IdentityNode) FingerPrint

func (m *IdentityNode) FingerPrint(r rune) string

func (*IdentityNode) IsBooleanIdentity

func (m *IdentityNode) IsBooleanIdentity() bool

func (*IdentityNode) LeftRight

func (m *IdentityNode) LeftRight() (string, string, bool)

Return left, right values if is of form `table.column` and also return true/false for if it even has left/right

func (*IdentityNode) NodeType

func (m *IdentityNode) NodeType() NodeType

func (*IdentityNode) String

func (m *IdentityNode) String() string

func (*IdentityNode) Type

func (m *IdentityNode) Type() reflect.Value

type LexTokenPager

type LexTokenPager struct {
	// contains filtered or unexported fields
}

TokenPager is responsible for determining end of current tree (column, etc)

func NewLexTokenPager

func NewLexTokenPager(lex *lex.Lexer) *LexTokenPager

func (*LexTokenPager) Backup

func (m *LexTokenPager) Backup()

backup backs the input stream up one token.

func (*LexTokenPager) ClauseEnd

func (m *LexTokenPager) ClauseEnd() bool

func (*LexTokenPager) Cur

func (m *LexTokenPager) Cur() lex.Token

func (*LexTokenPager) IsEnd

func (m *LexTokenPager) IsEnd() bool

func (*LexTokenPager) Last

func (m *LexTokenPager) Last() lex.TokenType

func (*LexTokenPager) Lexer

func (m *LexTokenPager) Lexer() *lex.Lexer

func (*LexTokenPager) Next

func (m *LexTokenPager) Next() lex.Token

next returns the next token.

func (*LexTokenPager) Peek

func (m *LexTokenPager) Peek() lex.Token

peek returns but does not consume the next token.

type MultiArgNode

type MultiArgNode struct {
	Args     []Node
	Operator lex.Token
}

Multi Arg Node

arg0 IN (arg1,arg2.....)
arg0 IN sliceident
arg0 IN mapident
5 in (1,2,3,4)   => false

func NewMultiArgNode

func NewMultiArgNode(operator lex.Token) *MultiArgNode

Create a Multi Arg node

@operator = In
@args ....

func NewMultiArgNodeArgs

func NewMultiArgNodeArgs(operator lex.Token, args []Node) *MultiArgNode

func (*MultiArgNode) Append

func (m *MultiArgNode) Append(n Node)

func (*MultiArgNode) Check

func (m *MultiArgNode) Check() error

func (*MultiArgNode) FingerPrint

func (m *MultiArgNode) FingerPrint(r rune) string

func (*MultiArgNode) NodeType

func (m *MultiArgNode) NodeType() NodeType

func (*MultiArgNode) String

func (m *MultiArgNode) String() string

func (*MultiArgNode) Type

func (m *MultiArgNode) Type() reflect.Value

type Node

type Node interface {
	// string representation of Node, AST parseable back to itself
	String() string

	// string representation of Node, AST but with values replaced by @rune (? generally)
	FingerPrint(r rune) string

	// performs type checking for itself and sub-nodes, evaluates
	// validity of the expression/node in advance of evaluation
	Check() error

	// describes the Node type, faster than interface casting
	NodeType() NodeType
}

A Node is an element in the expression tree, implemented by different types (string, binary, urnary, func, case, etc)

type NodeType

type NodeType uint8
const (
	NodeNodeType        NodeType = 1
	FuncNodeType        NodeType = 2
	IdentityNodeType    NodeType = 3
	StringNodeType      NodeType = 4
	NumberNodeType      NodeType = 5
	ValueNodeType       NodeType = 8
	BinaryNodeType      NodeType = 10
	UnaryNodeType       NodeType = 11
	TriNodeType         NodeType = 13
	MultiArgNodeType    NodeType = 14
	NullNodeType        NodeType = 15
	SqlPreparedType     NodeType = 29
	SqlSelectNodeType   NodeType = 30
	SqlInsertNodeType   NodeType = 31
	SqlUpdateNodeType   NodeType = 32
	SqlUpsertNodeType   NodeType = 33
	SqlDeleteNodeType   NodeType = 35
	SqlDescribeNodeType NodeType = 40
	SqlShowNodeType     NodeType = 41
	SqlCommandNodeType  NodeType = 42
	SqlCreateNodeType   NodeType = 50
	SqlSourceNodeType   NodeType = 55
	SqlWhereNodeType    NodeType = 56
	SqlIntoNodeType     NodeType = 57
	SqlJoinNodeType     NodeType = 58
)

func (NodeType) String

func (nt NodeType) String() string

String representation of NodeTypes for diagnostic purposes.

type NodeValueType

type NodeValueType interface {
	// describes the return type
	Type() reflect.Value
}

Node that has a Type Value

type NullNode

type NullNode struct{}

func NewNull

func NewNull(operator lex.Token) *NullNode

func (*NullNode) Check

func (n *NullNode) Check() error

func (*NullNode) FingerPrint

func (m *NullNode) FingerPrint(r rune) string

func (*NullNode) NodeType

func (m *NullNode) NodeType() NodeType

func (*NullNode) String

func (m *NullNode) String() string

func (*NullNode) Type

func (m *NullNode) Type() reflect.Value

type NumberNode

type NumberNode struct {
	IsInt   bool    // Number has an integer value.
	IsFloat bool    // Number has a floating-point value.
	Int64   int64   // The integer value.
	Float64 float64 // The floating-point value.
	Text    string  // The original textual representation from the input.
}

NumberNode holds a number: signed or unsigned integer or float. The value is parsed and stored under all the types that can represent the value. This simulates in a small amount of code the behavior of Go's ideal constants.

func NewNumber

func NewNumber(fv float64) (*NumberNode, error)

func NewNumberStr

func NewNumberStr(text string) (*NumberNode, error)

NewNumberStr is a little weird in that this Node accepts string @text and uses go to parse into Int, AND Float.

func (*NumberNode) Check

func (n *NumberNode) Check() error

func (*NumberNode) FingerPrint

func (n *NumberNode) FingerPrint(r rune) string

func (*NumberNode) NodeType

func (m *NumberNode) NodeType() NodeType

func (*NumberNode) String

func (n *NumberNode) String() string

func (*NumberNode) Type

func (n *NumberNode) Type() reflect.Value

type ParsedNode

type ParsedNode interface {
	Finalize() error
}

type PreparedStatement

type PreparedStatement struct {
	Alias     string
	Statement SqlStatement
}

Prepared/Aliased SQL

func NewPreparedStatement

func NewPreparedStatement() *PreparedStatement

func (*PreparedStatement) Accept

func (m *PreparedStatement) Accept(visitor Visitor) (interface{}, error)

func (*PreparedStatement) Check

func (m *PreparedStatement) Check() error

func (*PreparedStatement) FingerPrint

func (m *PreparedStatement) FingerPrint(r rune) string

func (*PreparedStatement) Keyword

func (m *PreparedStatement) Keyword() lex.TokenType

func (*PreparedStatement) NodeType

func (m *PreparedStatement) NodeType() NodeType

func (*PreparedStatement) String

func (m *PreparedStatement) String() string

func (*PreparedStatement) Type

func (m *PreparedStatement) Type() reflect.Value

type Projection

type Projection struct {
	Distinct bool
	Columns  ResultColumns
}

Projection is just the ResultColumns for a result-set

func NewProjection

func NewProjection() *Projection

func (*Projection) AddColumnShort

func (m *Projection) AddColumnShort(name string, vt value.ValueType)

type ResultColumn

type ResultColumn struct {
	//Expr   Node            // If expression, is here
	Name   string          // Original path/name for query field
	ColPos int             // Ordinal position in sql statement
	Col    *Column         // the original sql column
	Star   bool            // Was this a select * ??
	As     string          // aliased
	Type   value.ValueType // Data Type
}

Result Column

func NewResultColumn

func NewResultColumn(as string, ordinal int, col *Column, valtype value.ValueType) *ResultColumn

type ResultColumns

type ResultColumns []*ResultColumn

type RowWriter

type RowWriter interface {
	Commit(rowInfo []SchemaInfo, row RowWriter) error
	Put(col SchemaInfo, readCtx ContextReader, v value.Value) error
}

for commiting row ops (insert, update)

type SchemaInfo

type SchemaInfo interface {
	Key() string
}

SchemaInfo is interface for a Column type

type SqlCommand

type SqlCommand struct {
	Columns  CommandColumns
	Identity string
	Value    Node
	// contains filtered or unexported fields
}

func (*SqlCommand) Accept

func (m *SqlCommand) Accept(visitor Visitor) (interface{}, error)

func (*SqlCommand) Check

func (m *SqlCommand) Check() error

func (*SqlCommand) FingerPrint

func (m *SqlCommand) FingerPrint(r rune) string

func (*SqlCommand) Keyword

func (m *SqlCommand) Keyword() lex.TokenType

func (*SqlCommand) NodeType

func (m *SqlCommand) NodeType() NodeType

func (*SqlCommand) String

func (m *SqlCommand) String() string

func (*SqlCommand) Type

func (m *SqlCommand) Type() reflect.Value

type SqlDelete

type SqlDelete struct {
	Table string
	Where Node
	Limit int
}

func NewSqlDelete

func NewSqlDelete() *SqlDelete

func (*SqlDelete) Accept

func (m *SqlDelete) Accept(visitor Visitor) (interface{}, error)

func (*SqlDelete) Check

func (m *SqlDelete) Check() error

func (*SqlDelete) FingerPrint

func (m *SqlDelete) FingerPrint(r rune) string

func (*SqlDelete) Keyword

func (m *SqlDelete) Keyword() lex.TokenType

func (*SqlDelete) NodeType

func (m *SqlDelete) NodeType() NodeType

func (*SqlDelete) SqlSelect

func (m *SqlDelete) SqlSelect() *SqlSelect

func (*SqlDelete) String

func (m *SqlDelete) String() string

func (*SqlDelete) Type

func (m *SqlDelete) Type() reflect.Value

type SqlDescribe

type SqlDescribe struct {
	Identity string
	Tok      lex.Token // Explain, Describe, Desc
	Stmt     SqlStatement
}

func (*SqlDescribe) Accept

func (m *SqlDescribe) Accept(visitor Visitor) (interface{}, error)

func (*SqlDescribe) Check

func (m *SqlDescribe) Check() error

func (*SqlDescribe) FingerPrint

func (m *SqlDescribe) FingerPrint(r rune) string

func (*SqlDescribe) Keyword

func (m *SqlDescribe) Keyword() lex.TokenType

func (*SqlDescribe) NodeType

func (m *SqlDescribe) NodeType() NodeType

func (*SqlDescribe) String

func (m *SqlDescribe) String() string

func (*SqlDescribe) Type

func (m *SqlDescribe) Type() reflect.Value

type SqlInsert

type SqlInsert struct {
	Table   string           // table name
	Columns Columns          // Column Names
	Rows    [][]*ValueColumn // Values to insert
	Select  *SqlSelect       //
	// contains filtered or unexported fields
}

func NewSqlInsert

func NewSqlInsert() *SqlInsert

func (*SqlInsert) Accept

func (m *SqlInsert) Accept(visitor Visitor) (interface{}, error)

func (*SqlInsert) Check

func (m *SqlInsert) Check() error

func (*SqlInsert) ColumnNames

func (m *SqlInsert) ColumnNames() []string

func (*SqlInsert) FingerPrint

func (m *SqlInsert) FingerPrint(r rune) string

func (*SqlInsert) Keyword

func (m *SqlInsert) Keyword() lex.TokenType

func (m *Join) Accept(visitor SubVisitor) (interface{}, error) { return visitor.VisitSubselect(m) } func (m *Join) Keyword() lex.TokenType { return lex.TokenJoin } func (m *Join) Check() error { return nil } func (m *Join) Type() reflect.Value { return nilRv } func (m *Join) NodeType() NodeType { return SqlJoinNodeType } func (m *Join) StringAST() string { return m.String() } func (m *Join) String() string { return fmt.Sprintf("%s", m.Table) }

func (*SqlInsert) NodeType

func (m *SqlInsert) NodeType() NodeType

func (*SqlInsert) String

func (m *SqlInsert) String() string

func (*SqlInsert) Type

func (m *SqlInsert) Type() reflect.Value

type SqlInto

type SqlInto struct {
	Table string
}

func NewSqlInto

func NewSqlInto(table string) *SqlInto

func (*SqlInto) Check

func (m *SqlInto) Check() error

func (*SqlInto) FingerPrint

func (m *SqlInto) FingerPrint(r rune) string

func (*SqlInto) Keyword

func (m *SqlInto) Keyword() lex.TokenType

func (*SqlInto) NodeType

func (m *SqlInto) NodeType() NodeType

func (*SqlInto) String

func (m *SqlInto) String() string

func (*SqlInto) Type

func (m *SqlInto) Type() reflect.Value

type SqlSelect

type SqlSelect struct {
	Db       string       // If provided a use "dbname"
	Raw      string       // full original raw statement
	Star     bool         // for select * from ...
	Distinct bool         // Distinct flag?
	Columns  Columns      // An array (ordered) list of columns
	From     []*SqlSource // From, Join
	Into     *SqlInto     // Into "table"
	Where    *SqlWhere    // Expr Node, or *SqlSelect
	Having   Node         // Filter results
	GroupBy  Columns
	OrderBy  Columns
	Limit    int
	Offset   int
	Alias    string       // Non-Standard sql, alias/name of sql another way of expression Prepared Statement
	With     u.JsonHelper // Non-Standard SQL for properties/config info, similar to Cassandra with, purse json
	// contains filtered or unexported fields
}

SQL Select statement

func NewSqlSelect

func NewSqlSelect() *SqlSelect

func (*SqlSelect) Accept

func (m *SqlSelect) Accept(visitor Visitor) (interface{}, error)

func (*SqlSelect) AddColumn

func (m *SqlSelect) AddColumn(colArg Column) error

func (*SqlSelect) AliasedColumns

func (m *SqlSelect) AliasedColumns() map[string]*Column

func (*SqlSelect) Check

func (m *SqlSelect) Check() error

func (*SqlSelect) CountStar

func (m *SqlSelect) CountStar() bool

Is this a select count(*) FROM ... query?

func (*SqlSelect) Finalize

func (m *SqlSelect) Finalize() error

Finalize this Query plan by preparing sub-sources

ie we need to rewrite some things into sub-statements
- we need to share the join expression across sources

func (*SqlSelect) FingerPrint

func (m *SqlSelect) FingerPrint(r rune) string

func (*SqlSelect) FingerPrintID

func (m *SqlSelect) FingerPrintID() int64

func (*SqlSelect) Keyword

func (m *SqlSelect) Keyword() lex.TokenType

func (*SqlSelect) NodeType

func (m *SqlSelect) NodeType() NodeType

func (*SqlSelect) Projection

func (m *SqlSelect) Projection(p *Projection) *Projection

func (*SqlSelect) Rewrite

func (m *SqlSelect) Rewrite()

func (*SqlSelect) String

func (m *SqlSelect) String() string

func (*SqlSelect) SysVariable

func (m *SqlSelect) SysVariable() string

Is this a internal variable query?

@@max_packet_size   ??

func (*SqlSelect) Type

func (m *SqlSelect) Type() reflect.Value

func (*SqlSelect) UnAliasedColumns

func (m *SqlSelect) UnAliasedColumns() map[string]*Column

type SqlShow

type SqlShow struct {
	Raw      string
	Identity string
	From     string
	Full     bool
}

func (*SqlShow) Accept

func (m *SqlShow) Accept(visitor Visitor) (interface{}, error)

func (*SqlShow) Check

func (m *SqlShow) Check() error

func (*SqlShow) FingerPrint

func (m *SqlShow) FingerPrint(r rune) string

func (*SqlShow) Keyword

func (m *SqlShow) Keyword() lex.TokenType

func (*SqlShow) NodeType

func (m *SqlShow) NodeType() NodeType

func (*SqlShow) String

func (m *SqlShow) String() string

func (*SqlShow) Type

func (m *SqlShow) Type() reflect.Value

type SqlSource

type SqlSource struct {
	// Plan Hints, move to a dedicated planner
	Seekable bool

	Source      *SqlSelect    // Sql Select Source query, written by Rewrite
	Raw         string        // Raw Partial Query
	Name        string        // From Name (optional, empty if join, subselect)
	Alias       string        // From name aliased
	Op          lex.TokenType // In, =, ON
	LeftOrRight lex.TokenType // Left, Right
	JoinType    lex.TokenType // INNER, OUTER
	JoinExpr    Node          // Join expression       x.y = q.y
	SubQuery    *SqlSelect    // optional, Join/SubSelect statement
	// contains filtered or unexported fields
}

Source is a table name, sub-query, or join as used in SELECT <columns> FROM <SQLSOURCE>

  • SELECT .. FROM table_name
  • SELECT .. from (select a,b,c from tableb)
  • SELECT .. FROM tablex INNER JOIN ...

func NewSqlSource

func NewSqlSource(table string) *SqlSource

func (*SqlSource) Accept

func (m *SqlSource) Accept(visitor SubVisitor) (interface{}, error)

func (*SqlSource) BuildColIndex

func (m *SqlSource) BuildColIndex(colNames []string) error

func (*SqlSource) Check

func (m *SqlSource) Check() error

func (*SqlSource) ColumnPositions

func (m *SqlSource) ColumnPositions() map[string]int

Get a list of Column names to position

func (*SqlSource) Finalize

func (m *SqlSource) Finalize() error

func (*SqlSource) FingerPrint

func (m *SqlSource) FingerPrint(r rune) string

func (*SqlSource) JoinNodes

func (m *SqlSource) JoinNodes() []Node

We need to be able to rewrite statements to convert a stmt such as:

		FROM users AS u
			INNER JOIN orders AS o
			ON u.user_id = o.user_id

 So that we can evaluate the Join Key on left/right
    in this case, it is simple, just

   =>   user_id

 or this one:

		FROM users AS u
			INNER JOIN orders AS o
			ON LOWER(u.email) = LOWER(o.email)

   =>  LOWER(user_id)

func (*SqlSource) JoinValueExprOld

func (m *SqlSource) JoinValueExprOld() (Node, error)

func (*SqlSource) Keyword

func (m *SqlSource) Keyword() lex.TokenType

func (*SqlSource) NodeType

func (m *SqlSource) NodeType() NodeType

func (*SqlSource) Rewrite

func (m *SqlSource) Rewrite(parentStmt *SqlSelect) *SqlSelect

Rewrite this Source to act as a stand-alone query to backend

@parentStmt = the parent statement that this a partial source to

func (*SqlSource) SourceName

func (m *SqlSource) SourceName() string

func (*SqlSource) String

func (m *SqlSource) String() string

func (*SqlSource) Type

func (m *SqlSource) Type() reflect.Value

func (*SqlSource) UnAliasedColumns

func (m *SqlSource) UnAliasedColumns() map[string]*Column

Get a list of Un-Aliased Columns, ie columns with column

names that have NOT yet been aliased

type SqlStatement

type SqlStatement interface {
	Node
	Accept(visitor Visitor) (interface{}, error)
	Keyword() lex.TokenType
}

The sqlStatement interface, to define the sql-types

Select, Insert, Delete etc

func ParseSql

func ParseSql(sqlQuery string) (SqlStatement, error)

Parses Tokens and returns an request.

func ParseSqlVm

func ParseSqlVm(sqlQuery string) (SqlStatement, error)

type SqlSubStatement

type SqlSubStatement interface {
	Node
	Accept(visitor SubVisitor) (interface{}, error)
	Keyword() lex.TokenType
}

The sqlStatement interface, to define the subselect/join-types

Join, SubSelect, From

type SqlTokenPager

type SqlTokenPager struct {
	*LexTokenPager
	// contains filtered or unexported fields
}

TokenPager is responsible for determining end of current tree (column, etc)

func NewSqlTokenPager

func NewSqlTokenPager(lex *lex.Lexer) *SqlTokenPager

func (*SqlTokenPager) ClauseEnd

func (m *SqlTokenPager) ClauseEnd() bool

func (*SqlTokenPager) IsEnd

func (m *SqlTokenPager) IsEnd() bool

type SqlUpdate

type SqlUpdate struct {
	Values map[string]*ValueColumn
	Where  Node
	Table  string
}

func NewSqlUpdate

func NewSqlUpdate() *SqlUpdate

func (*SqlUpdate) Accept

func (m *SqlUpdate) Accept(visitor Visitor) (interface{}, error)

func (*SqlUpdate) Check

func (m *SqlUpdate) Check() error

func (*SqlUpdate) FingerPrint

func (m *SqlUpdate) FingerPrint(r rune) string

func (*SqlUpdate) Keyword

func (m *SqlUpdate) Keyword() lex.TokenType

func (*SqlUpdate) NodeType

func (m *SqlUpdate) NodeType() NodeType

func (*SqlUpdate) SqlSelect

func (m *SqlUpdate) SqlSelect() *SqlSelect

func (*SqlUpdate) String

func (m *SqlUpdate) String() string

func (*SqlUpdate) Type

func (m *SqlUpdate) Type() reflect.Value

type SqlUpsert

type SqlUpsert struct {
	Columns Columns
	Rows    [][]*ValueColumn
	Values  map[string]*ValueColumn
	Where   Node
	Table   string
}

func NewSqlUpsert

func NewSqlUpsert() *SqlUpsert

func (*SqlUpsert) Accept

func (m *SqlUpsert) Accept(visitor Visitor) (interface{}, error)

func (*SqlUpsert) Check

func (m *SqlUpsert) Check() error

func (*SqlUpsert) FingerPrint

func (m *SqlUpsert) FingerPrint(r rune) string

func (*SqlUpsert) Keyword

func (m *SqlUpsert) Keyword() lex.TokenType

func (*SqlUpsert) NodeType

func (m *SqlUpsert) NodeType() NodeType

func (*SqlUpsert) SqlSelect

func (m *SqlUpsert) SqlSelect() *SqlSelect

func (*SqlUpsert) String

func (m *SqlUpsert) String() string

func (*SqlUpsert) Type

func (m *SqlUpsert) Type() reflect.Value

type SqlWhere

type SqlWhere struct {
	Op     lex.TokenType // (In|=|ON)  for Select Clauses operators
	Source *SqlSelect    // IN (SELECT a,b,c from z)
	Expr   Node          // x = y
}

WHERE is select stmt, or set of expressions - WHERE x in (select name from q) - WHERE x = y - WHERE x = y AND z = q - WHERE tolower(x) IN (select name from q)

func NewSqlWhere

func NewSqlWhere(where Node) *SqlWhere

func (*SqlWhere) Check

func (m *SqlWhere) Check() error

func (*SqlWhere) FingerPrint

func (m *SqlWhere) FingerPrint(r rune) string

func (*SqlWhere) Keyword

func (m *SqlWhere) Keyword() lex.TokenType

func (*SqlWhere) NodeType

func (m *SqlWhere) NodeType() NodeType

func (*SqlWhere) String

func (m *SqlWhere) String() string

func (*SqlWhere) Type

func (m *SqlWhere) Type() reflect.Value

type Sqlbridge

type Sqlbridge struct {
	*SqlTokenPager
	// contains filtered or unexported fields
}

generic SQL parser evaluates should be sufficient for most

sql compatible languages

type StringNode

type StringNode struct {
	Text string
	// contains filtered or unexported fields
}

StringNode holds a value literal, quotes not included

func NewStringNoQuoteNode

func NewStringNoQuoteNode(text string) *StringNode

func NewStringNode

func NewStringNode(text string) *StringNode

func (*StringNode) Check

func (m *StringNode) Check() error

func (*StringNode) FingerPrint

func (n *StringNode) FingerPrint(r rune) string

func (*StringNode) NodeType

func (m *StringNode) NodeType() NodeType

func (*StringNode) String

func (m *StringNode) String() string

func (*StringNode) Type

func (m *StringNode) Type() reflect.Value

type SubVisitor

type SubVisitor interface {
	VisitSubselect(stmt *SqlSource) (Task, error)
	VisitJoin(stmt *SqlSource) (Task, error)
}

Interface for sub-select Tasks of the Select Statement, joins, sub-selects

type Task

type Task interface {
	Run(ctx *Context) error
	Close() error
}

Task is the interface for execution/plan

type TokenPager

type TokenPager interface {
	Peek() lex.Token
	Next() lex.Token
	Cur() lex.Token
	Last() lex.TokenType
	Backup()
	IsEnd() bool
	ClauseEnd() bool
	Lexer() *lex.Lexer
}

TokenPager wraps a Lexer, and implements the Logic to determine what is the end of this particular clause. Lexer's are stateless, while tokenpager implements state ontop of pager and allows forward/back etc

type Tree

type Tree struct {
	Root       Node // top-level root node of the tree
	TokenPager      // pager for grabbing next tokens, backup(), recognizing end
	// contains filtered or unexported fields
}

Tree is the representation of a single parsed expression

func NewTree

func NewTree(pager TokenPager) *Tree

func ParseExpression

func ParseExpression(expressionText string) (*Tree, error)

Parse a single Expression, returning a Tree

ParseExpression("5 * toint(item_name)")

func (*Tree) A

func (t *Tree) A(depth int) Node

func (*Tree) BuildTree

func (t *Tree) BuildTree(runCheck bool) (err error)

buildTree take the tokens and recursively build into expression tree node @runCheck Do we want to verify this tree? If being used as VM then yes.

func (*Tree) C

func (t *Tree) C(depth int) Node

func (*Tree) F

func (t *Tree) F(depth int) Node

func (*Tree) Func

func (t *Tree) Func(depth int, funcTok lex.Token) (fn *FuncNode)

func (*Tree) M

func (t *Tree) M(depth int) Node

func (*Tree) MultiArg

func (t *Tree) MultiArg(first Node, op lex.Token, depth int) Node

MultiArg parses multi-argument clauses like x IN y.

func (*Tree) O

func (t *Tree) O(depth int) Node

expr:

func (*Tree) P

func (t *Tree) P(depth int) Node

func (*Tree) String

func (t *Tree) String() string

type TriNode

type TriNode struct {
	Args     [3]Node
	Operator lex.Token
}

Tri Node

ARG1 Between ARG2 AND ARG3

func NewTriNode

func NewTriNode(operator lex.Token, arg1, arg2, arg3 Node) *TriNode

Create a Tri node

 @operator = Between
@arg1, @arg2, @arg3

func (*TriNode) Check

func (m *TriNode) Check() error

func (*TriNode) FingerPrint

func (m *TriNode) FingerPrint(r rune) string

func (*TriNode) NodeType

func (m *TriNode) NodeType() NodeType

func (*TriNode) String

func (m *TriNode) String() string

func (*TriNode) Type

func (m *TriNode) Type() reflect.Value

type UnaryNode

type UnaryNode struct {
	Arg      Node
	Operator lex.Token
}

UnaryNode holds one argument and an operator

!eq(5,6)
!true
!(true OR false)
!toint(now())

func NewUnary

func NewUnary(operator lex.Token, arg Node) *UnaryNode

Unary nodes

NOT
EXISTS

func (*UnaryNode) Check

func (n *UnaryNode) Check() error

func (*UnaryNode) FingerPrint

func (m *UnaryNode) FingerPrint(r rune) string

func (*UnaryNode) NodeType

func (m *UnaryNode) NodeType() NodeType

func (*UnaryNode) String

func (m *UnaryNode) String() string

func (*UnaryNode) Type

func (m *UnaryNode) Type() reflect.Value

type ValueColumn

type ValueColumn struct {
	Value value.Value
	Expr  Node
}

List of Value columns in INSERT into TABLE (colnames) VALUES (valuecolumns)

type ValueNode

type ValueNode struct {
	Value value.Value
	// contains filtered or unexported fields
}

Value holds a value.Value type

value.Values can be strings, numbers, arrays, objects, etc

func NewValueNode

func NewValueNode(val value.Value) *ValueNode

func (*ValueNode) Check

func (m *ValueNode) Check() error

func (*ValueNode) FingerPrint

func (n *ValueNode) FingerPrint(r rune) string

func (*ValueNode) NodeType

func (m *ValueNode) NodeType() NodeType

func (*ValueNode) String

func (m *ValueNode) String() string

func (*ValueNode) Type

func (m *ValueNode) Type() reflect.Value

type Visitor

type Visitor interface {
	VisitPreparedStmt(stmt *PreparedStatement) (Task, error)
	VisitSelect(stmt *SqlSelect) (Task, error)
	VisitInsert(stmt *SqlInsert) (Task, error)
	VisitUpsert(stmt *SqlUpsert) (Task, error)
	VisitUpdate(stmt *SqlUpdate) (Task, error)
	VisitDelete(stmt *SqlDelete) (Task, error)
	VisitShow(stmt *SqlShow) (Task, error)
	VisitDescribe(stmt *SqlDescribe) (Task, error)
	VisitCommand(stmt *SqlCommand) (Task, error)
}

Visitor defines the Visit Pattern, so our expr package can

expect implementations from downstream packages
in our case: planner(s), job builder, execution engine

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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