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.
To construct a View
, call the Table::view
factory method. A
Table
can have as many View
s associated with it as you need -
Perspective conserves memory by relying on a single Table
to power
multiple View
s concurrently.
Implementations§
Source§impl View
impl View
Sourcepub fn column_paths(&self, py: Python<'_>) -> PyResult<Vec<String>>
pub fn column_paths(&self, py: Python<'_>) -> PyResult<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 fn to_columns_string(
&self,
py: Python<'_>,
window: Option<Py<PyDict>>,
) -> PyResult<String>
pub fn to_columns_string( &self, py: Python<'_>, window: Option<Py<PyDict>>, ) -> PyResult<String>
Renders this View
as a column-oriented JSON string. Useful if you
want to save additional round trip serialize/deserialize cycles.
Sourcepub fn to_json_string(
&self,
py: Python<'_>,
window: Option<Py<PyDict>>,
) -> PyResult<String>
pub fn to_json_string( &self, py: Python<'_>, window: Option<Py<PyDict>>, ) -> PyResult<String>
Renders this View
as a row-oriented JSON string.
Sourcepub fn to_records<'a>(
&self,
py: Python<'a>,
window: Option<Py<PyDict>>,
) -> PyResult<Bound<'a, PyAny>>
pub fn to_records<'a>( &self, py: Python<'a>, window: Option<Py<PyDict>>, ) -> PyResult<Bound<'a, PyAny>>
Renders this View
as a row-oriented Python list
.
Sourcepub fn to_json<'a>(
&self,
py: Python<'a>,
window: Option<Py<PyDict>>,
) -> PyResult<Bound<'a, PyAny>>
pub fn to_json<'a>( &self, py: Python<'a>, window: Option<Py<PyDict>>, ) -> PyResult<Bound<'a, PyAny>>
Renders this View
as a row-oriented Python list
.
Sourcepub fn to_columns<'a>(
&self,
py: Python<'a>,
window: Option<Py<PyDict>>,
) -> PyResult<Bound<'a, PyAny>>
pub fn to_columns<'a>( &self, py: Python<'a>, window: Option<Py<PyDict>>, ) -> PyResult<Bound<'a, PyAny>>
Renders this View
as a column-oriented Python dict
.
Sourcepub fn to_csv(
&self,
py: Python<'_>,
window: Option<Py<PyDict>>,
) -> PyResult<String>
pub fn to_csv( &self, py: Python<'_>, window: Option<Py<PyDict>>, ) -> PyResult<String>
Renders this View
as a CSV String
in a standard format.
Sourcepub fn to_dataframe(
&self,
py: Python<'_>,
window: Option<Py<PyDict>>,
) -> PyResult<Py<PyAny>>
pub fn to_dataframe( &self, py: Python<'_>, window: Option<Py<PyDict>>, ) -> PyResult<Py<PyAny>>
Renders this View
as a pandas.DataFrame
.
Sourcepub fn to_pandas(
&self,
py: Python<'_>,
window: Option<Py<PyDict>>,
) -> PyResult<Py<PyAny>>
pub fn to_pandas( &self, py: Python<'_>, window: Option<Py<PyDict>>, ) -> PyResult<Py<PyAny>>
Renders this View
as a pandas.DataFrame
.
Sourcepub fn to_polars(
&self,
py: Python<'_>,
window: Option<Py<PyDict>>,
) -> PyResult<Py<PyAny>>
pub fn to_polars( &self, py: Python<'_>, window: Option<Py<PyDict>>, ) -> PyResult<Py<PyAny>>
Renders this View
as a polars.DataFrame
.
Sourcepub fn to_arrow(
&self,
py: Python<'_>,
window: Option<Py<PyDict>>,
) -> PyResult<Py<PyBytes>>
pub fn to_arrow( &self, py: Python<'_>, window: Option<Py<PyDict>>, ) -> PyResult<Py<PyBytes>>
pub fn expand(&self, py: Python<'_>, index: u32) -> PyResult<u32>
pub fn collapse(&self, py: Python<'_>, index: u32) -> PyResult<u32>
Sourcepub fn dimensions(&self, py: Python<'_>) -> PyResult<Py<PyAny>>
pub fn dimensions(&self, py: Python<'_>) -> PyResult<Py<PyAny>>
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 fn expression_schema(
&self,
py: Python<'_>,
) -> PyResult<HashMap<String, String>>
pub fn expression_schema( &self, py: Python<'_>, ) -> PyResult<HashMap<String, String>>
The expression schema of this View
, which contains only the
expressions created on this View
. See View::schema
for
details.
Sourcepub fn get_config(&self, py: Python<'_>) -> PyResult<Py<PyAny>>
pub fn get_config(&self, py: Python<'_>) -> PyResult<Py<PyAny>>
A copy of the [ViewConfig
] object passed to the Table::view
method
which created this View
.
Sourcepub fn get_min_max(
&self,
py: Python<'_>,
column_name: String,
) -> PyResult<(String, String)>
pub fn get_min_max( &self, py: Python<'_>, column_name: String, ) -> PyResult<(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 fn schema(&self, py: Python<'_>) -> PyResult<HashMap<String, String>>
pub fn schema(&self, py: Python<'_>) -> PyResult<HashMap<String, String>>
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 fn remove_delete(&self, py: Python<'_>, callback_id: u32) -> PyResult<()>
pub fn remove_delete(&self, py: Python<'_>, callback_id: u32) -> PyResult<()>
Unregister a previously registered View::on_delete
callback.
Sourcepub fn on_update(
&self,
py: Python<'_>,
callback: Py<PyAny>,
mode: Option<String>,
) -> PyResult<u32>
pub fn on_update( &self, py: Python<'_>, callback: Py<PyAny>, mode: Option<String>, ) -> PyResult<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
.
Sourcepub fn remove_update(&self, py: Python<'_>, callback_id: u32) -> PyResult<()>
pub fn remove_update(&self, py: Python<'_>, callback_id: u32) -> PyResult<()>
Unregister a previously registered update callback with this View
.
§Arguments
id
- A callbackid
as returned by a recipricol call toView::on_update
.
§Examples
let callback = |_| async { print!("Updated!") };
let cid = view.on_update(callback, OnUpdateOptions::default()).await?;
view.remove_update(cid).await?;
Trait Implementations§
Source§impl<'py> IntoPyObject<'py> for View
impl<'py> IntoPyObject<'py> for View
Source§type Output = Bound<'py, <View as IntoPyObject<'py>>::Target>
type Output = Bound<'py, <View as IntoPyObject<'py>>::Target>
Source§fn into_pyobject(
self,
py: Python<'py>,
) -> Result<<Self as IntoPyObject<'_>>::Output, <Self as IntoPyObject<'_>>::Error>
fn into_pyobject( self, py: Python<'py>, ) -> Result<<Self as IntoPyObject<'_>>::Output, <Self as IntoPyObject<'_>>::Error>
Source§impl PyClassBaseType for View
impl PyClassBaseType for View
type LayoutAsBase = PyClassObject<View>
type BaseNativeType = <View as PyClassImpl>::BaseNativeType
type Initializer = PyClassInitializer<View>
type PyClassMutability = <View as PyClassImpl>::PyClassMutability
Source§impl PyClassImpl for View
impl PyClassImpl for View
Source§const IS_BASETYPE: bool = true
const IS_BASETYPE: bool = true
Source§const IS_SUBCLASS: bool = false
const IS_SUBCLASS: bool = false
Source§const IS_MAPPING: bool = false
const IS_MAPPING: bool = false
Source§const IS_SEQUENCE: bool = false
const IS_SEQUENCE: bool = false
Source§const IS_IMMUTABLE_TYPE: bool = false
const IS_IMMUTABLE_TYPE: bool = false
Source§type ThreadChecker = SendablePyClass<View>
type ThreadChecker = SendablePyClass<View>
Source§type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
Source§type BaseNativeType = PyAny
type BaseNativeType = PyAny
PyAny
by default, and when you declare
#[pyclass(extends=PyDict)]
, it’s PyDict
.fn items_iter() -> PyClassItemsIter
fn lazy_type_object() -> &'static LazyTypeObject<Self>
fn dict_offset() -> Option<isize>
fn weaklist_offset() -> Option<isize>
Source§impl PyClassNewTextSignature<View> for PyClassImplCollector<View>
impl PyClassNewTextSignature<View> for PyClassImplCollector<View>
fn new_text_signature(self) -> Option<&'static str>
Source§impl PyMethods<View> for PyClassImplCollector<View>
impl PyMethods<View> for PyClassImplCollector<View>
fn py_methods(self) -> &'static PyClassItems
Source§impl PyTypeInfo for View
impl PyTypeInfo for View
Source§fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
Source§fn type_object(py: Python<'_>) -> Bound<'_, PyType>
fn type_object(py: Python<'_>) -> Bound<'_, PyType>
impl DerefToPyAny 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> 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<'py, T> IntoPyObjectExt<'py> for Twhere
T: IntoPyObject<'py>,
impl<'py, T> IntoPyObjectExt<'py> for Twhere
T: IntoPyObject<'py>,
Source§fn into_bound_py_any(self, py: Python<'py>) -> Result<Bound<'py, PyAny>, PyErr>
fn into_bound_py_any(self, py: Python<'py>) -> Result<Bound<'py, PyAny>, PyErr>
self
into an owned Python object, dropping type information.