pub struct Query<A> {
pub attrs: Attrs,
pub sources: Vec<Source<A>>,
pub predicate: Option<Expr>,
pub group_by: Option<GroupBy>,
pub order_by: Option<OrderBy>,
pub limit: Option<Limit>,
pub projection: Expr,
pub distinct: bool,
pub meta: A,
}Expand description
A complete EventQL query.
This is the root node of the AST, representing a full query with all its clauses. A query must have at least one source and a projection; other clauses are optional.
§Structure
FROM <alias> <source>
[FROM <alias> <source>] ...
[WHERE <condition>]
[GROUP BY <field> [HAVING <condition>]]
[ORDER BY <field> ASC|DESC]
[TOP|SKIP <n>]
PROJECT INTO [DISTINCT] <projection>§Examples
use eventql_parser::parse_query;
let query = parse_query(
"FROM e IN events \
WHERE e.price > 100 \
ORDER BY e.timestamp DESC \
TOP 10 \
PROJECT INTO {id: e.id, price: e.price}"
).unwrap();
assert_eq!(query.sources.len(), 1);
assert!(query.predicate.is_some());
assert!(query.order_by.is_some());
assert!(query.limit.is_some());Fields§
§attrs: AttrsMetadata about this query
sources: Vec<Source<A>>FROM clause sources (must have at least one)
predicate: Option<Expr>Optional WHERE clause filter predicate
group_by: Option<GroupBy>Optional GROUP BY clause expression
order_by: Option<OrderBy>Optional ORDER BY clause
limit: Option<Limit>Optional LIMIT clause (TOP or SKIP)
projection: ExprPROJECT INTO clause expression (required)
distinct: boolRemove duplicate rows from the query’s results
meta: AType-level metadata about the query’s analysis state.
This field uses a generic type parameter to track whether the query is in a raw (unparsed/untyped) state or has been statically analyzed:
Query<Raw>: Query parsed but not yet type-checkedQuery<Typed>: Query that has passed static analysis with validated types and variable scopes
This provides compile-time guarantees about the query’s type safety.
Implementations§
Source§impl Query<Raw>
impl Query<Raw>
Sourcepub fn run_static_analysis(
self,
options: &AnalysisOptions,
) -> Result<Query<Typed>>
pub fn run_static_analysis( self, options: &AnalysisOptions, ) -> Result<Query<Typed>>
Performs static analysis on this raw query.
This is a convenience method that runs type checking and variable scoping analysis on the query, converting it from a raw (untyped) query to a typed query.
The analysis validates:
- Variable declarations and scoping
- Type compatibility in expressions and operations
- Valid field accesses on record types
- Correct function argument types and counts
- Aggregate function usage restrictions (only in PROJECT INTO)
- No mixing of aggregate functions with source-bound fields
- Aggregate function arguments are source-bound fields
- Non-empty record literals in projections
§Arguments
options- Configuration containing type information and default scope
§Returns
Returns a typed query on success, or an error if type checking fails.