parser

package
v0.0.0-...-bec5d16 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Code generated by goyacc -l -o promql/parser/generated_parser.y.go promql/parser/generated_parser.y. DO NOT EDIT.

Index

Constants

View Source
const ADD = 57381
View Source
const AT = 57398
View Source
const ATAN2 = 57399
View Source
const AVG = 57402
View Source
const BLANK = 57347
View Source
const BOOL = 57416
View Source
const BOTTOMK = 57403
View Source
const BUCKETS_DESC = 57375
View Source
const BY = 57417
View Source
const CLOSE_HIST = 57359
View Source
const COLON = 57348
View Source
const COMMA = 57349
View Source
const COMMENT = 57350
View Source
const COUNT = 57404
View Source
const COUNT_DESC = 57371
View Source
const COUNT_VALUES = 57405
View Source
const DIV = 57382
View Source
const DURATION = 57351
View Source
const END = 57427
View Source
const EOF = 57352
View Source
const EQL = 57346
View Source
const EQLC = 57383
View Source
const EQL_REGEX = 57384
View Source
const ERROR = 57353
View Source
const GROUP = 57406
View Source
const GROUP_LEFT = 57418
View Source
const GROUP_RIGHT = 57419
View Source
const GTE = 57385
View Source
const GTR = 57386
View Source
const IDENTIFIER = 57354
View Source
const IGNORING = 57420
View Source
const LAND = 57387
View Source
const LEFT_BRACE = 57355
View Source
const LEFT_BRACKET = 57356
View Source
const LEFT_PAREN = 57357
View Source
const LOR = 57388
View Source
const LSS = 57389
View Source
const LTE = 57390
View Source
const LUNLESS = 57391
View Source
const MAX = 57407
View Source
const METRIC_IDENTIFIER = 57360
View Source
const MIN = 57408
View Source
const MOD = 57392
View Source
const MUL = 57393
View Source
const NEGATIVE_BUCKETS_DESC = 57376
View Source
const NEGATIVE_OFFSET_DESC = 57374
View Source
const NEQ = 57394
View Source
const NEQ_REGEX = 57395
View Source
const NUMBER = 57361
View Source
const OFFSET = 57421
View Source
const OFFSET_DESC = 57373
View Source
const ON = 57422
View Source
const OPEN_HIST = 57358
View Source
const POW = 57396
View Source
const QUANTILE = 57409
View Source
const RIGHT_BRACE = 57362
View Source
const RIGHT_BRACKET = 57363
View Source
const RIGHT_PAREN = 57364
View Source
const SCHEMA_DESC = 57372
View Source
const SEMICOLON = 57365
View Source
const SPACE = 57366
View Source
const START = 57426
View Source
const START_EXPRESSION = 57432
View Source
const START_METRIC = 57430
View Source
const START_METRIC_SELECTOR = 57433
View Source
const START_SERIES_DESCRIPTION = 57431
View Source
const STDDEV = 57410
View Source
const STDVAR = 57411
View Source
const STRING = 57367
View Source
const SUB = 57397
View Source
const SUM = 57412
View Source
const SUM_DESC = 57370
View Source
const TIMES = 57368
View Source
const TOPK = 57413
View Source
const WITHOUT = 57423
View Source
const ZERO_BUCKET_DESC = 57377
View Source
const ZERO_BUCKET_WIDTH_DESC = 57378

Variables

View Source
var EnableExperimentalFunctions bool

EnableExperimentalFunctions controls whether experimentalFunctions are enabled.

View Source
var Functions = map[string]*Function{
	"abs": {
		Name:       "abs",
		ArgTypes:   []ValueType{ValueTypeVector},
		ReturnType: ValueTypeVector,
	},
	"absent": {
		Name:       "absent",
		ArgTypes:   []ValueType{ValueTypeVector},
		ReturnType: ValueTypeVector,
	},
	"absent_over_time": {
		Name:       "absent_over_time",
		ArgTypes:   []ValueType{ValueTypeMatrix},
		ReturnType: ValueTypeVector,
	},
	"acos": {
		Name:       "acos",
		ArgTypes:   []ValueType{ValueTypeVector},
		ReturnType: ValueTypeVector,
	},
	"acosh": {
		Name:       "acosh",
		ArgTypes:   []ValueType{ValueTypeVector},
		ReturnType: ValueTypeVector,
	},
	"asin": {
		Name:       "asin",
		ArgTypes:   []ValueType{ValueTypeVector},
		ReturnType: ValueTypeVector,
	},
	"asinh": {
		Name:       "asinh",
		ArgTypes:   []ValueType{ValueTypeVector},
		ReturnType: ValueTypeVector,
	},
	"atan": {
		Name:       "atan",
		ArgTypes:   []ValueType{ValueTypeVector},
		ReturnType: ValueTypeVector,
	},
	"atanh": {
		Name:       "atanh",
		ArgTypes:   []ValueType{ValueTypeVector},
		ReturnType: ValueTypeVector,
	},
	"avg_over_time": {
		Name:       "avg_over_time",
		ArgTypes:   []ValueType{ValueTypeMatrix},
		ReturnType: ValueTypeVector,
	},
	"ceil": {
		Name:       "ceil",
		ArgTypes:   []ValueType{ValueTypeVector},
		ReturnType: ValueTypeVector,
	},
	"changes": {
		Name:       "changes",
		ArgTypes:   []ValueType{ValueTypeMatrix},
		ReturnType: ValueTypeVector,
	},
	"clamp": {
		Name:       "clamp",
		ArgTypes:   []ValueType{ValueTypeVector, ValueTypeScalar, ValueTypeScalar},
		ReturnType: ValueTypeVector,
	},
	"clamp_max": {
		Name:       "clamp_max",
		ArgTypes:   []ValueType{ValueTypeVector, ValueTypeScalar},
		ReturnType: ValueTypeVector,
	},
	"clamp_min": {
		Name:       "clamp_min",
		ArgTypes:   []ValueType{ValueTypeVector, ValueTypeScalar},
		ReturnType: ValueTypeVector,
	},
	"cos": {
		Name:       "cos",
		ArgTypes:   []ValueType{ValueTypeVector},
		ReturnType: ValueTypeVector,
	},
	"cosh": {
		Name:       "cosh",
		ArgTypes:   []ValueType{ValueTypeVector},
		ReturnType: ValueTypeVector,
	},
	"count_over_time": {
		Name:       "count_over_time",
		ArgTypes:   []ValueType{ValueTypeMatrix},
		ReturnType: ValueTypeVector,
	},
	"days_in_month": {
		Name:       "days_in_month",
		ArgTypes:   []ValueType{ValueTypeVector},
		Variadic:   1,
		ReturnType: ValueTypeVector,
	},
	"day_of_month": {
		Name:       "day_of_month",
		ArgTypes:   []ValueType{ValueTypeVector},
		Variadic:   1,
		ReturnType: ValueTypeVector,
	},
	"day_of_week": {
		Name:       "day_of_week",
		ArgTypes:   []ValueType{ValueTypeVector},
		Variadic:   1,
		ReturnType: ValueTypeVector,
	},
	"day_of_year": {
		Name:       "day_of_year",
		ArgTypes:   []ValueType{ValueTypeVector},
		Variadic:   1,
		ReturnType: ValueTypeVector,
	},
	"deg": {
		Name:       "deg",
		ArgTypes:   []ValueType{ValueTypeVector},
		ReturnType: ValueTypeVector,
	},
	"delta": {
		Name:       "delta",
		ArgTypes:   []ValueType{ValueTypeMatrix},
		ReturnType: ValueTypeVector,
	},
	"deriv": {
		Name:       "deriv",
		ArgTypes:   []ValueType{ValueTypeMatrix},
		ReturnType: ValueTypeVector,
	},
	"exp": {
		Name:       "exp",
		ArgTypes:   []ValueType{ValueTypeVector},
		ReturnType: ValueTypeVector,
	},
	"floor": {
		Name:       "floor",
		ArgTypes:   []ValueType{ValueTypeVector},
		ReturnType: ValueTypeVector,
	},
	"histogram_avg": {
		Name:       "histogram_avg",
		ArgTypes:   []ValueType{ValueTypeVector},
		ReturnType: ValueTypeVector,
	},
	"histogram_count": {
		Name:       "histogram_count",
		ArgTypes:   []ValueType{ValueTypeVector},
		ReturnType: ValueTypeVector,
	},
	"histogram_sum": {
		Name:       "histogram_sum",
		ArgTypes:   []ValueType{ValueTypeVector},
		ReturnType: ValueTypeVector,
	},
	"histogram_stddev": {
		Name:       "histogram_stddev",
		ArgTypes:   []ValueType{ValueTypeVector},
		ReturnType: ValueTypeVector,
	},
	"histogram_stdvar": {
		Name:       "histogram_stdvar",
		ArgTypes:   []ValueType{ValueTypeVector},
		ReturnType: ValueTypeVector,
	},
	"histogram_fraction": {
		Name:       "histogram_fraction",
		ArgTypes:   []ValueType{ValueTypeScalar, ValueTypeScalar, ValueTypeVector},
		ReturnType: ValueTypeVector,
	},
	"histogram_quantile": {
		Name:       "histogram_quantile",
		ArgTypes:   []ValueType{ValueTypeScalar, ValueTypeVector},
		ReturnType: ValueTypeVector,
	},
	"holt_winters": {
		Name:       "holt_winters",
		ArgTypes:   []ValueType{ValueTypeMatrix, ValueTypeScalar, ValueTypeScalar},
		ReturnType: ValueTypeVector,
	},
	"hour": {
		Name:       "hour",
		ArgTypes:   []ValueType{ValueTypeVector},
		Variadic:   1,
		ReturnType: ValueTypeVector,
	},
	"idelta": {
		Name:       "idelta",
		ArgTypes:   []ValueType{ValueTypeMatrix},
		ReturnType: ValueTypeVector,
	},
	"increase": {
		Name:       "increase",
		ArgTypes:   []ValueType{ValueTypeMatrix},
		ReturnType: ValueTypeVector,
	},
	"irate": {
		Name:       "irate",
		ArgTypes:   []ValueType{ValueTypeMatrix},
		ReturnType: ValueTypeVector,
	},
	"label_replace": {
		Name:       "label_replace",
		ArgTypes:   []ValueType{ValueTypeVector, ValueTypeString, ValueTypeString, ValueTypeString, ValueTypeString},
		ReturnType: ValueTypeVector,
	},
	"label_join": {
		Name:       "label_join",
		ArgTypes:   []ValueType{ValueTypeVector, ValueTypeString, ValueTypeString, ValueTypeString},
		Variadic:   -1,
		ReturnType: ValueTypeVector,
	},
	"last_over_time": {
		Name:       "last_over_time",
		ArgTypes:   []ValueType{ValueTypeMatrix},
		ReturnType: ValueTypeVector,
	},
	"ln": {
		Name:       "ln",
		ArgTypes:   []ValueType{ValueTypeVector},
		ReturnType: ValueTypeVector,
	},
	"log10": {
		Name:       "log10",
		ArgTypes:   []ValueType{ValueTypeVector},
		ReturnType: ValueTypeVector,
	},
	"log2": {
		Name:       "log2",
		ArgTypes:   []ValueType{ValueTypeVector},
		ReturnType: ValueTypeVector,
	},
	"mad_over_time": {
		Name:         "mad_over_time",
		ArgTypes:     []ValueType{ValueTypeMatrix},
		ReturnType:   ValueTypeVector,
		Experimental: true,
	},
	"max_over_time": {
		Name:       "max_over_time",
		ArgTypes:   []ValueType{ValueTypeMatrix},
		ReturnType: ValueTypeVector,
	},
	"min_over_time": {
		Name:       "min_over_time",
		ArgTypes:   []ValueType{ValueTypeMatrix},
		ReturnType: ValueTypeVector,
	},
	"minute": {
		Name:       "minute",
		ArgTypes:   []ValueType{ValueTypeVector},
		Variadic:   1,
		ReturnType: ValueTypeVector,
	},
	"month": {
		Name:       "month",
		ArgTypes:   []ValueType{ValueTypeVector},
		Variadic:   1,
		ReturnType: ValueTypeVector,
	},
	"pi": {
		Name:       "pi",
		ArgTypes:   []ValueType{},
		ReturnType: ValueTypeScalar,
	},
	"predict_linear": {
		Name:       "predict_linear",
		ArgTypes:   []ValueType{ValueTypeMatrix, ValueTypeScalar},
		ReturnType: ValueTypeVector,
	},
	"present_over_time": {
		Name:       "present_over_time",
		ArgTypes:   []ValueType{ValueTypeMatrix},
		ReturnType: ValueTypeVector,
	},
	"quantile_over_time": {
		Name:       "quantile_over_time",
		ArgTypes:   []ValueType{ValueTypeScalar, ValueTypeMatrix},
		ReturnType: ValueTypeVector,
	},
	"rad": {
		Name:       "rad",
		ArgTypes:   []ValueType{ValueTypeVector},
		ReturnType: ValueTypeVector,
	},
	"rate": {
		Name:       "rate",
		ArgTypes:   []ValueType{ValueTypeMatrix},
		ReturnType: ValueTypeVector,
	},
	"resets": {
		Name:       "resets",
		ArgTypes:   []ValueType{ValueTypeMatrix},
		ReturnType: ValueTypeVector,
	},
	"round": {
		Name:       "round",
		ArgTypes:   []ValueType{ValueTypeVector, ValueTypeScalar},
		Variadic:   1,
		ReturnType: ValueTypeVector,
	},
	"scalar": {
		Name:       "scalar",
		ArgTypes:   []ValueType{ValueTypeVector},
		ReturnType: ValueTypeScalar,
	},
	"sgn": {
		Name:       "sgn",
		ArgTypes:   []ValueType{ValueTypeVector},
		ReturnType: ValueTypeVector,
	},
	"sin": {
		Name:       "sin",
		ArgTypes:   []ValueType{ValueTypeVector},
		ReturnType: ValueTypeVector,
	},
	"sinh": {
		Name:       "sinh",
		ArgTypes:   []ValueType{ValueTypeVector},
		ReturnType: ValueTypeVector,
	},
	"sort": {
		Name:       "sort",
		ArgTypes:   []ValueType{ValueTypeVector},
		ReturnType: ValueTypeVector,
	},
	"sort_desc": {
		Name:       "sort_desc",
		ArgTypes:   []ValueType{ValueTypeVector},
		ReturnType: ValueTypeVector,
	},
	"sort_by_label": {
		Name:         "sort_by_label",
		ArgTypes:     []ValueType{ValueTypeVector, ValueTypeString},
		Variadic:     -1,
		ReturnType:   ValueTypeVector,
		Experimental: true,
	},
	"sort_by_label_desc": {
		Name:         "sort_by_label_desc",
		ArgTypes:     []ValueType{ValueTypeVector, ValueTypeString},
		Variadic:     -1,
		ReturnType:   ValueTypeVector,
		Experimental: true,
	},
	"sqrt": {
		Name:       "sqrt",
		ArgTypes:   []ValueType{ValueTypeVector},
		ReturnType: ValueTypeVector,
	},
	"stddev_over_time": {
		Name:       "stddev_over_time",
		ArgTypes:   []ValueType{ValueTypeMatrix},
		ReturnType: ValueTypeVector,
	},
	"stdvar_over_time": {
		Name:       "stdvar_over_time",
		ArgTypes:   []ValueType{ValueTypeMatrix},
		ReturnType: ValueTypeVector,
	},
	"sum_over_time": {
		Name:       "sum_over_time",
		ArgTypes:   []ValueType{ValueTypeMatrix},
		ReturnType: ValueTypeVector,
	},
	"tan": {
		Name:       "tan",
		ArgTypes:   []ValueType{ValueTypeVector},
		ReturnType: ValueTypeVector,
	},
	"tanh": {
		Name:       "tanh",
		ArgTypes:   []ValueType{ValueTypeVector},
		ReturnType: ValueTypeVector,
	},
	"time": {
		Name:       "time",
		ArgTypes:   []ValueType{},
		ReturnType: ValueTypeScalar,
	},
	"timestamp": {
		Name:       "timestamp",
		ArgTypes:   []ValueType{ValueTypeVector},
		ReturnType: ValueTypeVector,
	},
	"vector": {
		Name:       "vector",
		ArgTypes:   []ValueType{ValueTypeScalar},
		ReturnType: ValueTypeVector,
	},
	"year": {
		Name:       "year",
		ArgTypes:   []ValueType{ValueTypeVector},
		Variadic:   1,
		ReturnType: ValueTypeVector,
	},
}

Functions is a list of all functions supported by PromQL, including their types.

View Source
var ItemTypeStr = map[ItemType]string{
	OPEN_HIST:     "{{",
	CLOSE_HIST:    "}}",
	LEFT_PAREN:    "(",
	RIGHT_PAREN:   ")",
	LEFT_BRACE:    "{",
	RIGHT_BRACE:   "}",
	LEFT_BRACKET:  "[",
	RIGHT_BRACKET: "]",
	COMMA:         ",",
	EQL:           "=",
	COLON:         ":",
	SEMICOLON:     ";",
	BLANK:         "_",
	TIMES:         "x",
	SPACE:         "<space>",

	SUB:       "-",
	ADD:       "+",
	MUL:       "*",
	MOD:       "%",
	DIV:       "/",
	EQLC:      "==",
	NEQ:       "!=",
	LTE:       "<=",
	LSS:       "<",
	GTE:       ">=",
	GTR:       ">",
	EQL_REGEX: "=~",
	NEQ_REGEX: "!~",
	POW:       "^",
}

ItemTypeStr is the default string representations for common Items. It does not imply that those are the only character sequences that can be lexed to such an Item.

Functions

func DocumentedType

func DocumentedType(t ValueType) string

DocumentedType returns the internal type to the equivalent user facing terminology as defined in the documentation.

func EnrichParseError

func EnrichParseError(err error, enrich func(parseErr *ParseErr))

EnrichParseError enriches a single or list of parse errors (used for unit tests and promtool).

func ExtractSelectors

func ExtractSelectors(expr Expr) [][]*labels.Matcher

func Inspect

func Inspect(node Node, f inspector)

Inspect traverses an AST in depth-first order: It starts by calling f(node, path); node must not be nil. If f returns a nil error, Inspect invokes f for all the non-nil children of node, recursively.

func MustLabelMatcher

func MustLabelMatcher(mt labels.MatchType, name, val string) *labels.Matcher

func NewParser

func NewParser(input string, opts ...Opt) *parser

NewParser returns a new parser.

func ParseMetric

func ParseMetric(input string) (m labels.Labels, err error)

ParseMetric parses the input into a metric.

func ParseMetricSelector

func ParseMetricSelector(input string) (m []*labels.Matcher, err error)

ParseMetricSelector parses the provided textual metric selector into a list of label matchers.

func ParseMetricSelectors

func ParseMetricSelectors(matchers []string) (m [][]*labels.Matcher, err error)

ParseMetricSelectors parses a list of provided textual metric selectors into lists of label matchers.

func Prettify

func Prettify(n Node) string

func Tree

func Tree(node Node) string

Tree returns a string of the tree structure of the given node.

func Walk

func Walk(v Visitor, node Node, path []Node) error

Walk traverses an AST in depth-first order: It starts by calling v.Visit(node, path); node must not be nil. If the visitor w returned by v.Visit(node, path) is not nil and the visitor returns no error, Walk is invoked recursively with visitor w for each of the non-nil children of node, followed by a call of w.Visit(nil), returning an error As the tree is descended the path of previous nodes is provided.

Types

type AggregateExpr

type AggregateExpr struct {
	Op       ItemType // The used aggregation operation.
	Expr     Expr     // The Vector expression over which is aggregated.
	Param    Expr     // Parameter used by some aggregators.
	Grouping []string // The labels by which to group the Vector.
	Without  bool     // Whether to drop the given labels rather than keep them.
	PosRange posrange.PositionRange
}

AggregateExpr represents an aggregation operation on a Vector.

func (*AggregateExpr) PositionRange

func (e *AggregateExpr) PositionRange() posrange.PositionRange

func (*AggregateExpr) Pretty

func (e *AggregateExpr) Pretty(level int) string

func (*AggregateExpr) PromQLExpr

func (*AggregateExpr) PromQLExpr()

func (*AggregateExpr) String

func (node *AggregateExpr) String() string

func (*AggregateExpr) Type

func (e *AggregateExpr) Type() ValueType

type BinaryExpr

type BinaryExpr struct {
	Op       ItemType // The operation of the expression.
	LHS, RHS Expr     // 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 *VectorMatching

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

BinaryExpr represents a binary expression between two child expressions.

func (*BinaryExpr) PositionRange

func (e *BinaryExpr) PositionRange() posrange.PositionRange

func (*BinaryExpr) Pretty

func (e *BinaryExpr) Pretty(level int) string

func (*BinaryExpr) PromQLExpr

func (*BinaryExpr) PromQLExpr()

func (*BinaryExpr) String

func (node *BinaryExpr) String() string

func (*BinaryExpr) Type

func (e *BinaryExpr) Type() ValueType

type Call

type Call struct {
	Func *Function   // The function that was called.
	Args Expressions // Arguments used in the call.

	PosRange posrange.PositionRange
}

Call represents a function call.

func (*Call) PositionRange

func (e *Call) PositionRange() posrange.PositionRange

func (*Call) Pretty

func (e *Call) Pretty(level int) string

func (*Call) PromQLExpr

func (*Call) PromQLExpr()

func (*Call) String

func (node *Call) String() string

func (*Call) Type

func (e *Call) Type() ValueType

type EvalStmt

type EvalStmt struct {
	Expr Expr // Expression to be evaluated.

	// The time boundaries for the evaluation. If Start equals End an instant
	// is evaluated.
	Start, End time.Time
	// Time between two evaluated instants for the range [Start:End].
	Interval time.Duration
	// Lookback delta to use for this evaluation.
	LookbackDelta time.Duration
}

EvalStmt holds an expression and information on the range it should be evaluated on.

func (*EvalStmt) PositionRange

func (e *EvalStmt) PositionRange() posrange.PositionRange

func (*EvalStmt) Pretty

func (e *EvalStmt) Pretty(_ int) string

func (*EvalStmt) PromQLStmt

func (*EvalStmt) PromQLStmt()

func (*EvalStmt) String

func (node *EvalStmt) String() string

type Expr

type Expr interface {
	Node

	// Type returns the type the expression evaluates to. It does not perform
	// in-depth checks as this is done at parsing-time.
	Type() ValueType
	// PromQLExpr ensures that no other types accidentally implement the interface.
	PromQLExpr()
}

Expr is a generic interface for all expression types.

func ParseExpr

func ParseExpr(input string) (expr Expr, err error)

ParseExpr returns the expression parsed from the input.

type Expressions

type Expressions []Expr

Expressions is a list of expression nodes that implements Node.

func (Expressions) PositionRange

func (e Expressions) PositionRange() posrange.PositionRange

func (Expressions) Pretty

func (e Expressions) Pretty(level int) string

func (Expressions) String

func (es Expressions) String() (s string)

type Function

type Function struct {
	Name         string
	ArgTypes     []ValueType
	Variadic     int
	ReturnType   ValueType
	Experimental bool
}

Function represents a function of the expression language and is used by function nodes.

func MustGetFunction

func MustGetFunction(name string) *Function

type Item

type Item struct {
	Typ ItemType     // The type of this Item.
	Pos posrange.Pos // The starting position, in bytes, of this Item in the input string.
	Val string       // The value of this Item.
}

Item represents a token or text string returned from the scanner.

func (*Item) PositionRange

func (i *Item) PositionRange() posrange.PositionRange

Item implements the Node interface. This makes it possible to call mergeRanges on them.

func (Item) Pretty

func (i Item) Pretty(int) string

Pretty returns the prettified form of an item. This is same as the item's stringified format.

func (Item) String

func (i Item) String() string

String returns a descriptive string for the Item.

type ItemType

type ItemType int

func (ItemType) IsAggregator

func (i ItemType) IsAggregator() bool

IsAggregator returns true if the Item belongs to the aggregator functions. Returns false otherwise.

func (ItemType) IsAggregatorWithParam

func (i ItemType) IsAggregatorWithParam() bool

IsAggregatorWithParam returns true if the Item is an aggregator that takes a parameter. Returns false otherwise.

func (ItemType) IsComparisonOperator

func (i ItemType) IsComparisonOperator() bool

IsComparisonOperator returns true if the Item corresponds to a comparison operator. Returns false otherwise.

func (ItemType) IsKeyword

func (i ItemType) IsKeyword() bool

IsKeyword returns true if the Item corresponds to a keyword. Returns false otherwise.

func (ItemType) IsOperator

func (i ItemType) IsOperator() bool

IsOperator returns true if the Item corresponds to a arithmetic or set operator. Returns false otherwise.

func (ItemType) IsSetOperator

func (i ItemType) IsSetOperator() bool

IsSetOperator returns whether the Item corresponds to a set operator.

func (ItemType) String

func (i ItemType) String() string

type Lexer

type Lexer struct {
	// contains filtered or unexported fields
}

Lexer holds the state of the scanner.

func Lex

func Lex(input string) *Lexer

Lex creates a new scanner for the input string.

func (*Lexer) NextItem

func (l *Lexer) NextItem(itemp *Item)

NextItem writes the next item to the provided address.

type MatrixSelector

type MatrixSelector struct {
	// It is safe to assume that this is an VectorSelector
	// if the parser hasn't returned an error.
	VectorSelector Expr
	Range          time.Duration

	EndPos posrange.Pos
}

MatrixSelector represents a Matrix selection.

func (*MatrixSelector) PositionRange

func (e *MatrixSelector) PositionRange() posrange.PositionRange

func (*MatrixSelector) Pretty

func (e *MatrixSelector) Pretty(level int) string

func (*MatrixSelector) PromQLExpr

func (*MatrixSelector) PromQLExpr()

func (*MatrixSelector) String

func (node *MatrixSelector) String() string

func (*MatrixSelector) Type

func (e *MatrixSelector) Type() ValueType

type Node

type Node interface {
	// String representation of the node that returns the given node when parsed
	// as part of a valid query.
	String() string

	// Pretty returns the prettified representation of the node.
	// It uses the level information to determine at which level/depth the current
	// node is in the AST and uses this to apply indentation.
	Pretty(level int) string

	// PositionRange returns the position of the AST Node in the query string.
	PositionRange() posrange.PositionRange
}

Node is a generic interface for all nodes in an AST.

Whenever numerous nodes are listed such as in a switch-case statement or a chain of function definitions (e.g. String(), PromQLExpr(), etc.) convention is to list them as follows:

  • Statements
  • statement types (alphabetical)
  • ...
  • Expressions
  • expression types (alphabetical)
  • ...

func Children

func Children(node Node) []Node

Children returns a list of all child nodes of a syntax tree node.

type NumberLiteral

type NumberLiteral struct {
	Val float64

	PosRange posrange.PositionRange
}

NumberLiteral represents a number.

func (*NumberLiteral) PositionRange

func (e *NumberLiteral) PositionRange() posrange.PositionRange

func (*NumberLiteral) Pretty

func (e *NumberLiteral) Pretty(level int) string

func (*NumberLiteral) PromQLExpr

func (*NumberLiteral) PromQLExpr()

func (*NumberLiteral) String

func (node *NumberLiteral) String() string

func (*NumberLiteral) Type

func (e *NumberLiteral) Type() ValueType

type Opt

type Opt func(p *parser)

func WithFunctions

func WithFunctions(functions map[string]*Function) Opt

type ParenExpr

type ParenExpr struct {
	Expr     Expr
	PosRange posrange.PositionRange
}

ParenExpr wraps an expression so it cannot be disassembled as a consequence of operator precedence.

func (*ParenExpr) PositionRange

func (e *ParenExpr) PositionRange() posrange.PositionRange

func (*ParenExpr) Pretty

func (e *ParenExpr) Pretty(level int) string

func (*ParenExpr) PromQLExpr

func (*ParenExpr) PromQLExpr()

func (*ParenExpr) String

func (node *ParenExpr) String() string

func (*ParenExpr) Type

func (e *ParenExpr) Type() ValueType

type ParseErr

type ParseErr struct {
	PositionRange posrange.PositionRange
	Err           error
	Query         string

	// LineOffset is an additional line offset to be added. Only used inside unit tests.
	LineOffset int
}

ParseErr wraps a parsing error with line and position context.

func (*ParseErr) Error

func (e *ParseErr) Error() string

type ParseErrors

type ParseErrors []ParseErr

func (ParseErrors) Error

func (errs ParseErrors) Error() string

Since producing multiple error messages might look weird when combined with error wrapping, only the first error produced by the parser is included in the error string. If getting the full error list is desired, it is recommended to typecast the error returned by the parser to ParseErrors and work with the underlying slice.

type Parser

type Parser interface {
	ParseExpr() (Expr, error)
	Close()
}

type SequenceValue

type SequenceValue struct {
	Value     float64
	Omitted   bool
	Histogram *histogram.FloatHistogram
}

SequenceValue is an omittable value in a sequence of time series values.

func ParseSeriesDesc

func ParseSeriesDesc(input string) (labels labels.Labels, values []SequenceValue, err error)

ParseSeriesDesc parses the description of a time series.

func (SequenceValue) String

func (v SequenceValue) String() string

type Statement

type Statement interface {
	Node

	// PromQLStmt ensures that no other type accidentally implements the interface
	PromQLStmt()
}

Statement is a generic interface for all statements.

type StepInvariantExpr

type StepInvariantExpr struct {
	Expr Expr
}

StepInvariantExpr represents a query which evaluates to the same result irrespective of the evaluation time given the raw samples from TSDB remain unchanged. Currently this is only used for engine optimisations and the parser does not produce this.

func (*StepInvariantExpr) PositionRange

func (e *StepInvariantExpr) PositionRange() posrange.PositionRange

func (*StepInvariantExpr) Pretty

func (e *StepInvariantExpr) Pretty(level int) string

func (*StepInvariantExpr) PromQLExpr

func (*StepInvariantExpr) PromQLExpr()

func (*StepInvariantExpr) String

func (e *StepInvariantExpr) String() string

func (*StepInvariantExpr) Type

func (e *StepInvariantExpr) Type() ValueType

type StringLiteral

type StringLiteral struct {
	Val      string
	PosRange posrange.PositionRange
}

StringLiteral represents a string.

func (*StringLiteral) PositionRange

func (e *StringLiteral) PositionRange() posrange.PositionRange

func (*StringLiteral) Pretty

func (e *StringLiteral) Pretty(level int) string

func (*StringLiteral) PromQLExpr

func (*StringLiteral) PromQLExpr()

func (*StringLiteral) String

func (node *StringLiteral) String() string

func (*StringLiteral) Type

func (e *StringLiteral) Type() ValueType

type SubqueryExpr

type SubqueryExpr struct {
	Expr  Expr
	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
	StartOrEnd ItemType // Set when @ is used with start() or end()
	Step       time.Duration

	EndPos posrange.Pos
}

SubqueryExpr represents a subquery.

func (*SubqueryExpr) PositionRange

func (e *SubqueryExpr) PositionRange() posrange.PositionRange

func (*SubqueryExpr) Pretty

func (e *SubqueryExpr) Pretty(level int) string

func (*SubqueryExpr) PromQLExpr

func (*SubqueryExpr) PromQLExpr()

func (*SubqueryExpr) String

func (node *SubqueryExpr) String() string

func (*SubqueryExpr) Type

func (e *SubqueryExpr) Type() ValueType

type TestStmt

type TestStmt func(context.Context) error

TestStmt is an internal helper statement that allows execution of an arbitrary function during handling. It is used to test the Engine.

func (TestStmt) PositionRange

func (TestStmt) PositionRange() posrange.PositionRange

func (TestStmt) Pretty

func (t TestStmt) Pretty(int) string

func (TestStmt) PromQLStmt

func (TestStmt) PromQLStmt()

func (TestStmt) String

func (TestStmt) String() string

type UnaryExpr

type UnaryExpr struct {
	Op   ItemType
	Expr Expr

	StartPos posrange.Pos
}

UnaryExpr represents a unary operation on another expression. Currently unary operations are only supported for Scalars.

func (*UnaryExpr) PositionRange

func (e *UnaryExpr) PositionRange() posrange.PositionRange

func (*UnaryExpr) Pretty

func (e *UnaryExpr) Pretty(level int) string

func (*UnaryExpr) PromQLExpr

func (*UnaryExpr) PromQLExpr()

func (*UnaryExpr) String

func (node *UnaryExpr) String() string

func (*UnaryExpr) Type

func (e *UnaryExpr) Type() ValueType

type Value

type Value interface {
	Type() ValueType
	String() string
}

Value is a generic interface for values resulting from a query evaluation.

type ValueType

type ValueType string

ValueType describes a type of a value.

const (
	ValueTypeNone   ValueType = "none"
	ValueTypeVector ValueType = "vector"
	ValueTypeScalar ValueType = "scalar"
	ValueTypeMatrix ValueType = "matrix"
	ValueTypeString ValueType = "string"
)

The valid value types.

type VectorMatchCardinality

type VectorMatchCardinality int

VectorMatchCardinality describes the cardinality relationship of two Vectors in a binary operation.

const (
	CardOneToOne VectorMatchCardinality = iota
	CardManyToOne
	CardOneToMany
	CardManyToMany
)

func (VectorMatchCardinality) String

func (vmc VectorMatchCardinality) String() string

type VectorMatching

type VectorMatching struct {
	// The cardinality of the two Vectors.
	Card VectorMatchCardinality
	// MatchingLabels contains the labels which define equality of a pair of
	// elements from the Vectors.
	MatchingLabels []string
	// On includes the given label names from matching,
	// rather than excluding them.
	On bool
	// Include contains additional labels that should be included in
	// the result from the side with the lower cardinality.
	Include []string
}

VectorMatching describes how elements from two Vectors in a binary operation are supposed to be matched.

type VectorSelector

type VectorSelector struct {
	Name string
	// 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
	StartOrEnd    ItemType // Set when @ is used with start() or end()
	LabelMatchers []*labels.Matcher

	// The unexpanded seriesSet populated at query preparation time.
	UnexpandedSeriesSet storage.SeriesSet
	Series              []storage.Series

	PosRange posrange.PositionRange
}

VectorSelector represents a Vector selection.

func (*VectorSelector) PositionRange

func (e *VectorSelector) PositionRange() posrange.PositionRange

func (*VectorSelector) Pretty

func (e *VectorSelector) Pretty(level int) string

func (*VectorSelector) PromQLExpr

func (*VectorSelector) PromQLExpr()

func (*VectorSelector) String

func (node *VectorSelector) String() string

func (*VectorSelector) Type

func (e *VectorSelector) Type() ValueType

type Visitor

type Visitor interface {
	Visit(node Node, path []Node) (w Visitor, err error)
}

Visitor allows visiting a Node and its child nodes. The Visit method is invoked for each node with the path leading to the node provided additionally. If the result visitor w is not nil and no error, Walk visits each of the children of node with the visitor w, followed by a call of w.Visit(nil, nil).

Directories

Path Synopsis
posrange is used to report a position in query strings for error and warning messages.
posrange is used to report a position in query strings for error and warning messages.

Jump to

Keyboard shortcuts

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