Documentation
¶
Index ¶
- func AllColsContained(set ReferredCols, cols []string) bool
- func GetInputColumns(inputSchema Tables, subqueryOrTables ...interface{}) (columns ColExprs, tables TableExprs)
- func GetTabColsMap(inputCols ColExprs, logicalColIncluded bool, unresolvedColIncluded bool) map[string]map[string]bool
- func IsColumn(node interface{}) bool
- func NormalizeColumnName(expr tree.Expr, treeRange interface{}, inputPhysicalSchema []Table, ...) (tableName string, columnName string, err error)
- func ResolveExprTableColumn(expr tree.Expr) (table string, column string, err error)
- func SetExprTableName(expr tree.Expr, tableName string) error
- type Action
- type AstWalker
- type Col
- type ColExpr
- type ColExprs
- type ColumnName
- type ColumnStmt
- type DataSource
- type ExprType
- type GetProvidedCtx
- type NormalizeCtx
- type QueryCtx
- type ReferredCols
- type Schema
- type SubqueryCtx
- type Table
- type TableExpr
- type TableExprs
- type TableStmt
- type Tables
- type UserCtx
- type View
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AllColsContained ¶
func AllColsContained(set ReferredCols, cols []string) bool
func GetInputColumns ¶
func GetInputColumns(inputSchema Tables, subqueryOrTables ...interface{}) (columns ColExprs, tables TableExprs)
GetInputColumns returns a list of output columns of the subqueries or tables. Every table will also have a ColExpr with Name == "" for get output tables easily.
func GetTabColsMap ¶
func GetTabColsMap(inputCols ColExprs, logicalColIncluded bool, unresolvedColIncluded bool) map[string]map[string]bool
GetTabColsMap gets physical table columns referred in Query and returns a map[table][column]isPhysicalColumn
func NormalizeColumnName ¶
func NormalizeColumnName( expr tree.Expr, treeRange interface{}, inputPhysicalSchema []Table, stack *utils.Stack, userCtx *UserCtx, ) (tableName string, columnName string, err error)
NormalizeColumnName will try to get the deterministic table name and column name `expr` is searched in the `treeRange` with the input table schema `tables`.
func ResolveExprTableColumn ¶
Types ¶
type AstWalker ¶
type AstWalker struct {
NodeCount []int
UnknownNodes []interface{}
NodeStack *utils.Stack
Ctx interface{}
// Fn the function to be called when the walk.
//when newNode is not nil and action is Continue, AstWalker.Walk will stop walk deeper and return which will cause
//the AST node replaced by the newNode.
Fn func(ctx interface{}, node interface{}) (newNode interface{}, action Action)
}
type ColExpr ¶
type ColExpr struct {
Name string
SrcTable []string // length == 1 means source table is deterministic, else all elements are possible.
Scope *utils.Stack
// ColType is the type of column
// Physical column is a column in input physical table, otherwise it can be
// *tree.FuncExpr, *tree.CoalesceExpr, *tree.CaseExpr
ColType ExprType
}
ColExpr is a source identified column expression. TODO: introduce a ColExpr interface type, maybe.
func ResolveExprFromTables ¶
func (ColExpr) DebugString ¶
type ColExprs ¶
type ColExprs []ColExpr
func GetOutputColumns ¶
func GetOutputColumns(inputSchema Tables, queryExpr *tree.SelectClause) (columns ColExprs)
func GetPhysicalTableColumns ¶
func NormalizeAST ¶
type ColumnName ¶
type ColumnName string
func NewColumnName ¶
func NewColumnName(table string, column string) ColumnName
func (ColumnName) ColName ¶
func (c ColumnName) ColName() string
func (ColumnName) TabName ¶
func (c ColumnName) TabName() string
type ColumnStmt ¶
ColumnStmt is the column referenced in the SQL.
type DataSource ¶
type DataSource interface{}
type GetProvidedCtx ¶
type GetProvidedCtx struct {
Err error
}
type NormalizeCtx ¶
type NormalizeCtx struct {
UserCtx *UserCtx
Walker *AstWalker
Err error
// contains filtered or unexported fields
}
func (*NormalizeCtx) BackTraceSubQueryFromTables ¶
func (ctx *NormalizeCtx) BackTraceSubQueryFromTables() (subRange *tree.From, newStack *utils.Stack)
func (*NormalizeCtx) BackTraceSubQueryNewStack ¶
func (ctx *NormalizeCtx) BackTraceSubQueryNewStack() (subRange interface{}, newStack *utils.Stack)
type QueryCtx ¶
type QueryCtx struct {
Contexts []SubqueryCtx
Err error
// contains filtered or unexported fields
}
func FindAlias ¶
func FindAlias(stmts parser.Statements, inputSchema *Schema) (ctx *QueryCtx, err error)
FindAlias collects all tables and columns alias, the walker function will keep a subquery level context. As a result, this func is NOT CONCURRENT SAFE.
func (*QueryCtx) CurSubContext ¶
func (qc *QueryCtx) CurSubContext() *SubqueryCtx
func (*QueryCtx) NewSubContext ¶
func (qc *QueryCtx) NewSubContext() *SubqueryCtx
type ReferredCols ¶
func ColNamesInSelect ¶
func ColNamesInSelect(sql string) (referredCols ReferredCols, err error)
ColNamesInSelect finds all referred variables in a Select Statement. (variables = sub-expressions, placeholders, indexed vars, etc.) Implementation limits:
- Table with AS is not normalized.
- Columns referred from outer query are not translated.
func FullColNamesInSelect
deprecated
func FullColNamesInSelect(sql string) (referredCols ReferredCols, err error)
FullColNamesInSelect is not fully accurate.
Deprecated: see function NormalizeAST usage in TestNormalizeASTWithoutInputSchema
func (ReferredCols) ToList ¶
func (rc ReferredCols) ToList() []string
type SubqueryCtx ¶
type SubqueryCtx struct {
//Node tree.
// Projections are the query output schema
Projections []tree.SelectExpr
// From contains the input table schema and subquery schema
// we call these two types View
From []View
// Alias is the subquery alias name
Alias string
}
type Table ¶
type Table struct {
Name string
// Pk is the primary key name.
Pk string
// Cols are the columns in the Table
Cols []Col
// Index is the column names array to build an index
Index []string
}
Table is the description of table in ngnx.
type TableExpr ¶
type TableExpr struct {
Name string
AliasTo string
AliasClause *tree.AliasClause
TableType ExprType
}
type TableExprs ¶
type TableExprs []TableExpr
type TableStmt ¶
type TableStmt struct {
Name tree.NameParts
Columns map[string]ColumnStmt // map[ColumnName or AliasName]ColumnStmt
Alias string
}
TableStmt is the table referenced in the SQL.
type View ¶
type View struct {
TableView *TableStmt
SubqueryView *SubqueryCtx
NodeRef interface{} // Node pointer to AST tree node
}