perspective_client/virtual_server/
handler.rs1use std::future::Future;
14use std::pin::Pin;
15
16use indexmap::IndexMap;
17
18use super::data::VirtualDataSlice;
19use super::features::Features;
20use crate::config::{ViewConfig, ViewConfigUpdate};
21use crate::proto::{ColumnType, HostedTable, TableMakePortReq, ViewPort};
22
23#[cfg(feature = "sendable")]
24pub type VirtualServerFuture<'a, T> = Pin<Box<dyn Future<Output = T> + 'a>>;
25
26#[cfg(not(feature = "sendable"))]
32pub type VirtualServerFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>;
33
34pub trait VirtualServerHandler {
41 #[cfg(not(feature = "sendable"))]
45 type Error: std::error::Error + Send + Sync + 'static;
46
47 #[cfg(feature = "sendable")]
48 type Error: std::error::Error + 'static;
49
50 fn get_hosted_tables(&self) -> VirtualServerFuture<'_, Result<Vec<HostedTable>, Self::Error>>;
52
53 fn table_schema(
55 &self,
56 table_id: &str,
57 ) -> VirtualServerFuture<'_, Result<IndexMap<String, ColumnType>, Self::Error>>;
58
59 fn table_size(&self, table_id: &str) -> VirtualServerFuture<'_, Result<u32, Self::Error>>;
61
62 fn table_make_view(
67 &mut self,
68 view_id: &str,
69 view_id: &str,
70 config: &mut ViewConfigUpdate,
71 ) -> VirtualServerFuture<'_, Result<String, Self::Error>>;
72
73 fn view_delete(&self, view_id: &str) -> VirtualServerFuture<'_, Result<(), Self::Error>>;
75
76 fn view_get_data(
78 &self,
79 view_id: &str,
80 config: &ViewConfig,
81 schema: &IndexMap<String, ColumnType>,
82 viewport: &ViewPort,
83 ) -> VirtualServerFuture<'_, Result<VirtualDataSlice, Self::Error>>;
84
85 fn table_column_size(
89 &self,
90 table_id: &str,
91 ) -> VirtualServerFuture<'_, Result<u32, Self::Error>> {
92 let fut = self.table_schema(table_id);
93 Box::pin(async move { Ok(fut.await?.len() as u32) })
94 }
95
96 fn view_size(&self, view_id: &str) -> VirtualServerFuture<'_, Result<u32, Self::Error>> {
98 Box::pin(self.table_size(view_id))
99 }
100
101 fn view_column_size(
103 &self,
104 view_id: &str,
105 config: &ViewConfig,
106 ) -> VirtualServerFuture<'_, Result<u32, Self::Error>> {
107 let fut = self.view_schema(view_id, config);
108 Box::pin(async move { Ok(fut.await?.len() as u32) })
109 }
110
111 fn view_schema(
113 &self,
114 view_id: &str,
115 _config: &ViewConfig,
116 ) -> VirtualServerFuture<'_, Result<IndexMap<String, ColumnType>, Self::Error>> {
117 Box::pin(self.table_schema(view_id))
118 }
119
120 fn table_validate_expression(
124 &self,
125 _table_id: &str,
126 _expression: &str,
127 ) -> VirtualServerFuture<'_, Result<ColumnType, Self::Error>> {
128 Box::pin(async { Ok(ColumnType::Float) })
129 }
130
131 fn get_features(&self) -> VirtualServerFuture<'_, Result<Features<'_>, Self::Error>> {
135 Box::pin(async { Ok(Features::default()) })
136 }
137
138 fn table_make_port(
142 &self,
143 _req: &TableMakePortReq,
144 ) -> VirtualServerFuture<'_, Result<u32, Self::Error>> {
145 Box::pin(async { Ok(0) })
146 }
147
148 fn view_get_min_max(
152 &self,
153 _view_id: &str,
154 _column_name: &str,
155 _config: &crate::config::ViewConfig,
156 ) -> VirtualServerFuture<'_, Result<(crate::config::Scalar, crate::config::Scalar), Self::Error>>
157 {
158 Box::pin(async { unimplemented!("view_get_min_max not implemented") })
159 }
160
161 fn make_table(
167 &mut self,
168 _table_id: &str,
169 _data: &crate::proto::MakeTableData,
170 ) -> VirtualServerFuture<'_, Result<(), Self::Error>> {
171 Box::pin(async { unimplemented!("make_table not implemented") })
172 }
173}