pub enum Expr {
Aggregate(AggregateExpr),
Unary(UnaryExpr),
Binary(BinaryExpr),
Paren(ParenExpr),
Subquery(SubqueryExpr),
NumberLiteral(NumberLiteral),
StringLiteral(StringLiteral),
VectorSelector(VectorSelector),
MatrixSelector(MatrixSelector),
Call(Call),
Extension(Extension),
}Variants§
Aggregate(AggregateExpr)
Aggregate represents an aggregation operation on a Vector.
Unary(UnaryExpr)
Unary represents a unary operation on another expression. Currently unary operations are only supported for Scalars.
Binary(BinaryExpr)
Binary represents a binary expression between two child expressions.
Paren(ParenExpr)
Paren wraps an expression so it cannot be disassembled as a consequence of operator precedence.
Subquery(SubqueryExpr)
SubqueryExpr represents a subquery.
NumberLiteral(NumberLiteral)
NumberLiteral represents a number.
StringLiteral(StringLiteral)
StringLiteral represents a string.
VectorSelector(VectorSelector)
VectorSelector represents a Vector selection.
MatrixSelector(MatrixSelector)
MatrixSelector represents a Matrix selection.
Call(Call)
Call represents a function call.
Extension(Extension)
Extension represents an extension expression. It is for user to attach additional information to the AST. This parser won’t generate Extension node.
Implementations§
Source§impl Expr
impl Expr
pub fn value_type(&self) -> ValueType
Sourcepub fn prettify(&self) -> String
pub fn prettify(&self) -> String
Examples found in repository?
17fn main() {
18 let promql = r#"
19 http_requests_total{
20 environment=~"staging|testing|development",
21 method!="GET"
22 } offset 5m
23 "#;
24
25 match parser::parse(promql) {
26 Ok(expr) => {
27 println!("Prettify:\n{}\n", expr.prettify());
28 println!("AST:\n{expr:?}");
29 }
30 Err(info) => println!("Err: {info:?}"),
31 }
32}Trait Implementations§
Source§impl From<VectorSelector> for Expr
directly create an Expr::VectorSelector from instant vector
impl From<VectorSelector> for Expr
directly create an Expr::VectorSelector from instant vector
§Examples
Basic usage:
use promql_parser::label::Matchers;
use promql_parser::parser::{Expr, VectorSelector};
let name = String::from("foo");
let vs = VectorSelector::new(Some(name), Matchers::empty());
assert_eq!(Expr::VectorSelector(vs), Expr::from(VectorSelector::from("foo")));