View

Struct View 

Source
pub struct View(/* private fields */);
Expand description

The View struct is Perspective’s query and serialization interface. It represents a query on the Table’s dataset and is always created from an existing Table instance via the Table::view method.

Views are immutable with respect to the arguments provided to the Table::view method; to change these parameters, you must create a new View on the same Table. However, each View is live with respect to the Table’s data, and will (within a conflation window) update with the latest state as its parent Table updates, including incrementally recalculating all aggregates, pivots, filters, etc. View query parameters are composable, in that each parameter works independently and in conjunction with each other, and there is no limit to the number of pivots, filters, etc. which can be applied.

Implementations§

Source§

impl View

Source

pub async fn column_paths( &self, window: Option<JsColumnWindow>, ) -> ApiResult<JsValue>

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.

Source

pub async fn delete(self) -> ApiResult<()>

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.

Source

pub async fn dimensions(&self) -> ApiResult<JsValue>

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 underlying crate::Table.
  • num_table_columns - The number of columns in the underlying crate::Table (including the index column if this crate::Table was constructed with one).
  • num_view_rows - The number of rows in this View. If this View has a group_by clause, num_view_rows will also include aggregated rows.
  • num_view_columns - The number of columns in this View. If this View has a split_by clause, num_view_columns will include all column paths, e.g. the number of columns clause times the number of split_by groups.
Source

pub async fn expression_schema(&self) -> ApiResult<JsValue>

The expression schema of this View, which contains only the expressions created on this View. See View::schema for details.

Source

pub async fn get_config(&self) -> ApiResult<JsValue>

A copy of the config object passed to the Table::view method which created this View.

Source

pub async fn get_min_max(&self, name: String) -> ApiResult<Array>

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.

Source

pub async fn num_rows(&self) -> ApiResult<i32>

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.

Source

pub async fn schema(&self) -> ApiResult<JsValue>

The schema of this View.

The View schema differs from the schema returned by Table::schema; it may have different column names due to expressions or columns configs, or it maye have different column types due to the application og group_by and aggregates config. You can think of Table::schema as the input schema and View::schema as the output schema of a Perspective pipeline.

Source

pub async fn to_arrow( &self, window: Option<JsViewWindow>, ) -> ApiResult<ArrayBuffer>

Serializes a View to the Apache Arrow data format.

Source

pub async fn to_columns_string( &self, window: Option<JsViewWindow>, ) -> ApiResult<String>

Serializes this View to a string of JSON data. Useful if you want to save additional round trip serialize/deserialize cycles.

Source

pub async fn to_columns( &self, window: Option<JsViewWindow>, ) -> ApiResult<Object>

Serializes this View to JavaScript objects in a column-oriented format.

Source

pub async fn to_json_string( &self, window: Option<JsViewWindow>, ) -> ApiResult<String>

Render this View as a JSON string.

Source

pub async fn to_json(&self, window: Option<JsViewWindow>) -> ApiResult<Array>

Serializes this View to JavaScript objects in a row-oriented format.

Source

pub async fn to_ndjson(&self, window: Option<JsViewWindow>) -> ApiResult<String>

Renders this View as an NDJSON formatted String.

Source

pub async fn to_csv(&self, window: Option<JsViewWindow>) -> ApiResult<String>

Serializes this View to CSV data in a standard format.

Source

pub fn on_update( &self, on_update_js: Function, options: Option<JsOnUpdateOptions>, ) -> ApiFuture<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, and delta, whose value is dependent on the mode parameter.
  • options - If this is provided as OnUpdateOptions { mode: Some(OnUpdateMode::Row) }, then delta is an Arrow of the updated rows. Otherwise delta will be Option::None.
§JavaScript 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" });
Source

pub async fn remove_update(&self, callback_id: u32) -> ApiResult<()>

Unregister a previously registered update callback with this View.

§Arguments
Source

pub fn on_delete(&self, on_delete: Function) -> ApiFuture<u32>

Register a callback with this View. Whenever the View is deleted, this callback will be invoked.

Source

pub async fn num_columns(&self) -> ApiResult<u32>

The number of aggregated columns in this View. This is affected by the “split_by” configuration parameter supplied to this view’s contructor.

§Returns

The number of aggregated columns.

Source

pub fn remove_delete(&self, callback_id: u32) -> ApiFuture<()>

Unregister a previously registered View::on_delete callback.

Source

pub async fn collapse(&self, row_index: u32) -> ApiResult<u32>

Collapses the group_by row at row_index.

Source

pub async fn expand(&self, row_index: u32) -> ApiResult<u32>

Expand the group_by row at row_index.

Source

pub async fn set_depth(&self, depth: u32) -> ApiResult<()>

Set expansion depth of the group_by tree.

Trait Implementations§

Source§

impl Clone for View

Source§

fn clone(&self) -> View

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl From<View> for JsValue

Source§

fn from(value: View) -> Self

Converts to this type from the input type.
Source§

impl From<View> for View

Source§

fn from(value: View) -> Self

Converts to this type from the input type.
Source§

impl FromWasmAbi for View

Source§

type Abi = u32

The Wasm ABI type that this converts from when coming back out from the ABI boundary.
Source§

unsafe fn from_abi(js: u32) -> Self

Recover a Self from Self::Abi. Read more
Source§

impl IntoWasmAbi for View

Source§

type Abi = u32

The Wasm ABI type that this converts into when crossing the ABI boundary.
Source§

fn into_abi(self) -> u32

Convert self into Self::Abi so that it can be sent across the wasm ABI boundary.
Source§

impl LongRefFromWasmAbi for View

Source§

type Abi = u32

Same as RefFromWasmAbi::Abi
Source§

type Anchor = RcRef<View>

Same as RefFromWasmAbi::Anchor
Source§

unsafe fn long_ref_from_abi(js: Self::Abi) -> Self::Anchor

Same as RefFromWasmAbi::ref_from_abi
Source§

impl OptionFromWasmAbi for View

Source§

fn is_none(abi: &Self::Abi) -> bool

Tests whether the argument is a “none” instance. If so it will be deserialized as None, and otherwise it will be passed to FromWasmAbi.
Source§

impl OptionIntoWasmAbi for View

Source§

fn none() -> Self::Abi

Returns an ABI instance indicating “none”, which JS will interpret as the None branch of this option. Read more
Source§

impl RefFromWasmAbi for View

Source§

type Abi = u32

The Wasm ABI type references to Self are recovered from.
Source§

type Anchor = RcRef<View>

The type that holds the reference to Self for the duration of the invocation of the function that has an &Self parameter. This is required to ensure that the lifetimes don’t persist beyond one function call, and so that they remain anonymous.
Source§

unsafe fn ref_from_abi(js: Self::Abi) -> Self::Anchor

Recover a Self::Anchor from Self::Abi. Read more
Source§

impl RefMutFromWasmAbi for View

Source§

type Abi = u32

Same as RefFromWasmAbi::Abi
Source§

type Anchor = RcRefMut<View>

Same as RefFromWasmAbi::Anchor
Source§

unsafe fn ref_mut_from_abi(js: Self::Abi) -> Self::Anchor

Same as RefFromWasmAbi::ref_from_abi
Source§

impl TryFromJsValue for View

Source§

type Error = JsValue

The type returned in the event of a conversion error.
Source§

fn try_from_js_value(value: JsValue) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl VectorFromWasmAbi for View

Source§

type Abi = <Box<[JsValue]> as FromWasmAbi>::Abi

Source§

unsafe fn vector_from_abi(js: Self::Abi) -> Box<[View]>

Source§

impl VectorIntoJsValue for View

Source§

impl VectorIntoWasmAbi for View

Source§

type Abi = <Box<[JsValue]> as IntoWasmAbi>::Abi

Source§

fn vector_into_abi(vector: Box<[View]>) -> Self::Abi

Source§

impl WasmDescribe for View

Source§

impl WasmDescribeVector for View

Source§

impl SupportsConstructor for View

Source§

impl SupportsInstanceProperty for View

Source§

impl SupportsStaticProperty for View

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> ReturnWasmAbi for T
where T: IntoWasmAbi,

Source§

type Abi = <T as IntoWasmAbi>::Abi

Same as IntoWasmAbi::Abi
Source§

fn return_abi(self) -> <T as ReturnWasmAbi>::Abi

Same as IntoWasmAbi::into_abi, except that it may throw and never return in the case of Err.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more