logicalplan

package
v0.0.0-...-6d4171b Latest Latest
Warning

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

Go to latest
Published: May 6, 2024 License: Apache-2.0 Imports: 17 Imported by: 4

Documentation

Index

Constants

View Source
const (
	VectorSelectorNode = "vector_selector"
	MatrixSelectorNode = "matrix_selector"
	AggregationNode    = "aggregation"
	BinaryNode         = "binary"
	FunctionNode       = "function"
	NumberLiteralNode  = "number_literal"
	StringLiteralNode  = "string_literal"
	SubqueryNode       = "subquery"
	CheckDuplicateNode = "check_duplicate"
	StepInvariantNode  = "step_invariant"
	ParensNode         = "parens"
	UnaryNode          = "unary"

	RemoteExecutionNode = "remote_exec"
	DeduplicateNode     = "dedup"
	NoopNode            = "noop"
)

Variables

View Source
var (
	NoOptimizers  = []Optimizer{}
	AllOptimizers = append(DefaultOptimizers, PropagateMatchersOptimizer{})
)
View Source
var DefaultOptimizers = []Optimizer{
	SortMatchers{},
	MergeSelectsOptimizer{},
}
View Source
var (
	RewrittenExternalLabelWarning = errors.Newf("%s: rewriting an external label with label_replace can disable distributed query execution", annotations.PromQLWarning.Error())
)

Functions

func IsConstantExpr

func IsConstantExpr(expr Node) bool

IsConstantExpr reports if the expression evaluates to a constant.

func Marshal

func Marshal(node Node) ([]byte, error)

func Traverse

func Traverse(expr *Node, transform func(*Node))

func TraverseBottomUp

func TraverseBottomUp(parent *Node, current *Node, transform func(parent *Node, node *Node) bool) bool

func UnsafeUnwrapString

func UnsafeUnwrapString(expr Node) string

UnsafeUnwrapString is like UnwrapString but should only be used in cases where the parser guarantees success by already only allowing strings wrapped in parentheses.

func UnwrapFloat

func UnwrapFloat(expr Node) (float64, error)

UnwrapFloat recursively unwraps a parser.Expr until it reaches an NumberLiteral.

func UnwrapParens

func UnwrapParens(expr parser.Expr) parser.Expr

UnwrapParens recursively unwraps a parser.ParenExpr.

func UnwrapString

func UnwrapString(expr Node) (string, error)

UnwrapString recursively unwraps a parser.Expr until it reaches an StringLiteral.

Types

type Aggregation

type Aggregation struct {
	Op       parser.ItemType
	Expr     Node `json:"-"`
	Param    Node `json:"-"`
	Grouping []string
	Without  bool
}

Aggregation represents a PromQL aggregation.

func (*Aggregation) Children

func (f *Aggregation) Children() []*Node

func (*Aggregation) Clone

func (f *Aggregation) Clone() Node

func (*Aggregation) ReturnType

func (f *Aggregation) ReturnType() parser.ValueType

func (*Aggregation) String

func (f *Aggregation) String() string

func (*Aggregation) Type

func (f *Aggregation) Type() NodeType

type Binary

type Binary struct {
	Op       parser.ItemType // The operation of the expression.
	LHS, RHS Node            `json:"-"` // The operands on the respective sides of the operator.

	// The matching behavior for the operation if both operands are Vectors.
	// If they are not this field is nil.
	VectorMatching *parser.VectorMatching

	// If a comparison operator, return 0/1 rather than filtering.
	ReturnBool bool

	ValueType parser.ValueType
}

func (*Binary) Children

func (b *Binary) Children() []*Node

func (*Binary) Clone

func (b *Binary) Clone() Node

func (*Binary) ReturnType

func (b *Binary) ReturnType() parser.ValueType

func (*Binary) String

func (b *Binary) String() string

func (*Binary) Type

func (b *Binary) Type() NodeType

type CheckDuplicateLabels

type CheckDuplicateLabels struct {
	Expr Node `json:"-"`
}

CheckDuplicateLabels is a logical node that checks for duplicate labels in the same timestamp.

func (*CheckDuplicateLabels) Children

func (c *CheckDuplicateLabels) Children() []*Node

func (*CheckDuplicateLabels) Clone

func (c *CheckDuplicateLabels) Clone() Node

func (*CheckDuplicateLabels) ReturnType

func (c *CheckDuplicateLabels) ReturnType() parser.ValueType

func (*CheckDuplicateLabels) String

func (c *CheckDuplicateLabels) String() string

func (*CheckDuplicateLabels) Type

func (c *CheckDuplicateLabels) Type() NodeType

type Cloneable

type Cloneable interface {
	Clone() Node
}

type Deduplicate

type Deduplicate struct {
	LeafNode
	Expressions RemoteExecutions
}

Deduplicate is a logical plan which deduplicates samples from multiple RemoteExecutions.

func (Deduplicate) Clone

func (r Deduplicate) Clone() Node

func (Deduplicate) ReturnType

func (r Deduplicate) ReturnType() parser.ValueType

func (Deduplicate) String

func (r Deduplicate) String() string

func (Deduplicate) Type

func (r Deduplicate) Type() NodeType

type DistributeAvgOptimizer

type DistributeAvgOptimizer struct {
	SkipBinaryPushdown bool
}

DistributeAvgOptimizer rewrites an AVG aggregation into a SUM/COUNT aggregation so that it can be executed in a distributed manner.

func (DistributeAvgOptimizer) Optimize

type DistributedExecutionOptimizer

type DistributedExecutionOptimizer struct {
	Endpoints          api.RemoteEndpoints
	SkipBinaryPushdown bool
}

DistributedExecutionOptimizer produces a logical plan suitable for distributed Query execution.

func (DistributedExecutionOptimizer) Optimize

type FunctionCall

type FunctionCall struct {
	// The function that was called.
	Func parser.Function
	// Arguments passed into the function.
	Args []Node `json:"-"`
}

FunctionCall represents a PromQL function.

func (*FunctionCall) Children

func (f *FunctionCall) Children() []*Node

func (*FunctionCall) Clone

func (f *FunctionCall) Clone() Node

func (*FunctionCall) ReturnType

func (f *FunctionCall) ReturnType() parser.ValueType

func (*FunctionCall) String

func (f *FunctionCall) String() string

func (*FunctionCall) Type

func (f *FunctionCall) Type() NodeType

type LeafNode

type LeafNode struct{}

func (LeafNode) Children

func (l LeafNode) Children() []*Node

type MatrixSelector

type MatrixSelector struct {
	VectorSelector *VectorSelector `json:"-"`
	Range          time.Duration

	// Needed because this operator is used in the distributed mode
	OriginalString string
}

MatrixSelector is matrix selector with additional configuration set by optimizers. It is used so we can get rid of VectorSelector in distributed mode too.

func (*MatrixSelector) Children

func (f *MatrixSelector) Children() []*Node

func (*MatrixSelector) Clone

func (f *MatrixSelector) Clone() Node

func (*MatrixSelector) ReturnType

func (f *MatrixSelector) ReturnType() parser.ValueType

func (*MatrixSelector) String

func (f *MatrixSelector) String() string

func (*MatrixSelector) Type

func (f *MatrixSelector) Type() NodeType

type MergeSelectsOptimizer

type MergeSelectsOptimizer struct{}

MergeSelectsOptimizer optimizes a binary expression where one select is a superset of the other select. For example, the expression:

metric{a="b", c="d"} / scalar(metric{a="b"}) becomes:
Filter(c="d", metric{a="b"}) / scalar(metric{a="b"}).

The engine can then cache the result of `metric{a="b"}` and apply an additional filter for {c="d"}.

func (MergeSelectsOptimizer) Optimize

type Node

type Node interface {
	fmt.Stringer
	Cloneable
	Traversable
	Type() NodeType
	ReturnType() parser.ValueType
}

func Unmarshal

func Unmarshal(data []byte) (Node, error)

type NodeType

type NodeType string

type Nodes

type Nodes []Node

type Noop

type Noop struct {
	LeafNode
}

func (Noop) Clone

func (r Noop) Clone() Node

func (Noop) ReturnType

func (r Noop) ReturnType() parser.ValueType

func (Noop) String

func (r Noop) String() string

func (Noop) Type

func (r Noop) Type() NodeType

type NumberLiteral

type NumberLiteral struct {
	LeafNode
	Val float64
}

NumberLiteral is a logical node representing a literal number.

func (*NumberLiteral) Clone

func (c *NumberLiteral) Clone() Node

func (*NumberLiteral) ReturnType

func (c *NumberLiteral) ReturnType() parser.ValueType

func (*NumberLiteral) String

func (c *NumberLiteral) String() string

func (*NumberLiteral) Type

func (c *NumberLiteral) Type() NodeType

type Optimizer

type Optimizer interface {
	Optimize(plan Node, opts *query.Options) (Node, annotations.Annotations)
}

type Parens

type Parens struct {
	Expr Node `json:"-"`
}

func (*Parens) Children

func (p *Parens) Children() []*Node

func (*Parens) Clone

func (p *Parens) Clone() Node

func (*Parens) ReturnType

func (p *Parens) ReturnType() parser.ValueType

func (*Parens) String

func (p *Parens) String() string

func (*Parens) Type

func (p *Parens) Type() NodeType

type PassthroughOptimizer

type PassthroughOptimizer struct {
	Endpoints api.RemoteEndpoints
}

PassthroughOptimizer optimizes queries which can be simply passed through to a RemoteEngine.

func (PassthroughOptimizer) Optimize

func (m PassthroughOptimizer) Optimize(plan Node, opts *query.Options) (Node, annotations.Annotations)

type Plan

type Plan interface {
	Optimize([]Optimizer) (Plan, annotations.Annotations)
	Root() Node
}

func New

func New(root Node, queryOpts *query.Options, planOpts PlanOptions) Plan

New creates a new logical plan from logical node.

func NewFromAST

func NewFromAST(ast parser.Expr, queryOpts *query.Options, planOpts PlanOptions) Plan

func NewFromBytes

func NewFromBytes(bytes []byte, queryOpts *query.Options, planOpts PlanOptions) (Plan, error)

NewFromBytes creates a new logical plan from a byte slice created with Marshal. This method is used to deserialize a logical plan which has been sent over the wire.

type PlanOptions

type PlanOptions struct {
	DisableDuplicateLabelCheck bool
}

type Projection

type Projection struct {
	// Labels is a list of labels to be included or excluded from the selection result, depending on the value of Include.
	Labels []string
	// Include is true if only the provided list of labels should be retrieved from storage.
	// When set to false, the provided list of labels should be excluded from selection.
	Include bool
}

Projection has information on which series labels should be selected from storage.

type PropagateMatchersOptimizer

type PropagateMatchersOptimizer struct{}

PropagateMatchersOptimizer implements matcher propagation between two vector selectors in a binary expression.

func (PropagateMatchersOptimizer) Optimize

type RemoteExecution

type RemoteExecution struct {
	LeafNode
	Engine          api.RemoteEngine
	Query           Node
	QueryRangeStart time.Time
}

RemoteExecution is a logical plan that describes a remote execution of a Query against the given PromQL Engine.

func (RemoteExecution) Clone

func (r RemoteExecution) Clone() Node

func (RemoteExecution) ReturnType

func (r RemoteExecution) ReturnType() parser.ValueType

func (RemoteExecution) String

func (r RemoteExecution) String() string

func (RemoteExecution) Type

func (r RemoteExecution) Type() NodeType

type RemoteExecutions

type RemoteExecutions []RemoteExecution

func (RemoteExecutions) String

func (rs RemoteExecutions) String() string

type SelectorBatchSize

type SelectorBatchSize struct {
	Size int64
}

SelectorBatchSize configures the batch size of selector based on aggregates present in the plan.

func (SelectorBatchSize) Optimize

Optimize configures the batch size of selector based on the query plan. If any aggregate is present in the plan, the batch size is set to the configured value. The two exceptions where this cannot be done is if the aggregate is quantile, or when a binary expression precedes the aggregate.

type SortMatchers

type SortMatchers struct{}

SortMatchers sorts all matchers in a selector so that all subsequent optimizers, both in the logical and physical plan, can rely on this property.

func (SortMatchers) Optimize

func (m SortMatchers) Optimize(plan Node, _ *query.Options) (Node, annotations.Annotations)

type StepInvariantExpr

type StepInvariantExpr struct {
	Expr Node `json:"-"`
}

StepInvariantExpr is a logical node that expresses that the child expression returns the same value at every step in the evaluation.

func (*StepInvariantExpr) Children

func (c *StepInvariantExpr) Children() []*Node

func (*StepInvariantExpr) Clone

func (c *StepInvariantExpr) Clone() Node

func (*StepInvariantExpr) ReturnType

func (c *StepInvariantExpr) ReturnType() parser.ValueType

func (*StepInvariantExpr) String

func (c *StepInvariantExpr) String() string

func (*StepInvariantExpr) Type

func (c *StepInvariantExpr) Type() NodeType

type StringLiteral

type StringLiteral struct {
	LeafNode
	Val string
}

StringLiteral is a logical node representing a literal string.

func (*StringLiteral) Clone

func (c *StringLiteral) Clone() Node

func (*StringLiteral) ReturnType

func (c *StringLiteral) ReturnType() parser.ValueType

func (*StringLiteral) String

func (c *StringLiteral) String() string

func (*StringLiteral) Type

func (c *StringLiteral) Type() NodeType

type Subquery

type Subquery struct {
	Expr  Node `json:"-"`
	Range time.Duration
	// OriginalOffset is the actual offset that was set in the query.
	// This never changes.
	OriginalOffset time.Duration
	// Offset is the offset used during the query execution
	// which is calculated using the original offset, at modifier time,
	// eval time, and subquery offsets in the AST tree.
	Offset    time.Duration
	Timestamp *int64
	Step      time.Duration

	StartOrEnd parser.ItemType
}

func (*Subquery) Children

func (s *Subquery) Children() []*Node

func (*Subquery) Clone

func (s *Subquery) Clone() Node

func (*Subquery) ReturnType

func (s *Subquery) ReturnType() parser.ValueType

func (*Subquery) String

func (s *Subquery) String() string

func (*Subquery) Type

func (s *Subquery) Type() NodeType

type Traversable

type Traversable interface {
	Children() []*Node
}

type Unary

type Unary struct {
	Op   parser.ItemType
	Expr Node `json:"-"`
}

func (*Unary) Children

func (p *Unary) Children() []*Node

func (*Unary) Clone

func (p *Unary) Clone() Node

func (*Unary) ReturnType

func (p *Unary) ReturnType() parser.ValueType

func (*Unary) String

func (p *Unary) String() string

func (*Unary) Type

func (p *Unary) Type() NodeType

type UserDefinedExpr

type UserDefinedExpr interface {
	Node
	MakeExecutionOperator(
		ctx context.Context,
		vectors *model.VectorPool,
		opts *query.Options,
		hints storage.SelectHints,
	) (model.VectorOperator, error)
}

UserDefinedExpr is an extension point which allows users to define their execution operators.

type VectorSelector

type VectorSelector struct {
	*parser.VectorSelector
	LeafNode
	Filters         []*labels.Matcher
	BatchSize       int64
	SelectTimestamp bool
	Projection      Projection
}

VectorSelector is vector selector with additional configuration set by optimizers.

func (*VectorSelector) Clone

func (f *VectorSelector) Clone() Node

func (*VectorSelector) ReturnType

func (f *VectorSelector) ReturnType() parser.ValueType

func (*VectorSelector) String

func (f *VectorSelector) String() string

func (*VectorSelector) Type

func (f *VectorSelector) Type() NodeType

Jump to

Keyboard shortcuts

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