pub struct Table { /* private fields */ }Expand description
Table is Perspective’s columnar data frame, analogous to a Pandas/Polars
DataFrame or Apache Arrow, supporting append & in-place updates, removal
by index, and update notifications.
A Table contains columns, each of which have a unique name, are strongly
and consistently typed, and contains rows of data conforming to the column’s
type. Each column in a Table must have the same number of rows, though
not every row must contain data; null-values are used to indicate missing
values in the dataset. The schema of a Table is immutable after
creation, which means the column names and data types cannot be changed
after the Table has been created. Columns cannot be added or deleted
after creation either, but a View can be used to select an arbitrary set
of columns from the Table.
Implementations§
Source§impl Table
 
impl Table
Sourcepub fn get_client(&self) -> Client
 
pub fn get_client(&self) -> Client
Sourcepub async fn get_features(&self) -> ClientResult<Features>
 
pub async fn get_features(&self) -> ClientResult<Features>
Get a metadata dictionary of the perspective_server::Server’s
features, which is (currently) implementation specific, but there is
only one implementation.
Sourcepub fn get_index(&self) -> Option<String>
 
pub fn get_index(&self) -> Option<String>
Returns the name of the index column for the table.
§Examples
let options = TableInitOptions {
    index: Some("x".to_string()),
    ..default()
};
let table = client.table("x,y\n1,2\n3,4", options).await;
let index = table.get_index()Sourcepub fn get_name(&self) -> &str
 
pub fn get_name(&self) -> &str
Returns the user-specified name for this table, or the auto-generated name if a name was not specified when the table was created.
Sourcepub async fn clear(&self) -> ClientResult<()>
 
pub async fn clear(&self) -> ClientResult<()>
Removes all the rows in the Table, but preserves everything else
including the schema, index, and any callbacks or registered
View instances.
Calling Table::clear, like Table::update and Table::remove,
will trigger an update event to any registered listeners via
View::on_update.
Sourcepub async fn delete(&self, options: DeleteOptions) -> ClientResult<()>
 
pub async fn delete(&self, options: DeleteOptions) -> ClientResult<()>
Delete this Table and cleans up associated resources.
Tables do not stop consuming resources or processing updates when
they are garbage collected in their host language - you must call
this method to reclaim these.
§Arguments
optionsAn options dictionary.lazyWhether to delete thisTablelazily. When false (the default), the delete will occur immediately, assuming it has noViewinstances registered to it (which must be deleted first, otherwise this method will throw an error). When true, theTablewill only be marked for deltion once itsViewdependency count reaches 0.
§Examples
let opts = TableInitOptions::default();
let data = TableData::Update(UpdateData::Csv("x,y\n1,2\n3,4".into()));
let table = client.table(data, opts).await?;
// ...
table.delete(DeleteOptions::default()).await?;Sourcepub async fn columns(&self) -> ClientResult<Vec<String>>
 
pub async fn columns(&self) -> ClientResult<Vec<String>>
Sourcepub async fn size(&self) -> ClientResult<usize>
 
pub async fn size(&self) -> ClientResult<usize>
Returns the number of rows in a Table.
Sourcepub async fn schema(&self) -> ClientResult<HashMap<String, ColumnType>>
 
pub async fn schema(&self) -> ClientResult<HashMap<String, ColumnType>>
Returns a table’s [Schema], a mapping of column names to column types.
The mapping of a Table’s column names to data types is referred to
as a [Schema]. Each column has a unique name and a data type, one
of:
"boolean"- A boolean type"date"- A timesonze-agnostic date type (month/day/year)"datetime"- A millisecond-precision datetime type in the UTC timezone"float"- A 64 bit float"integer"- A signed 32 bit integer (the integer type supported by JavaScript)"string"- AStringdata type (encoded internally as a dictionary)
Note that all Table columns are nullable, regardless of the data
type.
Sourcepub async fn make_port(&self) -> ClientResult<i32>
 
pub async fn make_port(&self) -> ClientResult<i32>
Create a unique channel ID on this Table, which allows
View::on_update callback calls to be associated with the
Table::update which caused them.
Sourcepub async fn on_delete(
    &self,
    on_delete: Box<dyn Fn() + Send + Sync + 'static>,
) -> ClientResult<u32>
 
pub async fn on_delete( &self, on_delete: Box<dyn Fn() + Send + Sync + 'static>, ) -> ClientResult<u32>
Register a callback which is called exactly once, when this Table is
deleted with the Table::delete method.
Table::on_delete resolves when the subscription message is sent, not
when the delete event occurs.
Sourcepub async fn remove_delete(&self, callback_id: u32) -> ClientResult<()>
 
pub async fn remove_delete(&self, callback_id: u32) -> ClientResult<()>
Removes a listener with a given ID, as returned by a previous call to
Table::on_delete.
Sourcepub async fn remove(&self, input: UpdateData) -> ClientResult<()>
 
pub async fn remove(&self, input: UpdateData) -> ClientResult<()>
Sourcepub async fn replace(&self, input: UpdateData) -> ClientResult<()>
 
pub async fn replace(&self, input: UpdateData) -> ClientResult<()>
Replace all rows in this Table with the input data, coerced to this
Table’s existing [Schema], notifying any derived View and
View::on_update callbacks.
Calling Table::replace is an easy way to replace all the data in a
Table without losing any derived View instances or
View::on_update callbacks. Table::replace does not infer
data types like Client::table does, rather it coerces input
data to the Schema like Table::update. If you need a Table
with a different Schema, you must create a new one.
§Examples
let data = UpdateData::Csv("x,y\n1,2".into());
let opts = UpdateOptions::default();
table.replace(data, opts).await?;Sourcepub async fn update(
    &self,
    input: UpdateData,
    options: UpdateOptions,
) -> ClientResult<()>
 
pub async fn update( &self, input: UpdateData, options: UpdateOptions, ) -> ClientResult<()>
Updates the rows of this table and any derived View instances.
Calling Table::update will trigger the View::on_update callbacks
register to derived View, and the call itself will not resolve until
all derived View’s are notified.
When updating a Table with an index, Table::update supports
partial updates, by omitting columns from the update data.
§Arguments
input- The input data for thisTable. The schema of aTableis immutable after creation, so this method cannot be called with a schema.options- Options for this update step - seeUpdateOptions.
§Examples
let data = UpdateData::Csv("x,y\n1,2".into());
let opts = UpdateOptions::default();
table.update(data, opts).await?;Sourcepub async fn validate_expressions(
    &self,
    expressions: Expressions,
) -> ClientResult<ExprValidationResult>
 
pub async fn validate_expressions( &self, expressions: Expressions, ) -> ClientResult<ExprValidationResult>
Validates the given expressions.
Sourcepub async fn view(&self, config: Option<ViewConfigUpdate>) -> ClientResult<View>
 
pub async fn view(&self, config: Option<ViewConfigUpdate>) -> ClientResult<View>
Create a new View from this table with a specified
ViewConfigUpdate.
See View struct.
§Examples
use crate::config::*;
let view = table
    .view(Some(ViewConfigUpdate {
        columns: Some(vec![Some("Sales".into())]),
        aggregates: Some(HashMap::from_iter(vec![("Sales".into(), "sum".into())])),
        group_by: Some(vec!["Region".into(), "Country".into()]),
        filter: Some(vec![Filter::new("Category", "in", &[
            "Furniture",
            "Technology",
        ])]),
        ..ViewConfigUpdate::default()
    }))
    .await?;Trait Implementations§
Auto Trait Implementations§
impl Freeze for Table
impl !RefUnwindSafe for Table
impl Send for Table
impl Sync for Table
impl Unpin for Table
impl !UnwindSafe for Table
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
    T: ?Sized,
 
impl<T> BorrowMut<T> for Twhere
    T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
 
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
    T: Clone,
 
impl<T> CloneToUninit for Twhere
    T: Clone,
Source§impl<T> Instrument for T
 
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
 
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
 
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
 
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
 
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
 
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more