tools

package
v0.0.0-debug-20260702 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertFunc

func AssertFunc(b bool, errInfo string)

func AssertPlan

func AssertPlan(ctx context.Context, sql string, pattern *MatchPattern) error

func Insert

func Insert(ctx context.Context, aliases UnorderedMap[string, string], k, v string) error

func MergeAliases

func MergeAliases(ctx context.Context,
	aliases1, aliases2 UnorderedMap[string, string]) error

func SimpleMatchMatchers

func SimpleMatchMatchers(pattern *MatchPattern, node *plan2.Node) bool

func StringsEqual

func StringsEqual(a, b []string) bool

func VarRefsEqual

func VarRefsEqual(a, b []VarRef) bool

Types

type AggrFuncMatcher

type AggrFuncMatcher struct {
	Aggr    tree.Expr
	AggrStr string
}

func NewAggrFuncMatcher

func NewAggrFuncMatcher(s string) *AggrFuncMatcher

func (*AggrFuncMatcher) GetAssignedVar

func (matcher *AggrFuncMatcher) GetAssignedVar(node *plan2.Node, aliases UnorderedMap[string, string]) (*VarRef, error)

func (*AggrFuncMatcher) String

func (matcher *AggrFuncMatcher) String() string

type AggrPair

type AggrPair Pair[string, *AggrFuncMatcher]

func NewAggrPair

func NewAggrPair(k string, v *AggrFuncMatcher) AggrPair

type AliasMatcher

type AliasMatcher struct {
	Alias   string
	Matcher RValueMatcher
}

func (*AliasMatcher) DeepMatch

func (matcher *AliasMatcher) DeepMatch(ctx context.Context, node *plan.Node, aliases UnorderedMap[string, string]) (*MatchResult, error)

func (*AliasMatcher) SimpleMatch

func (matcher *AliasMatcher) SimpleMatch(node *plan.Node) bool

func (*AliasMatcher) String

func (matcher *AliasMatcher) String() string

type AssertConfig

type AssertConfig struct {
}

type AssignPair

type AssignPair Pair[string, *ExprMatcher]

func NewAssignPair

func NewAssignPair(k string, v *ExprMatcher) AssignPair

type AssignedSymbolsMatcher

type AssignedSymbolsMatcher struct {
	GetFunc          GetFunc
	ExpectedMatchers []RValueMatcher
}

func (*AssignedSymbolsMatcher) DeepMatch

func (matcher *AssignedSymbolsMatcher) DeepMatch(ctx context.Context, node *plan.Node, aliases UnorderedMap[string, string]) (*MatchResult, error)

func (*AssignedSymbolsMatcher) SimpleMatch

func (matcher *AssignedSymbolsMatcher) SimpleMatch(node *plan.Node) bool

func (*AssignedSymbolsMatcher) String

func (matcher *AssignedSymbolsMatcher) String() string

type ColumnRef

type ColumnRef struct {
	TableName  string
	ColumnName string
}

func (*ColumnRef) GetAssignedVar

func (matcher *ColumnRef) GetAssignedVar(node *plan2.Node, aliases UnorderedMap[string, string]) (*VarRef, error)

func (*ColumnRef) String

func (matcher *ColumnRef) String() string

type Domain

type Domain struct {
}

type ExprChecker

type ExprChecker struct {
	Aliases UnorderedMap[string, string]
}

func (*ExprChecker) Check

func (checker *ExprChecker) Check(astExpr tree.Expr, expr *plan2.Expr) (bool, error)

type ExprMatcher

type ExprMatcher struct {
	Sql  string
	Expr tree.Expr
}

func NewExprMatcher

func NewExprMatcher(sql string) *ExprMatcher

func TExpr

func TExpr(e string) *ExprMatcher

func (*ExprMatcher) GetAssignedVar

func (matcher *ExprMatcher) GetAssignedVar(node *plan2.Node, aliases UnorderedMap[string, string]) (*VarRef, error)

func (*ExprMatcher) String

func (matcher *ExprMatcher) String() string

type GetFunc

type GetFunc func(*plan.QueryBuilder, *plan2.Node) []VarRef

type JoinMatcher

type JoinMatcher struct {
	JoinTyp    plan2.Node_JoinType
	OnCondsStr []string
	OnConds    []tree.Expr
	FiltersStr []string
	Filters    []tree.Expr
}

func NewJoinMatcher

func NewJoinMatcher(joinType plan2.Node_JoinType, conds []string, filters []string) *JoinMatcher

func (*JoinMatcher) DeepMatch

func (matcher *JoinMatcher) DeepMatch(ctx context.Context, node *plan2.Node, aliases UnorderedMap[string, string]) (*MatchResult, error)

func (*JoinMatcher) SimpleMatch

func (matcher *JoinMatcher) SimpleMatch(node *plan2.Node) bool

func (*JoinMatcher) String

func (matcher *JoinMatcher) String() string

type MatchPattern

type MatchPattern struct {
	Matchers []Matcher       //matchers for components in Node
	Children []*MatchPattern // children pattern of children nodes
	AnyTree  bool
}

MatchPattern denotes the structure pattern that the Plan should have.

func TAggr

func TAggr(aggrs UnorderedMap[string, *AggrFuncMatcher], children ...*MatchPattern) *MatchPattern

func TAny

func TAny(children ...*MatchPattern) *MatchPattern

TAny yields a pattern without designated node type

func TAnyNot

func TAnyNot(nodeType plan2.Node_NodeType, children ...*MatchPattern) *MatchPattern

func TAnyTree

func TAnyTree(children ...*MatchPattern) *MatchPattern

TAnyTree denotes children tree matches the patterns

func TJoin

func TJoin(joinTyp plan2.Node_JoinType,
	onConds []string,
	filters []string,
	left, right *MatchPattern) *MatchPattern

func TNode

func TNode(nodeType plan2.Node_NodeType, children ...*MatchPattern) *MatchPattern

func TOutput

func TOutput(outputs []string, child *MatchPattern) *MatchPattern

func TOutputWithoutOutputs

func TOutputWithoutOutputs(child *MatchPattern) *MatchPattern

func TProject

func TProject(assigns UnorderedMap[string, *ExprMatcher], child *MatchPattern) *MatchPattern

func TProjectWithoutAssignments

func TProjectWithoutAssignments(child *MatchPattern) *MatchPattern

func TStrictOutput

func TStrictOutput(outputs []string, child *MatchPattern) *MatchPattern

func TStrictProject

func TStrictProject(assigns UnorderedMap[string, *ExprMatcher], child *MatchPattern) *MatchPattern

func TStrictTableScan

func TStrictTableScan(tableName string, colRefs UnorderedMap[string, string]) *MatchPattern

func TTableScan

func TTableScan(tableName string, colRefs UnorderedMap[string, string]) *MatchPattern

func TTableScanWithoutColRef

func TTableScanWithoutColRef(tableName string) *MatchPattern

func (*MatchPattern) AddColRefs

func (pattern *MatchPattern) AddColRefs(name string, refs UnorderedMap[string, string]) *MatchPattern

func (*MatchPattern) IsEnd

func (pattern *MatchPattern) IsEnd() bool

func (*MatchPattern) MatchAnyTree

func (pattern *MatchPattern) MatchAnyTree() *MatchPattern

func (*MatchPattern) String

func (pattern *MatchPattern) String() string

func (*MatchPattern) With

func (pattern *MatchPattern) With(matcher Matcher) *MatchPattern

func (*MatchPattern) WithAlias

func (pattern *MatchPattern) WithAlias(alias string, matcher RValueMatcher) *MatchPattern

func (*MatchPattern) WithExactAssignedOutputs

func (pattern *MatchPattern) WithExactAssignedOutputs(expectedAliases []RValueMatcher) *MatchPattern

func (*MatchPattern) WithExactAssignments

func (pattern *MatchPattern) WithExactAssignments(expectedAliases []RValueMatcher) *MatchPattern

func (*MatchPattern) WithExactOutputs

func (pattern *MatchPattern) WithExactOutputs(outputs ...string) *MatchPattern

func (*MatchPattern) WithOutputs

func (pattern *MatchPattern) WithOutputs(aliases ...string) *MatchPattern

type MatchResult

type MatchResult struct {
	IsMatch    bool
	RetAliases UnorderedMap[string, string]
}

func DeepMatch

func DeepMatch(
	ctx context.Context,
	node *plan2.Node,
	pattern *MatchPattern,
	aliases UnorderedMap[string, string]) (*MatchResult, error)

func FailMatched

func FailMatched() *MatchResult

func Match

func Match(ctx context.Context, nodes []*plan2.Node, node *plan2.Node, pattern *MatchPattern) (*MatchResult, error)

func MatchChildren

func MatchChildren(ctx context.Context,
	nodes []*plan2.Node,
	node *plan2.Node,
	state *MatchingState) (*MatchResult, error)

func MatchLeaf

func MatchLeaf(ctx context.Context,
	node *plan2.Node,
	pattern *MatchPattern,
	states []*MatchingState) (*MatchResult, error)

func MatchSteps

func MatchSteps(ctx context.Context, query *plan2.Query, pattern *MatchPattern) (*MatchResult, error)

func Matched

func Matched() *MatchResult

func MatchedWithAlias

func MatchedWithAlias(alias, ref string) *MatchResult

func MatchedWithAliases

func MatchedWithAliases(aliases UnorderedMap[string, string]) *MatchResult

func NewMatchResult

func NewMatchResult(isMatch bool, retAliases UnorderedMap[string, string]) *MatchResult

func (*MatchResult) String

func (mr *MatchResult) String() string

type Matcher

type Matcher interface {
	// SimpleMatch check the intuitive properties about Node like type, datatype, etc.
	SimpleMatch(*plan2.Node) bool

	// DeepMatch check the internal structure about Node
	DeepMatch(context.Context, *plan2.Node, UnorderedMap[string, string]) (*MatchResult, error)

	String() string
}

type MatchingState

type MatchingState struct {
	Patterns []*MatchPattern
}

func SimpleMatch

func SimpleMatch(pattern *MatchPattern, node *plan2.Node) []*MatchingState

func (*MatchingState) IsEnd

func (state *MatchingState) IsEnd() bool

type NodeMatcher

type NodeMatcher struct {
	NodeType plan2.Node_NodeType
	Not      bool
}

func (*NodeMatcher) DeepMatch

func (matcher *NodeMatcher) DeepMatch(ctx context.Context, node *plan.Node, aliases UnorderedMap[string, string]) (*MatchResult, error)

func (*NodeMatcher) SimpleMatch

func (matcher *NodeMatcher) SimpleMatch(node *plan2.Node) bool

func (*NodeMatcher) String

func (matcher *NodeMatcher) String() string

type OutputMatcher

type OutputMatcher struct {
	Aliases []string
}

func (*OutputMatcher) DeepMatch

func (matcher *OutputMatcher) DeepMatch(ctx context.Context, node *plan.Node, aliases UnorderedMap[string, string]) (*MatchResult, error)

func (*OutputMatcher) SimpleMatch

func (matcher *OutputMatcher) SimpleMatch(node *plan.Node) bool

func (*OutputMatcher) String

func (matcher *OutputMatcher) String() string

type Pair

type Pair[KT, VT any] struct {
	Key   KT
	Value VT
}

func NewPair

func NewPair[KT, VT any](k KT, v VT) Pair[KT, VT]

type RValueMatcher

type RValueMatcher interface {
	GetAssignedVar(*plan2.Node, UnorderedMap[string, string]) (*VarRef, error)
	String() string
}

func TColumnRef

func TColumnRef(tableName, colName string) RValueMatcher

type StringPair

type StringPair Pair[string, string]

func NewStringPair

func NewStringPair(k, v string) StringPair

type SymbolsMatcher

type SymbolsMatcher struct {
	GetFunc         GetFunc
	ExpectedAliases []string
}

func (*SymbolsMatcher) DeepMatch

func (matcher *SymbolsMatcher) DeepMatch(ctx context.Context, node *plan.Node, aliases UnorderedMap[string, string]) (*MatchResult, error)

func (*SymbolsMatcher) SimpleMatch

func (matcher *SymbolsMatcher) SimpleMatch(node *plan.Node) bool

func (*SymbolsMatcher) String

func (matcher *SymbolsMatcher) String() string

type TableScanMatcher

type TableScanMatcher struct {
	TableName  string
	Constraint UnorderedMap[string, *Domain]
}

func (*TableScanMatcher) DeepMatch

func (matcher *TableScanMatcher) DeepMatch(ctx context.Context, node *plan.Node, aliases UnorderedMap[string, string]) (*MatchResult, error)

func (*TableScanMatcher) SimpleMatch

func (matcher *TableScanMatcher) SimpleMatch(node *plan.Node) bool

func (*TableScanMatcher) String

func (matcher *TableScanMatcher) String() string

type UnorderedMap

type UnorderedMap[KT ~string | ~int, VT any] map[KT]VT

func MergeAliasesReturnNew

func MergeAliasesReturnNew(ctx context.Context,
	aliases1, aliases2 UnorderedMap[string, string]) (UnorderedMap[string, string], error)

func NewAggrMap

func NewAggrMap(pairs ...AggrPair) UnorderedMap[string, *AggrFuncMatcher]

func NewAssignMap

func NewAssignMap(pairs ...AssignPair) UnorderedMap[string, *ExprMatcher]

func NewStringMap

func NewStringMap(pairs ...StringPair) UnorderedMap[string, string]

func (UnorderedMap[KT, VT]) Count

func (umap UnorderedMap[KT, VT]) Count(k KT) int

func (UnorderedMap[KT, VT]) Find

func (umap UnorderedMap[KT, VT]) Find(k KT) (ok bool, v VT)

func (UnorderedMap[KT, VT]) Insert

func (umap UnorderedMap[KT, VT]) Insert(k KT, v VT)

func (UnorderedMap[KT, VT]) Size

func (umap UnorderedMap[KT, VT]) Size() int

type ValuesMatcher

type ValuesMatcher struct {
}

type VarRef

type VarRef struct {
	Name string
	Type plan2.Type
}

Jump to

Keyboard shortcuts

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