rewrite

package
v0.18.3 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DebugOperatorTree = false

Functions

func BottomUp

func BottomUp(
	root ops.Operator,
	resolveID func(ops.Operator) semantics.TableSet,
	visit VisitF,
	shouldVisit ShouldVisit,
) (ops.Operator, error)

BottomUp rewrites an operator tree from the bottom up. BottomUp applies a transformation function to the given operator tree from the bottom up. Each callback [f] returns a ApplyResult that is aggregated into a final output indicating whether the operator tree was changed.

func BottomUpAll added in v0.17.0

func BottomUpAll(
	root ops.Operator,
	resolveID func(ops.Operator) semantics.TableSet,
	visit VisitF,
) (ops.Operator, error)

BottomUpAll rewrites an operator tree from the bottom up. BottomUp applies a transformation function to the given operator tree from the bottom up. Each callback [f] returns a ApplyResult that is aggregated into a final output indicating whether the operator tree was changed.

func EnableDebugPrinting added in v0.18.0

func EnableDebugPrinting() (reset func())

func FixedPointBottomUp added in v0.17.0

func FixedPointBottomUp(
	root ops.Operator,
	resolveID func(ops.Operator) semantics.TableSet,
	visit VisitF,
	shouldVisit ShouldVisit,
) (op ops.Operator, err error)

FixedPointBottomUp rewrites an operator tree much like BottomUp does, but does the rewriting repeatedly, until a tree walk is done with no changes to the tree.

func TopDown

func TopDown(
	root ops.Operator,
	resolveID func(ops.Operator) semantics.TableSet,
	visit VisitF,
	shouldVisit ShouldVisit,
) (op ops.Operator, err error)

TopDown rewrites an operator tree from the bottom up. BottomUp applies a transformation function to the given operator tree from the bottom up. Each callback [f] returns a ApplyResult that is aggregated into a final output indicating whether the operator tree was changed.

Parameters: - root: The root operator of the tree to be traversed. - resolveID: A function to resolve the TableSet of an operator. - visit: The VisitF function to be called for each visited operator. - shouldVisit: The ShouldVisit function to control which nodes and ancestors to visit and which to skip.

Returns: - ops.Operator: The root of the (potentially) transformed operator tree. - error: An error if any occurred during the traversal.

func Visit

func Visit(root ops.Operator, visitor func(ops.Operator) error) error

Visit allows for the walking of the operator tree. If any error is returned, the walk is aborted

Types

type ApplyResult added in v0.17.0

type ApplyResult struct {
	Transformations []Rewrite
}

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

var (
	SameTree *ApplyResult = nil
)

func NewTree

func NewTree(message string, op ops.Operator) *ApplyResult

func Swap added in v0.17.0

func Swap(parent, child ops.Operator, message string) (ops.Operator, *ApplyResult, error)

Swap takes a tree like a->b->c and swaps `a` and `b`, so we end up with b->a->c

func (*ApplyResult) Changed added in v0.17.0

func (ar *ApplyResult) Changed() bool

func (*ApplyResult) Merge added in v0.17.0

func (ar *ApplyResult) Merge(other *ApplyResult) *ApplyResult

type Rewrite added in v0.17.0

type Rewrite struct {
	Message string
	Op      ops.Operator
}

type ShouldVisit added in v0.17.0

type ShouldVisit func(ops.Operator) VisitRule

ShouldVisit is used when we want to control which nodes and ancestors to visit and which to skip

type VisitF added in v0.17.0

type VisitF func(
	op ops.Operator,
	lhsTables semantics.TableSet,
	isRoot bool,
) (ops.Operator, *ApplyResult, error)

VisitF is the visitor that walks an operator tree

type VisitRule

type VisitRule bool

VisitRule signals to the rewriter if the children of this operator should be visited or not

const (
	VisitChildren VisitRule = true
	SkipChildren  VisitRule = false
)

Jump to

Keyboard shortcuts

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