Documentation
¶
Index ¶
- Variables
- func CountFunc(ctx EvalContext, val value.Value) (value.IntValue, bool)
- func FindAllIdentityField(node Node) []string
- func FindIdentityField(node Node) string
- func FindIdentityName(depth int, node Node, prefix string) string
- func FuncAdd(name string, fn interface{})
- func FuncsGet() map[string]Func
- func PowFunc(ctx EvalContext, val, toPower value.Value) (value.NumberValue, bool)
- func SqrtFunc(ctx EvalContext, val value.Value) (value.NumberValue, bool)
- func ValueTypeFromNode(n Node) value.ValueType
- type BinaryNode
- type Column
- type Columns
- func (m *Columns) AliasedFieldNames() []string
- func (m *Columns) ByAs(as string) (*Column, bool)
- func (m *Columns) ByName(name string) (*Column, bool)
- func (m *Columns) FieldNames() []string
- func (m *Columns) FingerPrint(r rune) string
- func (m *Columns) String() string
- func (m *Columns) UnAliasedFieldNames() []string
- type CommandColumn
- type CommandColumns
- type Context
- type ContextReader
- type ContextWriter
- type EvalContext
- type FilterExpr
- type FilterQLParser
- type FilterStatement
- type FilterTokenPager
- type Filters
- type Func
- type FuncNode
- type IdentityNode
- func (m *IdentityNode) Bool() bool
- func (m *IdentityNode) Check() error
- func (m *IdentityNode) FingerPrint(r rune) string
- func (m *IdentityNode) IsBooleanIdentity() bool
- func (m *IdentityNode) LeftRight() (string, string, bool)
- func (m *IdentityNode) NodeType() NodeType
- func (m *IdentityNode) String() string
- func (m *IdentityNode) Type() reflect.Value
- type LexTokenPager
- func (m *LexTokenPager) Backup()
- func (m *LexTokenPager) ClauseEnd() bool
- func (m *LexTokenPager) Cur() lex.Token
- func (m *LexTokenPager) IsEnd() bool
- func (m *LexTokenPager) Last() lex.TokenType
- func (m *LexTokenPager) Lexer() *lex.Lexer
- func (m *LexTokenPager) Next() lex.Token
- func (m *LexTokenPager) Peek() lex.Token
- type MultiArgNode
- type Node
- type NodeType
- type NodeValueType
- type NullNode
- type NumberNode
- type ParsedNode
- type PreparedStatement
- func (m *PreparedStatement) Accept(visitor Visitor) (interface{}, error)
- func (m *PreparedStatement) Check() error
- func (m *PreparedStatement) FingerPrint(r rune) string
- func (m *PreparedStatement) Keyword() lex.TokenType
- func (m *PreparedStatement) NodeType() NodeType
- func (m *PreparedStatement) String() string
- func (m *PreparedStatement) Type() reflect.Value
- type Projection
- type ResultColumn
- type ResultColumns
- type RowWriter
- type SchemaInfo
- type SqlCommand
- func (m *SqlCommand) Accept(visitor Visitor) (interface{}, error)
- func (m *SqlCommand) Check() error
- func (m *SqlCommand) FingerPrint(r rune) string
- func (m *SqlCommand) Keyword() lex.TokenType
- func (m *SqlCommand) NodeType() NodeType
- func (m *SqlCommand) String() string
- func (m *SqlCommand) Type() reflect.Value
- type SqlDelete
- func (m *SqlDelete) Accept(visitor Visitor) (interface{}, error)
- func (m *SqlDelete) Check() error
- func (m *SqlDelete) FingerPrint(r rune) string
- func (m *SqlDelete) Keyword() lex.TokenType
- func (m *SqlDelete) NodeType() NodeType
- func (m *SqlDelete) SqlSelect() *SqlSelect
- func (m *SqlDelete) String() string
- func (m *SqlDelete) Type() reflect.Value
- type SqlDescribe
- func (m *SqlDescribe) Accept(visitor Visitor) (interface{}, error)
- func (m *SqlDescribe) Check() error
- func (m *SqlDescribe) FingerPrint(r rune) string
- func (m *SqlDescribe) Keyword() lex.TokenType
- func (m *SqlDescribe) NodeType() NodeType
- func (m *SqlDescribe) String() string
- func (m *SqlDescribe) Type() reflect.Value
- type SqlInsert
- func (m *SqlInsert) Accept(visitor Visitor) (interface{}, error)
- func (m *SqlInsert) Check() error
- func (m *SqlInsert) ColumnNames() []string
- func (m *SqlInsert) FingerPrint(r rune) string
- func (m *SqlInsert) Keyword() lex.TokenType
- func (m *SqlInsert) NodeType() NodeType
- func (m *SqlInsert) String() string
- func (m *SqlInsert) Type() reflect.Value
- type SqlInto
- type SqlSelect
- func (m *SqlSelect) Accept(visitor Visitor) (interface{}, error)
- func (m *SqlSelect) AddColumn(colArg Column) error
- func (m *SqlSelect) AliasedColumns() map[string]*Column
- func (m *SqlSelect) Check() error
- func (m *SqlSelect) CountStar() bool
- func (m *SqlSelect) Finalize() error
- func (m *SqlSelect) FingerPrint(r rune) string
- func (m *SqlSelect) FingerPrintID() int64
- func (m *SqlSelect) Keyword() lex.TokenType
- func (m *SqlSelect) NodeType() NodeType
- func (m *SqlSelect) Projection(p *Projection) *Projection
- func (m *SqlSelect) Rewrite()
- func (m *SqlSelect) String() string
- func (m *SqlSelect) SysVariable() string
- func (m *SqlSelect) Type() reflect.Value
- func (m *SqlSelect) UnAliasedColumns() map[string]*Column
- type SqlShow
- type SqlSource
- func (m *SqlSource) Accept(visitor SubVisitor) (interface{}, error)
- func (m *SqlSource) BuildColIndex(colNames []string) error
- func (m *SqlSource) Check() error
- func (m *SqlSource) ColumnPositions() map[string]int
- func (m *SqlSource) Finalize() error
- func (m *SqlSource) FingerPrint(r rune) string
- func (m *SqlSource) JoinNodes() []Node
- func (m *SqlSource) JoinValueExprOld() (Node, error)
- func (m *SqlSource) Keyword() lex.TokenType
- func (m *SqlSource) NodeType() NodeType
- func (m *SqlSource) Rewrite(parentStmt *SqlSelect) *SqlSelect
- func (m *SqlSource) SourceName() string
- func (m *SqlSource) String() string
- func (m *SqlSource) Type() reflect.Value
- func (m *SqlSource) UnAliasedColumns() map[string]*Column
- type SqlStatement
- type SqlSubStatement
- type SqlTokenPager
- type SqlUpdate
- func (m *SqlUpdate) Accept(visitor Visitor) (interface{}, error)
- func (m *SqlUpdate) Check() error
- func (m *SqlUpdate) FingerPrint(r rune) string
- func (m *SqlUpdate) Keyword() lex.TokenType
- func (m *SqlUpdate) NodeType() NodeType
- func (m *SqlUpdate) SqlSelect() *SqlSelect
- func (m *SqlUpdate) String() string
- func (m *SqlUpdate) Type() reflect.Value
- type SqlUpsert
- func (m *SqlUpsert) Accept(visitor Visitor) (interface{}, error)
- func (m *SqlUpsert) Check() error
- func (m *SqlUpsert) FingerPrint(r rune) string
- func (m *SqlUpsert) Keyword() lex.TokenType
- func (m *SqlUpsert) NodeType() NodeType
- func (m *SqlUpsert) SqlSelect() *SqlSelect
- func (m *SqlUpsert) String() string
- func (m *SqlUpsert) Type() reflect.Value
- type SqlWhere
- type Sqlbridge
- type StringNode
- type SubVisitor
- type Task
- type TokenPager
- type Tree
- func (t *Tree) A(depth int) Node
- func (t *Tree) BuildTree(runCheck bool) (err error)
- func (t *Tree) C(depth int) Node
- func (t *Tree) F(depth int) Node
- func (t *Tree) Func(depth int, funcTok lex.Token) (fn *FuncNode)
- func (t *Tree) M(depth int) Node
- func (t *Tree) MultiArg(first Node, op lex.Token, depth int) Node
- func (t *Tree) O(depth int) Node
- func (t *Tree) P(depth int) Node
- func (t *Tree) String() string
- type TriNode
- type UnaryNode
- type ValueColumn
- type ValueNode
- type Visitor
Constants ¶
This section is empty.
Variables ¶
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") )
var DefaultDialect *lex.Dialect = lex.LogicalExpressionDialect
We have a default Dialect, which is the "Language" or rule-set of ql
Functions ¶
func FindAllIdentityField ¶
Recursively descend down a node looking for all Identity Fields
min(year) == {year} eq(min(item), max(month)) == {item, month}
func FindIdentityField ¶
Recursively descend down a node looking for first Identity Field
min(year) == year eq(min(item), max(month)) == item
func FindIdentityName ¶
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 PowFunc ¶
func PowFunc(ctx EvalContext, val, toPower value.Value) (value.NumberValue, bool)
Pow
Types ¶
type BinaryNode ¶
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 NewColumnFromToken ¶
func (*Column) CopyRewrite ¶
Create a new copy of this column for rewrite purposes re-alias
func (*Column) FingerPrint ¶
type Columns ¶
type Columns []*Column
List of Columns in SELECT [columns]
func (*Columns) AliasedFieldNames ¶
func (*Columns) FieldNames ¶
func (*Columns) FingerPrint ¶
func (*Columns) UnAliasedFieldNames ¶
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
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 ¶
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 (*FuncNode) FingerPrint ¶
type IdentityNode ¶
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) Peek ¶
func (m *LexTokenPager) Peek() lex.Token
peek returns but does not consume the next token.
type MultiArgNode ¶
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 )
type NodeValueType ¶
Node that has a Type 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 ¶
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 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) ColumnNames ¶
func (*SqlInsert) FingerPrint ¶
func (*SqlInsert) Keyword ¶
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) }
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) AliasedColumns ¶
func (*SqlSelect) Finalize ¶
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 (*SqlSelect) FingerPrintID ¶
func (*SqlSelect) Projection ¶
func (m *SqlSelect) Projection(p *Projection) *Projection
func (*SqlSelect) UnAliasedColumns ¶
type SqlShow ¶
func (*SqlShow) FingerPrint ¶
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 (*SqlSource) Accept ¶
func (m *SqlSource) Accept(visitor SubVisitor) (interface{}, error)
func (*SqlSource) BuildColIndex ¶
func (*SqlSource) ColumnPositions ¶
Get a list of Column names to position
func (*SqlSource) FingerPrint ¶
func (*SqlSource) JoinNodes ¶
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 (*SqlSource) Rewrite ¶
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 (*SqlSource) UnAliasedColumns ¶
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) FingerPrint ¶
type SqlUpsert ¶
type SqlUpsert struct { Columns Columns Rows [][]*ValueColumn Values map[string]*ValueColumn Where Node Table string }
func NewSqlUpsert ¶
func NewSqlUpsert() *SqlUpsert
func (*SqlUpsert) FingerPrint ¶
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 (*SqlWhere) FingerPrint ¶
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 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 ¶
Parse a single Expression, returning a Tree
ParseExpression("5 * toint(item_name)")
func (*Tree) BuildTree ¶
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.
type TriNode ¶
Tri Node
ARG1 Between ARG2 AND ARG3
func (*TriNode) FingerPrint ¶
type UnaryNode ¶
UnaryNode holds one argument and an operator
!eq(5,6) !true !(true OR false) !toint(now())
func (*UnaryNode) FingerPrint ¶
type ValueColumn ¶
List of Value columns in INSERT into TABLE (colnames) VALUES (valuecolumns)
type ValueNode ¶
Value holds a value.Value type
value.Values can be strings, numbers, arrays, objects, etc
func NewValueNode ¶
func (*ValueNode) FingerPrint ¶
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