Struct perspective_client::View
source · pub struct View {
pub name: String,
/* private fields */
}Fields§
§name: StringImplementations§
source§impl View
impl View
pub fn new(name: String, client: Client) -> Self
sourcepub async fn column_paths(&self) -> ClientResult<Vec<String>>
pub async fn column_paths(&self) -> ClientResult<Vec<String>>
Returns an array of strings containing the column paths of the View without any of the source columns.
A column path shows the columns that a given cell belongs to after pivots are applied.
sourcepub async fn col_to_js_typed_array(
&self,
_column: &str
) -> ClientResult<Vec<u8>>
pub async fn col_to_js_typed_array( &self, _column: &str ) -> ClientResult<Vec<u8>>
Serializes a view column into a TypedArray.
sourcepub async fn dimensions(&self) -> ClientResult<ViewDimensionsResp>
pub async fn dimensions(&self) -> ClientResult<ViewDimensionsResp>
Returns this View’s dimensions, row and column count, as well as those of
the crate::Table from which it was derived.
num_table_rows- The number of rows in the underlyingcrate::Table.num_table_columns- The number of columns in the underlyingcrate::Table(including theindexcolumn if thiscrate::Tablewas constructed with one).num_view_rows- The number of rows in thisView. If thisViewhas agroup_byclause,num_view_rowswill also include aggregated rows.num_view_columns- The number of columns in thisView. If thisViewhas asplit_byclause,num_view_columnswill include all column paths, e.g. the number ofcolumnsclause times the number ofsplit_bygroups.
sourcepub async fn expression_schema(
&self
) -> ClientResult<HashMap<String, ColumnType>>
pub async fn expression_schema( &self ) -> ClientResult<HashMap<String, ColumnType>>
The expression schema of this view, which contains only the expressions created on this view.
A schema is an Object, the keys of which are the columns of this view, and the values are their string type names. If this view is aggregated, these will be the aggregated types; otherwise these types will be the same as the columns in the underlying table.
sourcepub async fn get_config(&self) -> ClientResult<ViewConfig>
pub async fn get_config(&self) -> ClientResult<ViewConfig>
A copy of the config object passed to the [Table::view] method which created this View.
sourcepub async fn num_rows(&self) -> ClientResult<u32>
pub async fn num_rows(&self) -> ClientResult<u32>
The number of aggregated rows in this view. This is affected by the “group_by” configuration parameter supplied to this view’s contructor.
§Returns
The number of aggregated rows.
sourcepub async fn schema(&self) -> ClientResult<HashMap<String, ColumnType>>
pub async fn schema(&self) -> ClientResult<HashMap<String, ColumnType>>
The schema of this view.
A schema is an Object, the keys of which are the columns of this view, and the values are their string type names. If this view is aggregated, theses will be the aggregated types; otherwise these types will be the same as the columns in the underlying table.
§Examples
// Create a view
const view = await table.view({
columns: ["a", "b"],
});
const schema = await view.schema(); // {a: "float", b: "string"}
sourcepub async fn to_arrow(&self, window: ViewWindow) -> ClientResult<Vec<u8>>
pub async fn to_arrow(&self, window: ViewWindow) -> ClientResult<Vec<u8>>
Serializes a view to the Apache Arrow data format.
sourcepub async fn to_columns_string(
&self,
window: ViewWindow
) -> ClientResult<String>
pub async fn to_columns_string( &self, window: ViewWindow ) -> ClientResult<String>
Serializes this view to a string of JSON data. Useful if you want to save additional round trip serialize/deserialize cycles.
sourcepub async fn to_json_string(&self, window: ViewWindow) -> ClientResult<String>
pub async fn to_json_string(&self, window: ViewWindow) -> ClientResult<String>
sourcepub async fn to_csv(&self, window: ViewWindow) -> ClientResult<String>
pub async fn to_csv(&self, window: ViewWindow) -> ClientResult<String>
Serializes this view to CSV data in a standard format.
sourcepub async fn delete(&self) -> ClientResult<()>
pub async fn delete(&self) -> ClientResult<()>
Delete this View and clean up all resources associated with it. View objects do not stop consuming resources or processing updates when they are garbage collected - you must call this method to reclaim these.
sourcepub async fn get_min_max(
&self,
column_name: String
) -> ClientResult<(String, String)>
pub async fn get_min_max( &self, column_name: String ) -> ClientResult<(String, String)>
Calculates the [min, max] of the leaf nodes of a column column_name.
§Returns
A tuple of [min, max], whose types are column and aggregate dependent.
sourcepub async fn on_update(
&self,
on_update: Box<dyn Fn(OnUpdateArgs) + Send + Sync + 'static>,
options: OnUpdateOptions
) -> ClientResult<u32>
pub async fn on_update( &self, on_update: Box<dyn Fn(OnUpdateArgs) + Send + Sync + 'static>, options: OnUpdateOptions ) -> ClientResult<u32>
Register a callback with this View. Whenever the view’s underlying table emits an update, this callback will be invoked with an object containing port_id, indicating which port the update fired on, and optionally delta, which is the new data that was updated for each cell or each row.
§Arguments
on_update- A callback function invoked on update, which receives an object with two keys:port_id, indicating which port the update was triggered on, anddelta, whose value is dependent on the mode parameter.options- If this is provided asOnUpdateOptions { mode: Some(OnUpdateMode::Row) }, thendeltais an Arrow of the updated rows. Otherwisedeltawill beOption::None.
§Examples
// Attach an `on_update` callback
view.on_update((updated) => console.log(updated.port_id));
// `on_update` with row deltas
view.on_update((updated) => console.log(updated.delta), { mode: "row" });
sourcepub async fn remove_update(&self, update_id: u32) -> ClientResult<()>
pub async fn remove_update(&self, update_id: u32) -> ClientResult<()>
Unregister a previously registered update callback with this view.
§Example
// remove an `on_update` callback
const callback = () => console.log("Updated!");
view.remove_update(callback);
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 with this view. Whenever the view is deleted, this callback will be invoked.
§Example
// attach an `on_delete` callback
view.on_delete(() => console.log("Deleted!"));
sourcepub async fn remove_delete(&self, callback_id: u32) -> ClientResult<()>
pub async fn remove_delete(&self, callback_id: u32) -> ClientResult<()>
Unregister a previously registered delete callback with this view.
§Example
// remove an `on_delete` callback
const callback = () => console.log("Deleted!");
view.remove_delete(callback);
sourcepub async fn collapse(&self, row_index: i32) -> ClientResult<i64>
pub async fn collapse(&self, row_index: i32) -> ClientResult<i64>
Collapses the row at index row_index.
This is used during a pivot.
§Examples
// make table
// make view with pivot
// collapse a row.
sourcepub async fn expand(&self, row_index: i32) -> ClientResult<i64>
pub async fn expand(&self, row_index: i32) -> ClientResult<i64>
Expands the row at index row_index.
This is used during a pivot.
§Examples
// make table
// make view with pivot
// expand a row.
sourcepub async fn set_depth(&self, depth: i32) -> ClientResult<()>
pub async fn set_depth(&self, depth: i32) -> ClientResult<()>
Set expansion depth of the pivot tree.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for View
impl !RefUnwindSafe for View
impl Send for View
impl Sync for View
impl Unpin for View
impl !UnwindSafe for View
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> 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