Struct perspective_client::Table
source · pub struct Table { /* private fields */ }Expand description
Table is Perspective’s columnar data frame, analogous to a Pandas DataFrame
or Apache Arrow. Table supports appending data, in-place updates, removal
by index, and notifications on update.
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 columns of a Table are immutable after creation, which means their names
and data types cannot be changed after the Table has been created. Columns
cannot be added or deleted after creation, 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_index(&self) -> Option<String>
pub fn get_index(&self) -> Option<String>
Returns the name of the index column for the table.
§Examples
JavaScript:
const table = await client.table("x,y\n1,2\n3,4", { index: "x" });
const index = table.get_index(); // "x"
Python:
table = await async_client.table("x,y\n1,2\n3,4", index="x");
index = table.get_index() # "x"
Rust:
let options = TableInitOptions {index: Some("x".to_string()), ..default() };
let table = client.table("x,y\n1,2\n3,4", options).await;
let tables = client.open_table("table_one").await;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) -> ClientResult<()>
pub async fn delete(&self) -> ClientResult<()>
sourcepub async fn columns(&self) -> ClientResult<Vec<String>>
pub async fn columns(&self) -> ClientResult<Vec<String>>
Returns the column names of this Table in “natural” order (the ordering
implied by the input format).
[```]javascript const table = await worker.table(“x,y\n1,2”); const columns = await table.columns();
// Prints [["x", "y"]]
console.log(columns);
[```]
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: TableData) -> ClientResult<()>
pub async fn remove(&self, input: TableData) -> ClientResult<()>
Removes rows from this Table with the index column values supplied. If
the Table doesn’t have an index column, this operation is inert
- TODO This operations should be an error, not inert, when lacking an
index.
Removes propagate to any View::on_update callbacks for Views derived
from this Table.
§Arguments
indices- A list ofindexcolumn values for rows that should be removed.
§Examples
tbl = Table({"a": [1, 2, 3]}, index="a")
tbl.remove([2, 3])
sourcepub async fn replace(&self, input: TableData) -> ClientResult<()>
pub async fn replace(&self, input: TableData) -> ClientResult<()>
sourcepub async fn update(
&self,
input: TableData,
options: UpdateOptions
) -> ClientResult<()>
pub async fn update( &self, input: TableData, options: UpdateOptions ) -> ClientResult<()>
sourcepub async fn validate_expressions(
&self,
expressions: Expressions
) -> ClientResult<ValidateExpressionsData>
pub async fn validate_expressions( &self, expressions: Expressions ) -> ClientResult<ValidateExpressionsData>
Validates the given expressions.
§Examples
Python:
(XXX: does this need to be awaited)
table = await async_client.validate_expressions({"computed": '"Quantity" + 4'})
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 configuration.
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> 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