lineage

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

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 IsColumn

func IsColumn(node interface{}) bool

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

func ResolveExprTableColumn(expr tree.Expr) (table string, column string, err error)

func SetExprTableName

func SetExprTableName(expr tree.Expr, tableName string) error

Types

type Action

type Action int8
const (
	// Goon go on as everything is ok.
	Goon Action = iota
	// Stop means return current WalkAST function, stop walking deeper. see NormalizeCtx.nextAction
	// TODO: move stop logic into WalkAST function.
	Stop
	// Continue means stop walking deeper, continue to next node
	Continue
)

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

func (*AstWalker) Walk

func (w *AstWalker) Walk(stmts parser.Statements) (ok bool, err error)

func (*AstWalker) WalkAST

func (w *AstWalker) WalkAST(ni interface{}) (newNode interface{})

type Col

type Col struct {
	// Name is the column name
	Name string
	// Type is the column schema type
	Type string
}

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 ResolveExprFromTables(ctx *NormalizeCtx, inputSchema []Table, from *tree.From, node interface{}) (
	colExpr *ColExpr, err error,
)

func (ColExpr) DebugString

func (c ColExpr) DebugString() string

func (ColExpr) ExprName

func (c ColExpr) ExprName() string

func (ColExpr) String

func (c ColExpr) String() string

type ColExprs

type ColExprs []ColExpr

func GetOutputColumns

func GetOutputColumns(inputSchema Tables, queryExpr *tree.SelectClause) (columns ColExprs)

func GetPhysicalTableColumns

func GetPhysicalTableColumns(inputSchema Tables, table string) (columns ColExprs)

func NormalizeAST

func NormalizeAST(ast tree.Statement, inputSchema Tables) (retAst tree.Statement, inputCols ColExprs, err error)

func (ColExprs) ToList

func (l ColExprs) ToList() []string

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

type ColumnStmt struct {
	Name  string
	Alias string
	Typ   string
}

ColumnStmt is the column referenced in the SQL.

type DataSource

type DataSource interface{}

type ExprType

type ExprType int8
const (
	Unknown ExprType = iota
	Physical
	Logical
)

func (ExprType) String

func (t ExprType) String() string

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

type ReferredCols map[string]int

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:

  1. Table with AS is not normalized.
  2. 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 Schema

type Schema struct {
	Name   string
	Engine string
	Query  string
	//Physical table columns referred in Query
	ReferredColumns map[string]map[string]bool // map[table][column]bool
	Tables          Tables
	TableMap        map[string]*Table `yaml:"-"` // tableName:table
}

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
}

func (TableExpr) String

func (t TableExpr) String() string

type TableExprs

type TableExprs []TableExpr

func (TableExprs) GetTable

func (ts TableExprs) GetTable(tblName string) (*TableExpr, error)

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 Tables

type Tables []Table

func UnmarshalSchema

func UnmarshalSchema(data []byte) (t Tables, err error)

type UserCtx

type UserCtx struct {
	//TableAliasList is `[]*tree.AliasClause`, for removing table alias after normalization.
	TableAliasList *utils.Stack
	TableCols      ColExprs     // table.column referenced in SQL statement
	DeferredFuncs  *utils.Stack // stack of `func() error`
}

type View

type View struct {
	TableView    *TableStmt
	SubqueryView *SubqueryCtx
	NodeRef      interface{} // Node pointer to AST tree node
}

Jump to

Keyboard shortcuts

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