hyprstream_metrics/query/physical/
mod.rs1mod vector;
8
9pub use vector::VectorizedOperator;
10
11use datafusion::arrow::datatypes::Schema;
12use datafusion::arrow::record_batch::RecordBatch;
13use datafusion::error::Result;
14use std::sync::Arc;
15
16pub trait PhysicalOperator: Send + Sync {
18 fn schema(&self) -> &Arc<Schema>;
20
21 fn execute(&self, input: Vec<RecordBatch>) -> Result<Vec<RecordBatch>>;
23
24 fn children(&self) -> Vec<Arc<dyn PhysicalOperator>>;
26}
27
28#[derive(Debug, Default)]
30pub struct OperatorMetrics {
31 pub input_rows: usize,
33 pub output_rows: usize,
35 pub execution_time_ms: u64,
37 pub memory_used: usize,
39}
40
41pub struct BaseOperator {
43 schema: Arc<Schema>,
45 children: Vec<Arc<dyn PhysicalOperator>>,
47 metrics: Arc<parking_lot::RwLock<OperatorMetrics>>,
49}
50
51impl BaseOperator {
52 pub fn new(schema: Arc<Schema>, children: Vec<Arc<dyn PhysicalOperator>>) -> Self {
53 Self {
54 schema,
55 children,
56 metrics: Arc::new(parking_lot::RwLock::new(OperatorMetrics::default())),
57 }
58 }
59
60 pub fn metrics(&self) -> Arc<parking_lot::RwLock<OperatorMetrics>> {
61 self.metrics.clone()
62 }
63}
64
65impl PhysicalOperator for BaseOperator {
66 fn schema(&self) -> &Arc<Schema> {
67 &self.schema
68 }
69
70 fn execute(&self, input: Vec<RecordBatch>) -> Result<Vec<RecordBatch>> {
71 Ok(input)
73 }
74
75 fn children(&self) -> Vec<Arc<dyn PhysicalOperator>> {
76 self.children.clone()
77 }
78}
79
80pub struct OperatorFactory;
82
83impl OperatorFactory {
84 pub fn create(
86 operator_type: &str,
87 schema: Arc<Schema>,
88 children: Vec<Arc<dyn PhysicalOperator>>,
89 properties: std::collections::HashMap<String, String>,
90 ) -> Result<Arc<dyn PhysicalOperator>> {
91 match operator_type {
92 "vector" => Ok(Arc::new(vector::VectorizedOperator::new(
93 schema, children, properties,
94 )?)),
95 _ => Err(datafusion::error::DataFusionError::NotImplemented(format!(
96 "Operator type {operator_type} not implemented"
97 ))),
98 }
99 }
100}