Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Index and Limit

`limit` cannot be used in conjunction with `index`.

Initializing a Table with an index tells Perspective to treat a column as the primary key, allowing in-place updates of rows. Only a single column (of any type) can be used as an index. Indexed Table instances allow:

  • In-place updates whenever a new row shares an index values with an existing row
  • Partial updates when a data batch omits some column.
  • Removes to delete a row by index.

To create an indexed Table, provide the index property with a string column name to be used as an index:

JavaScript:

const indexed_table = await perspective.table(data, { index: "a" });

Python

indexed_table = perspective.Table(data, index="a");

Initializing a Table with a limit sets the total number of rows the Table is allowed to have. When the Table is updated, and the resulting size of the Table would exceed its limit, rows that exceed limit overwrite the oldest rows in the Table. To create a Table with a limit, provide the limit property with an integer indicating the maximum rows:

JavaScript:

const limit_table = await perspective.table(data, { limit: 1000 });

Python:

limit_table = perspective.Table(data, limit=1000);

page_to_disk

By default a Table keeps its columns in memory. Initializing a Table with page_to_disk backs its column data with on-disk storage instead, so the Table can be larger than the memory available to the engine. It is otherwise an ordinary Table: index, update(), views, aggregates, expressions and Arrow round-trips all behave as they do in memory, and produce identical results.

JavaScript:

const table = await perspective.table(arrow, { page_to_disk: true });

Python:

table = perspective.table(arrow, page_to_disk=True)

Where the data goes depends on the runtime:

RuntimeBacking storage
Browser (WebAssembly, in a Web Worker)The Origin Private File System (OPFS)
Node.js (WebAssembly)Files under the OS temp directory, via node:fs
Python and Rust (native)Memory-mapped files under the OS temp directory