use std::sync::Arc;
use arrow_schema::SchemaRef;
use vgi_rpc::Result;
use crate::arguments::Arguments;
use crate::function::{ArgSpec, BindParams, BindResponse, FunctionMetadata};
use crate::settings::Settings;
use crate::storage::FunctionStorage;
use crate::table_function::TableProducer;
pub struct BufferingParams {
pub execution_id: Vec<u8>,
pub storage: Arc<dyn FunctionStorage>,
pub output_schema: SchemaRef,
pub arguments: Arguments,
pub settings: Settings,
pub attach_opaque_data: Option<Vec<u8>>,
pub batch_index: Option<i64>,
pub logs: Arc<std::sync::Mutex<Vec<String>>>,
}
impl BufferingParams {
pub fn log(&self, message: impl Into<String>) {
if let Ok(mut g) = self.logs.lock() {
g.push(message.into());
}
}
}
pub trait TableBufferingFunction: Send + Sync {
fn name(&self) -> &str;
fn metadata(&self) -> FunctionMetadata;
fn argument_specs(&self) -> Vec<ArgSpec>;
fn on_bind(&self, params: &BindParams) -> Result<BindResponse>;
fn process(
&self,
params: &BufferingParams,
batch: &arrow_array::RecordBatch,
) -> Result<Vec<u8>>;
fn combine(&self, params: &BufferingParams, state_ids: &[Vec<u8>]) -> Result<Vec<Vec<u8>>>;
fn finalize_producer(
&self,
params: &BufferingParams,
finalize_state_id: Vec<u8>,
) -> Result<Box<dyn TableProducer>>;
}