plantest

package
v0.58.1-0...-af594cf Latest Latest
Warning

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

Go to latest
Published: May 1, 2020 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package plantest contains utilities for testing each query planning phase

Index

Constants

View Source
const MockKind = "mock"

Variables

CmpOptions are the options needed to compare plan.ProcedureSpecs inside plan.Spec.

Functions

func CompareLogicalPlanNodes

func CompareLogicalPlanNodes(p, q plan.Node) error

CompareLogicalPlanNodes is a comparator function for LogicalPlanNodes

func CompareLogicalPlans

func CompareLogicalPlans(p, q *plan.Spec) error

CompareLogicalPlans compares two logical plans.

func ComparePhysicalPlanNodes

func ComparePhysicalPlanNodes(p, q plan.Node) error

ComparePhysicalPlanNodes is a comparator function for PhysicalPlanNodes

func ComparePlans

func ComparePlans(p, q *plan.Spec, f func(p, q plan.Node) error) error

ComparePlans compares two query plans using an arbitrary comparator function f

func ComparePlansShallow

func ComparePlansShallow(p, q *plan.Spec) error

ComparePlansShallow Compares the two specs, but only compares the metadata and the types of each node. Individual fields of procedure specs are not compared.

func CreateLogicalMockNode

func CreateLogicalMockNode(id string) *plan.LogicalNode

CreateLogicalMockNode creates a mock plan node that doesn't match any rules (other than rules that match any node)

func CreatePhysicalMockNode

func CreatePhysicalMockNode(id string) *plan.PhysicalPlanNode

CreatePhysicalMockNode creates a mock plan node that doesn't match any rules (other than rules that match any node)

func CreatePlanSpec

func CreatePlanSpec(spec *PlanSpec) *plan.Spec

CreatePlanSpec creates a logical plan from a set of nodes and edges

func LogicalRuleTestHelper

func LogicalRuleTestHelper(t *testing.T, tc *RuleTestCase)

LogicalRuleTestHelper will run a rule test case.

func PhysicalRuleTestHelper

func PhysicalRuleTestHelper(t *testing.T, tc *RuleTestCase)

PhysicalRuleTestHelper will run a rule test case.

Types

type CreateCycleRule

type CreateCycleRule struct {
	Node plan.Node
	Kind plan.ProcedureKind
}

CreateCycleRule creates a cycle between the given `Node` and its predecessor. It creates exactly one cycle. After the rule is triggered once, it won't have any effect later. This rule breaks the integrity of the plan. If `Kind` is specified, it takes precedence over `Node`, and the rule will use it to match.

func (CreateCycleRule) Name

func (CreateCycleRule) Name() string

func (CreateCycleRule) Pattern

func (ccr CreateCycleRule) Pattern() plan.Pattern

func (CreateCycleRule) Rewrite

func (ccr CreateCycleRule) Rewrite(ctx context.Context, node plan.Node) (plan.Node, bool, error)

type FunctionRule

type FunctionRule struct {
	RewriteFn func(ctx context.Context, node plan.Node) (plan.Node, bool, error)
}

FunctionRule is a simple rule intended to invoke a Rewrite function.

func (*FunctionRule) Name

func (fr *FunctionRule) Name() string

func (*FunctionRule) Pattern

func (fr *FunctionRule) Pattern() plan.Pattern

func (*FunctionRule) Rewrite

func (fr *FunctionRule) Rewrite(ctx context.Context, node plan.Node) (plan.Node, bool, error)

type MockProcedureSpec

type MockProcedureSpec struct {
	plan.DefaultCost
}

MockProcedureSpec provides a type that implements ProcedureSpec but does not require importing packages which register rules and procedure kinds, which makes it useful for unit testing.

func (MockProcedureSpec) Copy

func (MockProcedureSpec) Kind

type MultiRootRule

type MultiRootRule struct {
	SeenNodes []plan.NodeID
}

MultiRoot matches a set of plan nodes at the root and stores the NodeIDs of nodes it has visited in SeenNodes.

func (*MultiRootRule) Name

func (sr *MultiRootRule) Name() string

func (*MultiRootRule) Pattern

func (sr *MultiRootRule) Pattern() plan.Pattern

func (*MultiRootRule) Rewrite

func (sr *MultiRootRule) Rewrite(ctx context.Context, node plan.Node) (plan.Node, bool, error)

type PlanSpec

type PlanSpec struct {
	Nodes []plan.Node

	// Edges is a list of predecessor-to-successor edges.
	// [1, 3] => Nodes[1] is a predecessor of Nodes[3].
	// Predecessor ordering must be encoded in this list.
	Edges [][2]int

	Resources flux.ResourceManagement

	Now time.Time
}

Spec is a set of nodes and edges of a logical query plan

func (*PlanSpec) Copy

func (ps *PlanSpec) Copy() *PlanSpec

Copy makes a copy of a Spec.

type RuleTestCase

type RuleTestCase struct {
	Name          string
	Rules         []plan.Rule
	Before        *PlanSpec
	After         *PlanSpec
	NoChange      bool
	ValidateError error
}

RuleTestCase allows for concise creation of test cases that exercise rules

type SimpleRule

type SimpleRule struct {
	SeenNodes []plan.NodeID
}

SimpleRule is a simple rule whose pattern matches any plan node and just stores the NodeIDs of nodes it has visited in SeenNodes.

func (*SimpleRule) Name

func (sr *SimpleRule) Name() string

func (*SimpleRule) Pattern

func (sr *SimpleRule) Pattern() plan.Pattern

func (*SimpleRule) Rewrite

func (sr *SimpleRule) Rewrite(ctx context.Context, node plan.Node) (plan.Node, bool, error)

type SmashPlanRule

type SmashPlanRule struct {
	Node     plan.Node
	Intruder plan.Node
	Kind     plan.ProcedureKind
}

SmashPlanRule adds an `Intruder` as predecessor of the given `Node` without marking it as successor of it. It breaks the integrity of the plan. If `Kind` is specified, it takes precedence over `Node`, and the rule will use it to match.

func (SmashPlanRule) Name

func (SmashPlanRule) Name() string

func (SmashPlanRule) Pattern

func (spp SmashPlanRule) Pattern() plan.Pattern

func (SmashPlanRule) Rewrite

func (spp SmashPlanRule) Rewrite(ctx context.Context, node plan.Node) (plan.Node, bool, error)

Jump to

Keyboard shortcuts

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