perspective_client/table.rs
1// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
2// ┃ ██████ ██████ ██████ █ █ █ █ █ █▄ ▀███ █ ┃
3// ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█ ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄ ▀█ █ ▀▀▀▀▀ ┃
4// ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄ █ ▄▄▄▄▄ ┃
5// ┃ █ ██████ █ ▀█▄ █ ██████ █ ███▌▐███ ███████▄ █ ┃
6// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
7// ┃ Copyright (c) 2017, the Perspective Authors. ┃
8// ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃
9// ┃ This file is part of the Perspective library, distributed under the terms ┃
10// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
11// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
12
13use std::collections::HashMap;
14use std::fmt::Display;
15
16use serde::{Deserialize, Serialize};
17use ts_rs::TS;
18
19use crate::assert_table_api;
20use crate::client::{Client, Features};
21use crate::config::{Expressions, ViewConfigUpdate};
22use crate::proto::make_table_req::MakeTableOptions;
23use crate::proto::make_table_req::make_table_options::MakeTableType;
24use crate::proto::request::ClientReq;
25use crate::proto::response::ClientResp;
26use crate::proto::*;
27use crate::table_data::UpdateData;
28use crate::utils::*;
29use crate::view::View;
30
31pub type Schema = HashMap<String, ColumnType>;
32
33/// The format to interpret data preovided to [`Client::table`].
34///
35/// When serialized, these values are `"csv"`, `"json"`, `"columns"`, `"arrow"`
36/// and `"ndjson"`.
37#[derive(Clone, Copy, Debug, Serialize, Deserialize, TS)]
38pub enum TableReadFormat {
39 #[serde(rename = "csv")]
40 Csv,
41
42 #[serde(rename = "json")]
43 JsonString,
44
45 #[serde(rename = "columns")]
46 ColumnsString,
47
48 #[serde(rename = "arrow")]
49 Arrow,
50
51 #[serde(rename = "ndjson")]
52 Ndjson,
53}
54
55impl TableReadFormat {
56 pub fn parse(value: Option<String>) -> Result<Option<Self>, String> {
57 Ok(match value.as_deref() {
58 Some("csv") => Some(TableReadFormat::Csv),
59 Some("json") => Some(TableReadFormat::JsonString),
60 Some("columns") => Some(TableReadFormat::ColumnsString),
61 Some("arrow") => Some(TableReadFormat::Arrow),
62 Some("ndjson") => Some(TableReadFormat::Ndjson),
63 None => None,
64 Some(x) => return Err(format!("Unknown format \"{x}\"")),
65 })
66 }
67}
68
69/// Options which impact the behavior of [`Client::table`], as well as
70/// subsequent calls to [`Table::update`].
71#[derive(Clone, Debug, Default, Serialize, Deserialize, TS)]
72pub struct TableInitOptions {
73 #[serde(default)]
74 #[ts(optional)]
75 pub name: Option<String>,
76
77 #[serde(default)]
78 #[ts(optional)]
79 pub format: Option<TableReadFormat>,
80
81 /// This [`Table`] should use the column named by the `index` parameter as
82 /// the `index`, which causes [`Table::update`] and [`Client::table`] input
83 /// to either insert or update existing rows based on `index` column
84 /// value equality.
85 #[serde(default)]
86 #[ts(optional)]
87 pub index: Option<String>,
88
89 /// This [`Table`] should be limited to `limit` rows, after which the
90 /// _earliest_ rows will be overwritten (where _earliest_ is defined as
91 /// relative to insertion order).
92 #[serde(default)]
93 #[ts(optional)]
94 pub limit: Option<u32>,
95
96 /// Back this [`Table`]'s canonical data with the on-disk storage backend
97 /// instead of memory. On native targets this is a memory-mapped file; on
98 /// WASM it is OPFS (Worker only). Defaults to in-memory.
99 #[serde(default)]
100 #[ts(optional)]
101 pub page_to_disk: Option<bool>,
102
103 /// How Arrow `LIST` and JSON `Array` columns are ingested. `zip` (the
104 /// default) and `cartesian` expand a row into one row per list element,
105 /// and are incompatible with `index`, as the rows of an expansion
106 /// repeat their index. `stringify` encodes each list as a JSON array in
107 /// a single string column instead.
108 #[serde(default)]
109 #[ts(optional)]
110 pub list_flatten: Option<crate::proto::ListFlatten>,
111}
112
113impl TableInitOptions {
114 pub fn set_name<D: Display>(&mut self, name: D) {
115 self.name = Some(format!("{name}"))
116 }
117}
118
119impl TryFrom<TableOptions> for MakeTableOptions {
120 type Error = ClientError;
121
122 fn try_from(value: TableOptions) -> Result<Self, Self::Error> {
123 let page_to_disk = value.page_to_disk;
124 let list_flatten = value.list_flatten.map(|x| x as i32);
125 Ok(MakeTableOptions {
126 page_to_disk,
127 list_flatten,
128 make_table_type: match value {
129 TableOptions {
130 index: Some(_),
131 limit: Some(_),
132 ..
133 } => Err(ClientError::BadTableOptions)?,
134 TableOptions {
135 index: Some(index), ..
136 } => Some(MakeTableType::MakeIndexTable(index)),
137 TableOptions {
138 limit: Some(limit), ..
139 } => Some(MakeTableType::MakeLimitTable(limit)),
140 _ => None,
141 },
142 })
143 }
144}
145
146#[derive(Clone, Debug)]
147pub(crate) struct TableOptions {
148 pub index: Option<String>,
149 pub limit: Option<u32>,
150 pub page_to_disk: Option<bool>,
151 pub list_flatten: Option<crate::proto::ListFlatten>,
152}
153
154impl From<TableInitOptions> for TableOptions {
155 fn from(value: TableInitOptions) -> Self {
156 TableOptions {
157 index: value.index,
158 limit: value.limit,
159 page_to_disk: value.page_to_disk,
160 list_flatten: value.list_flatten,
161 }
162 }
163}
164
165/// Options for [`Client::join`].
166#[derive(Clone, Debug, Default, Serialize, Deserialize, TS)]
167pub struct JoinOptions {
168 #[serde(default)]
169 #[ts(optional)]
170 pub join_type: Option<crate::proto::JoinType>,
171
172 #[serde(default)]
173 #[ts(optional)]
174 pub name: Option<String>,
175
176 #[serde(default)]
177 #[ts(optional)]
178 pub right_on: Option<String>,
179}
180
181/// Options for [`Table::delete`].
182#[derive(Clone, Debug, Default, Deserialize, TS)]
183pub struct DeleteOptions {
184 pub lazy: bool,
185}
186
187/// Options for [`Table::update`].
188#[derive(Clone, Debug, Default, Deserialize, Serialize, TS)]
189pub struct UpdateOptions {
190 pub port_id: Option<u32>,
191 pub format: Option<TableReadFormat>,
192}
193
194/// Result of a call to [`Table::validate_expressions`], containing a schema
195/// for valid expressions and error messages for invalid ones.
196#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
197pub struct ExprValidationResult {
198 pub expression_schema: Schema,
199 pub errors: HashMap<String, table_validate_expr_resp::ExprValidationError>,
200 pub expression_alias: HashMap<String, String>,
201}
202
203/// [`Table`] is Perspective's columnar data frame, analogous to a Pandas/Polars
204/// `DataFrame` or Apache Arrow, supporting append & in-place updates, removal
205/// by index, and update notifications.
206///
207/// A [`Table`] contains columns, each of which have a unique name, are strongly
208/// and consistently typed, and contains rows of data conforming to the column's
209/// type. Each column in a [`Table`] must have the same number of rows, though
210/// not every row must contain data; null-values are used to indicate missing
211/// values in the dataset. The schema of a [`Table`] is _immutable after
212/// creation_, which means the column names and data types cannot be changed
213/// after the [`Table`] has been created. Columns cannot be added or deleted
214/// after creation either, but a [`View`] can be used to select an arbitrary set
215/// of columns from the [`Table`].
216#[derive(Clone)]
217pub struct Table {
218 name: String,
219 client: Client,
220 options: TableOptions,
221
222 /// If this table is constructed from a View, the view's on_update callback
223 /// is wired into this table. So, we store the token to clean it up properly
224 /// on destruction.
225 pub(crate) view_update_token: Option<u32>,
226}
227
228assert_table_api!(Table);
229
230impl PartialEq for Table {
231 fn eq(&self, other: &Self) -> bool {
232 self.name == other.name && self.client == other.client
233 }
234}
235
236impl Table {
237 pub(crate) fn new(name: String, client: Client, options: TableOptions) -> Self {
238 Table {
239 name,
240 client,
241 options,
242 view_update_token: None,
243 }
244 }
245
246 fn client_message(&self, req: ClientReq) -> Request {
247 Request {
248 msg_id: self.client.gen_id(),
249 entity_id: self.name.clone(),
250 client_req: Some(req),
251 }
252 }
253
254 /// Get a copy of the [`Client`] this [`Table`] came from.
255 pub fn get_client(&self) -> Client {
256 self.client.clone()
257 }
258
259 /// Get a metadata dictionary of the `perspective_server::Server`'s
260 /// features, which is (currently) implementation specific, but there is
261 /// only one implementation.
262 pub async fn get_features(&self) -> ClientResult<Features> {
263 self.client.get_features().await
264 }
265
266 /// Returns the name of the index column for the table.
267 ///
268 /// # Examples
269 ///
270 /// ```no_run
271 /// # use perspective_client::{Client, TableData, TableInitOptions, UpdateData};
272 /// # async fn run() -> Result<(), Box<dyn std::error::Error>> {
273 /// # let client: Client = todo!();
274 /// let options = TableInitOptions {
275 /// index: Some("x".to_string()),
276 /// ..TableInitOptions::default()
277 /// };
278 /// let data = TableData::Update(UpdateData::Csv("x,y\n1,2\n3,4".into()));
279 /// let table = client.table(data, options).await?;
280 /// let index = table.get_index();
281 /// # Ok(()) }
282 /// ```
283 pub fn get_index(&self) -> Option<String> {
284 self.options.index.as_ref().map(|index| index.to_owned())
285 }
286
287 /// Returns the user-specified row limit for this table.
288 pub fn get_limit(&self) -> Option<u32> {
289 self.options.limit.as_ref().map(|limit| *limit)
290 }
291
292 /// Returns the user-specified name for this table, or the auto-generated
293 /// name if a name was not specified when the table was created.
294 pub fn get_name(&self) -> &str {
295 self.name.as_str()
296 }
297
298 /// Removes all the rows in the [`Table`], but preserves everything else
299 /// including the schema, index, and any callbacks or registered
300 /// [`View`] instances.
301 ///
302 /// Calling [`Table::clear`], like [`Table::update`] and [`Table::remove`],
303 /// will trigger an update event to any registered listeners via
304 /// [`View::on_update`].
305 pub async fn clear(&self) -> ClientResult<()> {
306 self.replace(UpdateData::JsonRows("[]".to_owned())).await
307 }
308
309 /// Delete this [`Table`] and cleans up associated resources.
310 ///
311 /// [`Table`]s do not stop consuming resources or processing updates when
312 /// they are garbage collected in their host language - you must call
313 /// this method to reclaim these.
314 ///
315 /// # Arguments
316 ///
317 /// - `options` An options dictionary.
318 /// - `lazy` Whether to delete this [`Table`] _lazily_. When false (the
319 /// default), the delete will occur immediately, assuming it has no
320 /// [`View`] instances registered to it (which must be deleted first,
321 /// otherwise this method will throw an error). When true, the
322 /// [`Table`] will only be marked for deltion once its [`View`]
323 /// dependency count reaches 0.
324 ///
325 /// # Examples
326 ///
327 /// ```no_run
328 /// # use perspective_client::{Client, DeleteOptions, TableData, TableInitOptions, UpdateData};
329 /// # async fn run() -> Result<(), Box<dyn std::error::Error>> {
330 /// # let client: Client = todo!();
331 /// let opts = TableInitOptions::default();
332 /// let data = TableData::Update(UpdateData::Csv("x,y\n1,2\n3,4".into()));
333 /// let table = client.table(data, opts).await?;
334 ///
335 /// // ...
336 ///
337 /// table.delete(DeleteOptions::default()).await?;
338 /// # Ok(()) }
339 /// ```
340 pub async fn delete(&self, options: DeleteOptions) -> ClientResult<()> {
341 let msg = self.client_message(ClientReq::TableDeleteReq(TableDeleteReq {
342 is_immediate: !options.lazy,
343 }));
344
345 match self.client.oneshot(&msg).await? {
346 ClientResp::TableDeleteResp(_) => Ok(()),
347 resp => Err(resp.into()),
348 }
349 }
350
351 /// Returns the column names of this [`Table`] in "natural" order (the
352 /// ordering implied by the input format).
353 ///
354 /// # Examples
355 ///
356 /// ```no_run
357 /// # use perspective_client::Table;
358 /// # async fn run() -> Result<(), Box<dyn std::error::Error>> {
359 /// # let table: Table = todo!();
360 /// let columns = table.columns().await?;
361 /// # Ok(()) }
362 /// ```
363 pub async fn columns(&self) -> ClientResult<Vec<String>> {
364 let msg = self.client_message(ClientReq::TableSchemaReq(TableSchemaReq {}));
365 match self.client.oneshot(&msg).await? {
366 ClientResp::TableSchemaResp(TableSchemaResp { schema }) => Ok(schema
367 .map(|x| x.schema.into_iter().map(|x| x.name.to_owned()).collect())
368 .unwrap()),
369 resp => Err(resp.into()),
370 }
371 }
372
373 /// Returns the number of rows in a [`Table`].
374 pub async fn size(&self) -> ClientResult<usize> {
375 let msg = self.client_message(ClientReq::TableSizeReq(TableSizeReq {}));
376 match self.client.oneshot(&msg).await? {
377 ClientResp::TableSizeResp(TableSizeResp { size }) => Ok(size as usize),
378 resp => Err(resp.into()),
379 }
380 }
381
382 /// Returns a table's [`Schema`], a mapping of column names to column types.
383 ///
384 /// The mapping of a [`Table`]'s column names to data types is referred to
385 /// as a [`Schema`]. Each column has a unique name and a data type, one
386 /// of:
387 ///
388 /// - `"boolean"` - A boolean type
389 /// - `"date"` - A timesonze-agnostic date type (month/day/year)
390 /// - `"datetime"` - A millisecond-precision datetime type in the UTC
391 /// timezone
392 /// - `"float"` - A 64 bit float
393 /// - `"integer"` - A signed 32 bit integer (the integer type supported by
394 /// JavaScript)
395 /// - `"string"` - A [`String`] data type (encoded internally as a
396 /// _dictionary_)
397 ///
398 /// Note that all [`Table`] columns are _nullable_, regardless of the data
399 /// type.
400 pub async fn schema(&self) -> ClientResult<Schema> {
401 let msg = self.client_message(ClientReq::TableSchemaReq(TableSchemaReq {}));
402 match self.client.oneshot(&msg).await? {
403 ClientResp::TableSchemaResp(TableSchemaResp { schema }) => Ok(schema
404 .map(|x| {
405 x.schema
406 .into_iter()
407 .map(|x| (x.name, ColumnType::try_from(x.r#type).unwrap()))
408 .collect()
409 })
410 .unwrap()),
411 resp => Err(resp.into()),
412 }
413 }
414
415 /// Create a unique channel ID on this [`Table`], which allows
416 /// `View::on_update` callback calls to be associated with the
417 /// `Table::update` which caused them.
418 pub async fn make_port(&self) -> ClientResult<i32> {
419 let msg = self.client_message(ClientReq::TableMakePortReq(TableMakePortReq {}));
420 match self.client.oneshot(&msg).await? {
421 ClientResp::TableMakePortResp(TableMakePortResp { port_id }) => Ok(port_id as i32),
422 _ => Err(ClientError::Unknown("make_port".to_string())),
423 }
424 }
425
426 /// Register a callback which is called exactly once, when this [`Table`] is
427 /// deleted with the [`Table::delete`] method.
428 ///
429 /// [`Table::on_delete`] resolves when the subscription message is sent, not
430 /// when the _delete_ event occurs.
431 pub async fn on_delete(
432 &self,
433 on_delete: Box<dyn Fn() + Send + Sync + 'static>,
434 ) -> ClientResult<u32> {
435 let callback = move |resp: Response| match resp.client_resp {
436 Some(ClientResp::TableOnDeleteResp(_)) => {
437 on_delete();
438 Ok(())
439 },
440 resp => Err(resp.into()),
441 };
442
443 let msg = self.client_message(ClientReq::TableOnDeleteReq(TableOnDeleteReq {}));
444 self.client.subscribe_once(&msg, Box::new(callback)).await?;
445 Ok(msg.msg_id)
446 }
447
448 /// Removes a listener with a given ID, as returned by a previous call to
449 /// [`Table::on_delete`].
450 pub async fn remove_delete(&self, callback_id: u32) -> ClientResult<()> {
451 let msg = self.client_message(ClientReq::TableRemoveDeleteReq(TableRemoveDeleteReq {
452 id: callback_id,
453 }));
454
455 match self.client.oneshot(&msg).await? {
456 ClientResp::TableRemoveDeleteResp(_) => Ok(()),
457 resp => Err(resp.into()),
458 }
459 }
460
461 /// Removes rows from this [`Table`] with the `index` column values
462 /// supplied.
463 ///
464 /// # Arguments
465 ///
466 /// - `indices` - A list of `index` column values for rows that should be
467 /// removed.
468 ///
469 /// # Examples
470 ///
471 /// ```no_run
472 /// # use perspective_client::{Table, UpdateData};
473 /// # async fn run() -> Result<(), Box<dyn std::error::Error>> {
474 /// # let table: Table = todo!();
475 /// table
476 /// .remove(UpdateData::Csv("index\n1\n2\n3".into()))
477 /// .await?;
478 /// # Ok(()) }
479 /// ```
480 pub async fn remove(&self, input: UpdateData) -> ClientResult<()> {
481 let msg = self.client_message(ClientReq::TableRemoveReq(TableRemoveReq {
482 data: Some(input.into()),
483 }));
484
485 match self.client.oneshot(&msg).await? {
486 ClientResp::TableRemoveResp(_) => Ok(()),
487 resp => Err(resp.into()),
488 }
489 }
490
491 /// Replace all rows in this [`Table`] with the input data, coerced to this
492 /// [`Table`]'s existing [`Schema`], notifying any derived [`View`] and
493 /// [`View::on_update`] callbacks.
494 ///
495 /// Calling [`Table::replace`] is an easy way to replace _all_ the data in a
496 /// [`Table`] without losing any derived [`View`] instances or
497 /// [`View::on_update`] callbacks. [`Table::replace`] does _not_ infer
498 /// data types like [`Client::table`] does, rather it _coerces_ input
499 /// data to the `Schema` like [`Table::update`]. If you need a [`Table`]
500 /// with a different `Schema`, you must create a new one.
501 ///
502 /// # Examples
503 ///
504 /// ```no_run
505 /// # use perspective_client::{Table, UpdateData};
506 /// # async fn run() -> Result<(), Box<dyn std::error::Error>> {
507 /// # let table: Table = todo!();
508 /// let data = UpdateData::Csv("x,y\n1,2".into());
509 /// table.replace(data).await?;
510 /// # Ok(()) }
511 /// ```
512 pub async fn replace(&self, input: UpdateData) -> ClientResult<()> {
513 let msg = self.client_message(ClientReq::TableReplaceReq(TableReplaceReq {
514 data: Some(input.into()),
515 }));
516
517 match self.client.oneshot(&msg).await? {
518 ClientResp::TableReplaceResp(_) => Ok(()),
519 resp => Err(resp.into()),
520 }
521 }
522
523 /// Updates the rows of this table and any derived [`View`] instances.
524 ///
525 /// Calling [`Table::update`] will trigger the [`View::on_update`] callbacks
526 /// register to derived [`View`], and the call itself will not resolve until
527 /// _all_ derived [`View`]'s are notified.
528 ///
529 /// When updating a [`Table`] with an `index`, [`Table::update`] supports
530 /// partial updates, by omitting columns from the update data.
531 ///
532 /// # Arguments
533 ///
534 /// - `input` - The input data for this [`Table`]. The schema of a [`Table`]
535 /// is immutable after creation, so this method cannot be called with a
536 /// schema.
537 /// - `options` - Options for this update step - see [`UpdateOptions`].
538 ///
539 /// # Examples
540 ///
541 /// ```no_run
542 /// # use perspective_client::{Table, UpdateData, UpdateOptions};
543 /// # async fn run() -> Result<(), Box<dyn std::error::Error>> {
544 /// # let table: Table = todo!();
545 /// let data = UpdateData::Csv("x,y\n1,2".into());
546 /// let opts = UpdateOptions::default();
547 /// table.update(data, opts).await?;
548 /// # Ok(()) }
549 /// ```
550 pub async fn update(&self, input: UpdateData, options: UpdateOptions) -> ClientResult<()> {
551 let msg = self.client_message(ClientReq::TableUpdateReq(TableUpdateReq {
552 data: Some(input.into()),
553 port_id: options.port_id.unwrap_or(0),
554 }));
555
556 match self.client.oneshot(&msg).await? {
557 ClientResp::TableUpdateResp(_) => Ok(()),
558 resp => Err(resp.into()),
559 }
560 }
561
562 /// Validates the given expressions.
563 pub async fn validate_expressions(
564 &self,
565 expressions: Expressions,
566 ) -> ClientResult<ExprValidationResult> {
567 let msg = self.client_message(ClientReq::TableValidateExprReq(TableValidateExprReq {
568 column_to_expr: expressions.0,
569 }));
570
571 match self.client.oneshot(&msg).await? {
572 ClientResp::TableValidateExprResp(result) => Ok(ExprValidationResult {
573 errors: result.errors,
574 expression_alias: result.expression_alias,
575 expression_schema: result
576 .expression_schema
577 .into_iter()
578 .map(|(x, y)| (x, ColumnType::try_from(y).unwrap()))
579 .collect(),
580 }),
581 resp => Err(resp.into()),
582 }
583 }
584
585 /// Create a new [`View`] from this table with a specified
586 /// [`ViewConfigUpdate`].
587 ///
588 /// See [`View`] struct.
589 ///
590 /// # Examples
591 ///
592 /// ```no_run
593 /// # use std::collections::HashMap;
594 /// # use perspective_client::Table;
595 /// # use perspective_client::config::*;
596 /// # async fn run() -> Result<(), Box<dyn std::error::Error>> {
597 /// # let table: Table = todo!();
598 /// let view = table
599 /// .view(Some(ViewConfigUpdate {
600 /// columns: Some(vec![Some("Sales".into())]),
601 /// aggregates: Some(HashMap::from_iter(vec![("Sales".into(), "sum".into())])),
602 /// group_by: Some(vec!["Region".into(), "Country".into()]),
603 /// filter: Some(vec![Filter::new("Category", "in", &[
604 /// "Furniture",
605 /// "Technology",
606 /// ])]),
607 /// ..ViewConfigUpdate::default()
608 /// }))
609 /// .await?;
610 /// # Ok(()) }
611 /// ```
612 pub async fn view(&self, config: Option<ViewConfigUpdate>) -> ClientResult<View> {
613 let view_name = randid();
614 let msg = Request {
615 msg_id: self.client.gen_id(),
616 entity_id: self.name.clone(),
617 client_req: ClientReq::TableMakeViewReq(TableMakeViewReq {
618 view_id: view_name.clone(),
619 config: config.map(|x| x.into()),
620 })
621 .into(),
622 };
623
624 match self.client.oneshot(&msg).await? {
625 ClientResp::TableMakeViewResp(TableMakeViewResp { view_id })
626 if view_id == view_name =>
627 {
628 Ok(View::new(view_name, self.client.clone()))
629 },
630 resp => Err(resp.into()),
631 }
632 }
633}