Skip to main content

Crate densa_arrow

Crate densa_arrow 

Source
Expand description

Apache Arrow tables in densa’s data grid.

ArrowTable holds Arrow RecordBatches (from Parquet, DataFusion, DuckDB, a Flight stream or your own code) and formats their values into grid cells; ArrowTable::view turns it into a densa_grid::GridSource scrolled to a row, which GridPainter draws. Arrays are shared with the batches, never copied, so a table of millions of rows costs no more to show than its visible rows, and drawing a frame allocates nothing.

For live data, LiveModel makes a densa_data::LiveTable the model of the grid widget (densa_widgets::DataGrid): sorted by a click, filtered by the app, its selection kept on a row as the row moves. LiveGrid paints a view of one with GridPainter directly, and LiveSeries reads two of its numeric columns as a densa_chart series (a price over time), so a chart follows the same live data.

For tables too large to hold (a query engine’s result over billions of rows), a PagedModel is the grid widget’s model: your PageSource gives rows a page at a time, on a thread of the model’s own, and the grid fetches only the pages it shows, in the order a click on a column title asks for.

use std::sync::Arc;
use arrow_array::{ArrayRef, Float64Array, RecordBatch, StringArray};
use densa_arrow::ArrowTable;
use densa_grid::{CellText, GridSource, Palette};

let batch = RecordBatch::try_from_iter([
    ("sensor", Arc::new(StringArray::from(vec!["a-1", "b-2"])) as ArrayRef),
    ("celsius", Arc::new(Float64Array::from(vec![21.5, 80.25])) as ArrayRef),
])?;
let mut table = ArrowTable::from_batches([batch])?;
table.set_decimals(1, Some(1))?;

let columns = table.columns(); // for `GridPainter::new`
let view = table.view(0, &Palette::new()); // each frame: `painter.paint(&view, &mut canvas)`
let mut text = CellText::new();
view.cell(1, 1, &mut text);
assert_eq!(text.as_str(), "80.2");

The API takes and returns arrow_array and arrow_schema types, re-exported here so applications use the same Arrow version: a major Arrow upgrade is a breaking release of this crate.

Re-exports§

pub use arrow_array;
pub use arrow_schema;

Structs§

ArrowGrid
An ArrowTable as a grid’s data, scrolled to a first row. Cheap to create each frame.
ArrowTable
Arrow record batches shown as one table: rows run through the batches in order.
LiveGrid
Shows views of a densa_data::LiveTable in the grid, formatted like an ArrowTable.
LiveGridView
A live view scrolled to a first row, as a grid’s data. Cheap to create each frame.
LiveModel
A densa_data::LiveTable as the model of a grid widget (densa_widgets::DataGrid): one view of the table, sorted when the user clicks a column title and filtered by the app, with rows keyed by their record so a selection follows its row as the data changes.
LiveSeries
Two columns of a densa_data::LiveTable read as numbers, x and y, so a view of the table is a densa_chart series (points).
PageOptions
How a PagedModel pages: the rows of a page and how many pages it keeps.
PageQuery
What a PageSource is asked for: its rows, in an order (an ORDER BY).
PagedModel
A grid model (for densa_widgets::DataGrid) of rows fetched a page at a time from a PageSource: a table too large to hold, such as a query engine’s result over files of billions of rows. The grid shows only some rows, and the model fetches their pages and one on each side, on a thread of its own, so the window never waits; rows not yet fetched show empty until they arrive.
SeriesPoints
A view’s rows as points of a LiveSeries. Cheap to make each frame; reading allocates nothing.
SortKey
A column rows are sorted by, and which way.

Enums§

CellState
What ArrowTable::write_cell wrote.
FetchError
Why a PagedModel has rows it cannot show: what PagedModel::error gives.
SeriesError
Why a series could not be made.
TableError
Why a batch could not be added, or a column setting applied.

Traits§

PageSource
The rows of a table too large to hold, a page at a time: what a PagedModel reads. Its calls (but can_sort) run on a thread of the model’s own, so a call may take as long as it needs: a query to a database or a query engine. A call is not interrupted; the next waits for it. Rows are numbered from 0 in the order the query gives them.

Type Aliases§

PageError
What a PageSource fails with: any error, sent across threads.