transform

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2022 License: Apache-2.0 Imports: 3 Imported by: 20

Documentation

Index

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

func Inspect(node sql.Node, f func(sql.Node) bool)

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

func InspectExpressionsWithNode(node sql.Node, f func(sql.Node, sql.Expression) bool)

InspectExpressionsWithNode traverses the plan and calls sql.Inspect on any expression it finds.

func SchemaWithDefaults added in v0.14.0

func SchemaWithDefaults(schema sql.Schema, defaults []sql.Expression) sql.Schema

SchemaWithDefaults returns a copy of the schema given with the defaults provided. Default expressions must be wrapped with expression.Wrapper.

func Walk

func Walk(v Visitor, node sql.Node)

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

func WalkExpressions(v sql.Visitor, node sql.Node)

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

type NodeFunc func(n sql.Node) (sql.Node, TreeIdentity, error)

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

type SelectorFunc func(Context) bool

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

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

ExprWithNode applies a transformation function to the given expression from the bottom up.

func Exprs added in v0.14.0

Exprs applies a transformation function to the given set of expressions and returns the result.

func Node

func Node(node sql.Node, f NodeFunc) (sql.Node, TreeIdentity, error)

Node applies a transformation function to the given tree from the bottom up.

func NodeExprs

func NodeExprs(node sql.Node, f ExprFunc) (sql.Node, TreeIdentity, error)

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

func NodeWithOpaque(node sql.Node, f NodeFunc) (sql.Node, TreeIdentity, error)

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

func OneNodeExpressions(n sql.Node, f ExprFunc) (sql.Node, TreeIdentity, error)

OneNodeExpressions applies a transformation function to all expressions on the given node.

func OneNodeExprsWithNode

func OneNodeExprsWithNode(n sql.Node, f ExprWithNodeFunc) (sql.Node, TreeIdentity, error)

OneNodeExprsWithNode applies a transformation function to all expressions on the given plan tree.

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.

Jump to

Keyboard shortcuts

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