Documentation ¶
Index ¶
- func Clone(expr sql.Expression) (sql.Expression, error)
- func ExpressionToColumn(e sql.Expression) *sql.Column
- func Inspect(node sql.Node, f func(sql.Node) bool)
- func InspectExpr(node sql.Expression, f func(sql.Expression) bool) bool
- func InspectExpressions(node sql.Node, f func(sql.Expression) bool)
- func InspectExpressionsWithNode(node sql.Node, f func(sql.Node, sql.Expression) bool)
- func InspectUp(node sql.Node, f func(sql.Node) bool) bool
- func SchemaWithDefaults(schema sql.Schema, defaults []sql.Expression) sql.Schema
- func Walk(v Visitor, node sql.Node)
- func WalkExpressions(v sql.Visitor, node sql.Node)
- func WalkExpressionsWithNode(v sql.NodeVisitor, n sql.Node)
- func WrappedColumnDefaults(schema sql.Schema) []sql.Expression
- type Context
- type CtxFunc
- type ExprFunc
- type ExprWithNodeFunc
- type NodeFunc
- type SelectorFunc
- type TreeIdentity
- func Expr(e sql.Expression, f ExprFunc) (sql.Expression, TreeIdentity, error)
- func ExprWithNode(n sql.Node, e sql.Expression, f ExprWithNodeFunc) (sql.Expression, TreeIdentity, error)
- func Exprs(e []sql.Expression, f ExprFunc) ([]sql.Expression, TreeIdentity, error)
- func Node(node sql.Node, f NodeFunc) (sql.Node, TreeIdentity, error)
- func NodeChildren(node sql.Node, f NodeFunc) (sql.Node, TreeIdentity, error)
- func NodeExprs(node sql.Node, f ExprFunc) (sql.Node, TreeIdentity, error)
- func NodeExprsWithNode(node sql.Node, f ExprWithNodeFunc) (sql.Node, TreeIdentity, error)
- func NodeExprsWithNodeWithOpaque(node sql.Node, f ExprWithNodeFunc) (sql.Node, TreeIdentity, error)
- func NodeExprsWithOpaque(node sql.Node, f ExprFunc) (sql.Node, TreeIdentity, error)
- func NodeWithCtx(n sql.Node, s SelectorFunc, f CtxFunc) (sql.Node, TreeIdentity, error)
- func NodeWithOpaque(node sql.Node, f NodeFunc) (sql.Node, TreeIdentity, error)
- func NodeWithPrefixSchema(n sql.Node, s SelectorFunc, f CtxFunc) (sql.Node, TreeIdentity, error)
- func OneNodeExpressions(n sql.Node, f ExprFunc) (sql.Node, TreeIdentity, error)
- func OneNodeExprsWithNode(n sql.Node, f ExprWithNodeFunc) (sql.Node, TreeIdentity, error)
- type Visitor
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Clone ¶
func Clone(expr sql.Expression) (sql.Expression, error)
Clone duplicates an existing sql.Expression, returning new nodes with the same structure and internal values. It can be useful when dealing with stateful expression nodes where an evaluation needs to create multiple independent histories of the internal state of the expression nodes.
func ExpressionToColumn ¶
func ExpressionToColumn(e sql.Expression) *sql.Column
ExpressionToColumn converts the expression to the form that should be used in a Schema. Expressions that have Name() and Table() methods will use these; otherwise, String() and "" are used, respectively. The type and nullability are taken from the expression directly.
func Inspect ¶
Inspect traverses the plan in depth-first order: It starts by calling f(node); node must not be nil. If f returns true, Inspect invokes f recursively for each of the children of node, followed by a call of f(nil).
func InspectExpr ¶
func InspectExpr(node sql.Expression, f func(sql.Expression) bool) bool
InspectExpr traverses the given expression tree from the bottom up, breaking if stop = true. Returns a bool indicating whether traversal was interrupted.
func InspectExpressions ¶
func InspectExpressions(node sql.Node, f func(sql.Expression) bool)
InspectExpressions traverses the plan and calls sql.Inspect on any expression it finds.
func InspectExpressionsWithNode ¶
InspectExpressionsWithNode traverses the plan and calls sql.Inspect on any expression it finds.
func InspectUp ¶ added in v0.15.0
InspectUp traverses the given node tree from the bottom up, breaking if stop = true. Returns a bool indicating whether traversal was interrupted.
func SchemaWithDefaults ¶ added in v0.14.0
SchemaWithDefaults returns a copy of the schema given with the defaults provided. Default expressions must be wrapped with expression.Wrapper.
func Walk ¶
Walk traverses the plan tree in depth-first order. It starts by calling v.Visit(node); node must not be nil. If the visitor returned by v.Visit(node) is not nil, Walk is invoked recursively with the returned visitor for each children of the node, followed by a call of v.Visit(nil) to the returned visitor. If v.Visit(node) returns non-nil, then all children are walked, even if one of them returns nil for v.Visit().
func WalkExpressions ¶
WalkExpressions traverses the plan and calls sql.Walk on any expression it finds.
func WalkExpressionsWithNode ¶
func WalkExpressionsWithNode(v sql.NodeVisitor, n sql.Node)
WalkExpressionsWithNode traverses the plan and calls sql.WalkWithNode on any expression it finds.
func WrappedColumnDefaults ¶ added in v0.14.0
func WrappedColumnDefaults(schema sql.Schema) []sql.Expression
WrappedColumnDefaults returns the column defaults for the schema given, wrapped with expression.Wrapper
Types ¶
type Context ¶
type Context struct { // Node is the currently visited node which will be transformed. Node sql.Node // Parent is the current parent of the transforming node. Parent sql.Node // ChildNum is the index of Node in Parent.Children(). ChildNum int // SchemaPrefix is the concatenation of the Parent's SchemaPrefix with // child.Schema() for all child with an index < ChildNum in // Parent.Children(). For many Node, this represents the schema of the // |row| parameter that is going to be passed to this node by its // parent in a RowIter() call. This field is only non-nil if the entire // in-order traversal of the tree up to this point is Resolved(). SchemaPrefix sql.Schema }
Context provides additional metadata to a SelectorFunc about the active node in a traversal, including the parent node, and a partial prefix schema of sibling nodes in a level order traversal.
type CtxFunc ¶
type CtxFunc func(Context) (sql.Node, TreeIdentity, error)
CtxFunc is a function which will return new sql.Node values for a given Context.
type ExprFunc ¶
type ExprFunc func(e sql.Expression) (sql.Expression, TreeIdentity, error)
ExprFunc is a function that given an expression will return that expression as is or transformed, a TreeIdentity to indicate whether the expression was modified, and an error or nil.
type ExprWithNodeFunc ¶
type ExprWithNodeFunc func(sql.Node, sql.Expression) (sql.Expression, TreeIdentity, error)
ExprWithNodeFunc is a function that given an expression and the node that contains it, will return that expression as is or transformed along with an error, if any.
type NodeFunc ¶
NodeFunc is a function that given a node will return that node as is or transformed, a TreeIdentity to indicate whether the node was modified, and an error or nil.
type SelectorFunc ¶
SelectorFunc is a function which will allow NodeWithCtx to not traverse past a certain Context. If this function returns |false| for a given Context, the subtree is not transformed and the child is kept in its existing place in the parent as-is.
type TreeIdentity ¶
type TreeIdentity bool
TreeIdentity tracks modifications to node and expression trees. Only return SameTree when it is acceptable to return the original input and discard the returned result as a performance improvement.
const ( SameTree TreeIdentity = true NewTree TreeIdentity = false )
func Expr ¶
func Expr(e sql.Expression, f ExprFunc) (sql.Expression, TreeIdentity, error)
Expr applies a transformation function to the given expression tree from the bottom up. Each callback [f] returns a TreeIdentity that is aggregated into a final output indicating whether the expression tree was changed.
func ExprWithNode ¶
func ExprWithNode(n sql.Node, e sql.Expression, f ExprWithNodeFunc) (sql.Expression, TreeIdentity, error)
ExprWithNode applies a transformation function to the given expression from the bottom up.
func Exprs ¶ added in v0.14.0
func Exprs(e []sql.Expression, f ExprFunc) ([]sql.Expression, TreeIdentity, error)
Exprs applies a transformation function to the given set of expressions and returns the result.
func NodeChildren ¶ added in v0.15.0
NodeChildren applies a transformation function to the given node's children.
func NodeExprs ¶
NodeExprs applies a transformation function to all expressions on the given plan tree from the bottom up.
func NodeExprsWithNode ¶
func NodeExprsWithNode(node sql.Node, f ExprWithNodeFunc) (sql.Node, TreeIdentity, error)
NodeExprsWithNode applies a transformation function to all expressions on the given tree from the bottom up.
func NodeExprsWithNodeWithOpaque ¶ added in v0.15.0
func NodeExprsWithNodeWithOpaque(node sql.Node, f ExprWithNodeFunc) (sql.Node, TreeIdentity, error)
NodeExprsWithNodeWithOpaque applies a transformation function to all expressions on the given tree from the bottom up, including through opaque nodes.
func NodeExprsWithOpaque ¶ added in v0.15.0
NodeExprsWithOpaque applies a transformation function to all expressions on the given plan tree from the bottom up, including through opaque nodes.
func NodeWithCtx ¶
func NodeWithCtx(n sql.Node, s SelectorFunc, f CtxFunc) (sql.Node, TreeIdentity, error)
NodeWithCtx transforms |n| from the bottom up, left to right, by passing each node to |f|. If |s| is non-nil, does not descend into children where |s| returns false.
func NodeWithOpaque ¶
NodeWithOpaque applies a transformation function to the given tree from the bottom up, including through opaque nodes. This method is generally not safe to use for a transformation. Opaque nodes need to be considered in isolation except for very specific exceptions.
func NodeWithPrefixSchema ¶
func NodeWithPrefixSchema(n sql.Node, s SelectorFunc, f CtxFunc) (sql.Node, TreeIdentity, error)
NodeWithPrefixSchema transforms |n| from the bottom up, left to right, by passing each node to |f|. If |s| is non-nil, does not descend into children where |s| returns false.
func OneNodeExpressions ¶
OneNodeExpressions applies a transformation function to all expressions on the specified node. It does not traverse the children of the specified node.
func OneNodeExprsWithNode ¶
func OneNodeExprsWithNode(n sql.Node, f ExprWithNodeFunc) (sql.Node, TreeIdentity, error)
OneNodeExprsWithNode applies a transformation function to all expressions on the specified node. It does not traverse the children of the specified node.
type Visitor ¶
type Visitor interface { // Visit method is invoked for each node encountered by Walk. // If the result Visitor is not nil, Walk visits each of the children // of the node with that visitor, followed by a call of Visit(nil) // to the returned visitor. Visit(node sql.Node) Visitor }
Visitor visits nodes in the plan.