use async_trait::async_trait;
use datafusion::arrow::array::RecordBatch;
use datafusion::arrow::datatypes::Schema;
use std::sync::Arc;
use crate::core::error::Result;
#[async_trait]
pub trait FaoOperator: Send + Sync + std::fmt::Debug {
fn function_id(&self) -> &str;
fn version(&self) -> &str;
fn model_id(&self) -> &str;
fn input_schema(&self) -> &Arc<Schema>;
fn output_schema(&self) -> &Arc<Schema>;
async fn execute(&self, input: RecordBatch) -> Result<RecordBatch>;
fn estimated_latency_ms(&self, batch_size: usize) -> f64;
fn estimated_accuracy(&self) -> f64;
}
#[derive(Debug, Clone)]
pub struct FaoRef {
pub function_id: String,
pub version: String,
pub model_id: String,
pub est_latency_ms: f64,
pub est_accuracy: f64,
}
impl FaoRef {
pub fn from_operator(op: &dyn FaoOperator) -> Self {
Self {
function_id: op.function_id().to_string(),
version: op.version().to_string(),
model_id: op.model_id().to_string(),
est_latency_ms: op.estimated_latency_ms(1_000),
est_accuracy: op.estimated_accuracy(),
}
}
}