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.
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§
- Arrow
Grid - An
ArrowTableas a grid’s data, scrolled to a first row. Cheap to create each frame. - Arrow
Table - Arrow record batches shown as one table: rows run through the batches in order.
- Live
Grid - Shows views of a
densa_data::LiveTablein the grid, formatted like anArrowTable. - Live
Grid View - A live view scrolled to a first row, as a grid’s data. Cheap to create each frame.
- Live
Model - A
densa_data::LiveTableas 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. - Live
Series - Two columns of a
densa_data::LiveTableread as numbers,xandy, so a view of the table is adensa_chartseries (points). - Series
Points - A view’s rows as points of a
LiveSeries. Cheap to make each frame; reading allocates nothing.
Enums§
- Cell
State - What
ArrowTable::write_cellwrote. - Series
Error - Why a series could not be made.
- Table
Error - Why a batch could not be added, or a column setting applied.