use std::future::Future;
use std::pin::Pin;
use indexmap::IndexMap;
use super::data::VirtualDataSlice;
use super::features::Features;
use crate::config::{ViewConfig, ViewConfigUpdate};
use crate::proto::{ColumnType, HostedTable, TableMakePortReq, ViewPort};
#[cfg(feature = "sendable")]
pub type VirtualServerFuture<'a, T> = Pin<Box<dyn Future<Output = T> + 'a>>;
#[cfg(not(feature = "sendable"))]
pub type VirtualServerFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>;
pub trait VirtualServerHandler {
#[cfg(not(feature = "sendable"))]
type Error: std::error::Error + Send + Sync + 'static;
#[cfg(feature = "sendable")]
type Error: std::error::Error + 'static;
fn get_hosted_tables(&self) -> VirtualServerFuture<'_, Result<Vec<HostedTable>, Self::Error>>;
fn table_schema(
&self,
table_id: &str,
) -> VirtualServerFuture<'_, Result<IndexMap<String, ColumnType>, Self::Error>>;
fn table_size(&self, table_id: &str) -> VirtualServerFuture<'_, Result<u32, Self::Error>>;
fn table_make_view(
&mut self,
view_id: &str,
view_id: &str,
config: &mut ViewConfigUpdate,
) -> VirtualServerFuture<'_, Result<String, Self::Error>>;
fn view_delete(&self, view_id: &str) -> VirtualServerFuture<'_, Result<(), Self::Error>>;
fn view_get_data(
&self,
view_id: &str,
config: &ViewConfig,
schema: &IndexMap<String, ColumnType>,
viewport: &ViewPort,
) -> VirtualServerFuture<'_, Result<VirtualDataSlice, Self::Error>>;
fn table_column_size(
&self,
table_id: &str,
) -> VirtualServerFuture<'_, Result<u32, Self::Error>> {
let fut = self.table_schema(table_id);
Box::pin(async move { Ok(fut.await?.len() as u32) })
}
fn view_size(&self, view_id: &str) -> VirtualServerFuture<'_, Result<u32, Self::Error>> {
Box::pin(self.table_size(view_id))
}
fn view_column_size(
&self,
view_id: &str,
config: &ViewConfig,
) -> VirtualServerFuture<'_, Result<u32, Self::Error>> {
let fut = self.view_schema(view_id, config);
Box::pin(async move { Ok(fut.await?.len() as u32) })
}
fn view_schema(
&self,
view_id: &str,
_config: &ViewConfig,
) -> VirtualServerFuture<'_, Result<IndexMap<String, ColumnType>, Self::Error>> {
Box::pin(self.table_schema(view_id))
}
fn table_validate_expression(
&self,
_table_id: &str,
_expression: &str,
) -> VirtualServerFuture<'_, Result<ColumnType, Self::Error>> {
Box::pin(async { Ok(ColumnType::Float) })
}
fn get_features(&self) -> VirtualServerFuture<'_, Result<Features<'_>, Self::Error>> {
Box::pin(async { Ok(Features::default()) })
}
fn table_make_port(
&self,
_req: &TableMakePortReq,
) -> VirtualServerFuture<'_, Result<u32, Self::Error>> {
Box::pin(async { Ok(0) })
}
fn view_get_min_max(
&self,
_view_id: &str,
_column_name: &str,
_config: &crate::config::ViewConfig,
) -> VirtualServerFuture<'_, Result<(crate::config::Scalar, crate::config::Scalar), Self::Error>>
{
Box::pin(async { unimplemented!("view_get_min_max not implemented") })
}
fn make_table(
&mut self,
_table_id: &str,
_data: &crate::proto::MakeTableData,
) -> VirtualServerFuture<'_, Result<(), Self::Error>> {
Box::pin(async { unimplemented!("make_table not implemented") })
}
}