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.
View
s 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
impl View
Sourcepub async fn column_paths(
&self,
window: Option<JsColumnWindow>,
) -> ApiResult<JsValue>
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.
Sourcepub async fn dimensions(&self) -> ApiResult<JsValue>
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 underlyingcrate::Table
.num_table_columns
- The number of columns in the underlyingcrate::Table
(including theindex
column if thiscrate::Table
was constructed with one).num_view_rows
- The number of rows in thisView
. If thisView
has agroup_by
clause,num_view_rows
will also include aggregated rows.num_view_columns
- The number of columns in thisView
. If thisView
has asplit_by
clause,num_view_columns
will include all column paths, e.g. the number ofcolumns
clause times the number ofsplit_by
groups.
Sourcepub async fn expression_schema(&self) -> ApiResult<JsValue>
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.
Sourcepub async fn get_config(&self) -> ApiResult<JsValue>
pub async fn get_config(&self) -> ApiResult<JsValue>
A copy of the config object passed to the Table::view
method which
created this View
.
Sourcepub async fn get_min_max(&self, name: String) -> ApiResult<Array>
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.
Sourcepub async fn schema(&self) -> ApiResult<JsValue>
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.
Sourcepub async fn to_arrow(
&self,
window: Option<JsViewWindow>,
) -> ApiResult<ArrayBuffer>
pub async fn to_arrow( &self, window: Option<JsViewWindow>, ) -> ApiResult<ArrayBuffer>
Serializes a View
to the Apache Arrow data format.
Sourcepub async fn to_columns_string(
&self,
window: Option<JsViewWindow>,
) -> ApiResult<String>
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.
Sourcepub async fn to_columns(
&self,
window: Option<JsViewWindow>,
) -> ApiResult<Object>
pub async fn to_columns( &self, window: Option<JsViewWindow>, ) -> ApiResult<Object>
Serializes this View
to JavaScript objects in a column-oriented
format.
Sourcepub async fn to_json_string(
&self,
window: Option<JsViewWindow>,
) -> ApiResult<String>
pub async fn to_json_string( &self, window: Option<JsViewWindow>, ) -> ApiResult<String>
Render this View
as a JSON string.
Sourcepub async fn to_json(&self, window: Option<JsViewWindow>) -> ApiResult<Array>
pub async fn to_json(&self, window: Option<JsViewWindow>) -> ApiResult<Array>
Serializes this View
to JavaScript objects in a row-oriented
format.
Sourcepub async fn to_ndjson(&self, window: Option<JsViewWindow>) -> ApiResult<String>
pub async fn to_ndjson(&self, window: Option<JsViewWindow>) -> ApiResult<String>
Sourcepub async fn to_csv(&self, window: Option<JsViewWindow>) -> ApiResult<String>
pub async fn to_csv(&self, window: Option<JsViewWindow>) -> ApiResult<String>
Serializes this View
to CSV data in a standard format.
Sourcepub fn on_update(
&self,
on_update_js: Function,
options: Option<JsOnUpdateOptions>,
) -> ApiFuture<u32>
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, anddelta
, whose value is dependent on the mode parameter.options
- If this is provided asOnUpdateOptions { mode: Some(OnUpdateMode::Row) }
, thendelta
is an Arrow of the updated rows. Otherwisedelta
will beOption::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" });
Sourcepub async fn remove_update(&self, callback_id: u32) -> ApiResult<()>
pub async fn remove_update(&self, callback_id: u32) -> ApiResult<()>
Unregister a previously registered update callback with this View
.
§Arguments
id
- A callbackid
as returned by a recipricol call toView::on_update
.
Sourcepub async fn num_columns(&self) -> ApiResult<u32>
pub async fn num_columns(&self) -> ApiResult<u32>
Sourcepub fn remove_delete(&self, callback_id: u32) -> ApiFuture<()>
pub fn remove_delete(&self, callback_id: u32) -> ApiFuture<()>
Unregister a previously registered View::on_delete
callback.
Sourcepub async fn collapse(&self, row_index: u32) -> ApiResult<u32>
pub async fn collapse(&self, row_index: u32) -> ApiResult<u32>
Collapses the group_by
row at row_index
.
Trait Implementations§
Source§impl FromWasmAbi for View
impl FromWasmAbi for View
Source§impl IntoWasmAbi for View
impl IntoWasmAbi for View
Source§impl LongRefFromWasmAbi for View
impl LongRefFromWasmAbi for View
Source§impl OptionFromWasmAbi for View
impl OptionFromWasmAbi for View
Source§impl OptionIntoWasmAbi for View
impl OptionIntoWasmAbi for View
Source§impl RefFromWasmAbi for View
impl RefFromWasmAbi for View
Source§impl RefMutFromWasmAbi for View
impl RefMutFromWasmAbi for View
Source§impl TryFromJsValue for View
impl TryFromJsValue for View
Source§impl VectorFromWasmAbi for View
impl VectorFromWasmAbi for View
Source§impl VectorIntoWasmAbi for View
impl VectorIntoWasmAbi for View
impl SupportsConstructor for View
impl SupportsInstanceProperty for View
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> 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 moreSource§impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
Source§type Abi = <T as IntoWasmAbi>::Abi
type Abi = <T as IntoWasmAbi>::Abi
IntoWasmAbi::Abi
Source§fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
IntoWasmAbi::into_abi
, except that it may throw and never
return in the case of Err
.