Skip to main content

Crate rich_data

Crate rich_data 

Source
Expand description

§rich-data

Tabular data for rs-rich: one row source contract with adapters behind it, so a file, a stream of records or a query result becomes a table without hand-written glue. Not a port of anything upstream; it builds on rich-ext’s public API only.

  • RowSource: column names, an optional Schema (rich_ext’s format-neutral model) and rows of Values, one at a time. Rows holds them in memory and renders through rich_ext’s TableData.
  • Adapters: csv (CSV and TSV through the port of Python’s csv sniffer and reader that rich --csv uses), jsonl (JSON Lines), serialize (any serde::Serialize rows), and arrow (Arrow RecordBatches, behind the off-by-default arrow feature).
  • er: an ER diagram of a Schema or of SQL DDL, through rs-rich-diagram, behind the off-by-default er feature.
  • infer: column types (integers, floats, booleans, dates, timestamps, nulls, text) with the evidence for each, on request.
  • stats: per-column count, nulls, distinct values, min, max, mean, median, quantiles and top values, as a table or under each heading.
  • window: rows for rich_ext’s virtualised tables: Rows by index, and RowWindow, one window of a forward-only source read in constant memory.
  • sql: a query result set (ResultSet) with typed alignment, NULL marked apart from empty text, and a row count.
  • profile: a bounded profile of any row source (types, nulls, distinct values, statistics, histograms or top values, and a missing-value map), sampled when the input is long, as JSON or drawn; and of JSON records path by path, with presence and type mixes.
  • quality: data quality check results (pass, warn, fail, error, with observed and expected values and failing rows) as a report.

Conditional styles for the tables these rows become are rich_ext::table::rules.

use rich::Console;
use rich_data::{csv, infer::Inferrer, RowSource};

let mut rows = csv::CsvReader::new()
    .read("service,p99,up\nweb,120,true\napi,35.5,false\n")
    .unwrap();
assert_eq!(rows.columns(), ["service", "p99", "up"]);

// Types are only inferred when asked, and every guess carries its evidence.
let inference = Inferrer::new().infer(&rows);
assert_eq!(inference.columns()[1].data_type().to_string(), "float");
assert_eq!(inference.columns()[1].evidence().floats, 2);
inference.apply(&mut rows);

let console = Console::builder().width(40).build();
let out = console.render_export(&rows.to_table_data());
assert!(out.contains("│ api     │ 35.5 │ false │"));

Modules§

arrow
Arrow RecordBatches as rows, and Arrow schemas in the format-neutral model (the arrow feature).
csv
CSV and TSV: a port of Python’s csv sniffer and reader, and a CsvReader that turns a file into Rows.
er
ER diagrams from the schema model (#247), behind the er feature.
infer
Column type inference (#267), on request and with its evidence.
jsonl
JSON Lines: one JSON value per line, as rows.
profile
Data profiles (#343, #344, #345, #346): what every column of a CSV, JSON Lines or any other RowSource holds, in one bounded pass.
quality
Data quality results (#269): a check-result model and a report that renders it the way rich_ext’s test report renders test runs.
serialize
Rows from any serde::Serialize values: a struct’s fields (or a map’s keys) are columns, and any other value is one value column.
sql
SQL-shaped result sets (#235): a query’s rows as a database shell shows them.
stats
Column statistics (#261): count, nulls, distinct values, min, max, mean, median, quantiles and the most common values, per column.
window
Windows of rows for rich_ext’s virtualised tables (#260).

Structs§

DataError
Why rows could not be read: what went wrong, and where when the source knows (a 1-based line or record number).
Field
One named field: a type, whether it may be null and whether it must be present, its constraints, and optionally the source’s own name for the type, a description and metadata.
RecordSource
Rows from a stream of JSON records.
Rows
Rows held in memory: column names, an optional schema, and the rows.
RowsSource
Rows as a RowSource, from Rows::into_source.
Schema
An ordered list of top-level fields, optionally named (a table, a record type, a document), and the further tables a schema of several holds (SQL DDL’s CREATE TABLEs).

Enums§

DataType
A field’s logical type.
Value
A typed table cell.

Traits§

RowSource
The row source contract: column names, an optional schema, and rows.

Type Aliases§

Row
One row of cells.