Skip to main content

grafeo_core/execution/operators/
mod.rs

1//! Physical operators for query execution.
2//!
3//! This module provides the physical operators that form the execution tree:
4//!
5//! - Scan: Read nodes/edges from storage
6//! - Expand: Traverse edges from nodes
7//! - Filter: Apply predicates to filter rows
8//! - Project: Select and transform columns
9//! - Join: Hash join and nested loop join
10//! - Aggregate: Group by and aggregation functions
11//! - Sort: Order results by columns
12//! - Limit: Limit the number of results
13//!
14//! The `push` submodule contains push-based operator implementations.
15
16mod aggregate;
17mod distinct;
18mod expand;
19mod filter;
20mod join;
21mod limit;
22mod merge;
23mod mutation;
24mod project;
25pub mod push;
26mod scan;
27mod sort;
28mod union;
29mod unwind;
30
31pub use aggregate::{
32    AggregateExpr, AggregateFunction, HashAggregateOperator, SimpleAggregateOperator,
33};
34pub use distinct::DistinctOperator;
35pub use expand::ExpandOperator;
36pub use filter::{
37    BinaryFilterOp, ExpressionPredicate, FilterExpression, FilterOperator, Predicate, UnaryFilterOp,
38};
39pub use join::{
40    EqualityCondition, HashJoinOperator, HashKey, JoinCondition, JoinType, NestedLoopJoinOperator,
41};
42pub use limit::{LimitOperator, LimitSkipOperator, SkipOperator};
43pub use merge::MergeOperator;
44pub use mutation::{
45    AddLabelOperator, CreateEdgeOperator, CreateNodeOperator, DeleteEdgeOperator,
46    DeleteNodeOperator, PropertySource, RemoveLabelOperator, SetPropertyOperator,
47};
48pub use project::{ProjectExpr, ProjectOperator};
49pub use push::{
50    AggregatePushOperator, DistinctMaterializingOperator, DistinctPushOperator, FilterPushOperator,
51    LimitPushOperator, ProjectPushOperator, SkipLimitPushOperator, SkipPushOperator,
52    SortPushOperator, SpillableAggregatePushOperator, SpillableSortPushOperator,
53};
54pub use scan::ScanOperator;
55pub use sort::{NullOrder, SortDirection, SortKey, SortOperator};
56pub use union::UnionOperator;
57pub use unwind::UnwindOperator;
58
59use thiserror::Error;
60
61use super::DataChunk;
62
63/// Result of executing an operator.
64pub type OperatorResult = Result<Option<DataChunk>, OperatorError>;
65
66/// Error during operator execution.
67#[derive(Error, Debug, Clone)]
68pub enum OperatorError {
69    /// Type mismatch during execution.
70    #[error("type mismatch: expected {expected}, found {found}")]
71    TypeMismatch {
72        /// Expected type name.
73        expected: String,
74        /// Found type name.
75        found: String,
76    },
77    /// Column not found.
78    #[error("column not found: {0}")]
79    ColumnNotFound(String),
80    /// Execution error.
81    #[error("execution error: {0}")]
82    Execution(String),
83}
84
85/// Trait for physical operators.
86pub trait Operator: Send + Sync {
87    /// Returns the next chunk of data, or None if exhausted.
88    fn next(&mut self) -> OperatorResult;
89
90    /// Resets the operator to its initial state.
91    fn reset(&mut self);
92
93    /// Returns the name of this operator for debugging.
94    fn name(&self) -> &'static str;
95}