Skip to main content

Crate improv_storage_csv

Crate improv_storage_csv 

Source
Expand description

CSV/TSV connectivity (Phase A, post-v0.5.0 plan): import a CSV/TSV file into an Improv Model, and export a measure’s cells back to CSV/TSV (an input measure’s stored cells, or a derived measure’s engine-computed ones).

Mirrors improv_storage_sql’s shape (see its module docs): a column→model mapping (dimension columns → categories/items, one value column → a measure) turns external tabular data into ordinary input cells. CSV has no live “refresh” concept (no persistent connection to re-query) — import is a one-shot static load; re-running it against a changed file re-populates the measure the same way a fresh import_csv call would.

  • Storage separation. CSV is a data source/sink only; the canonical model lives in Mentat. Import produces ordinary categories/items/measures/ input cells — the engine gains no CSV-specific path.
  • Testability. Every file-based entry point (import_csv, export_measure_csv) has an io::Read/io::Write sibling (import_csv_from, export_measure_csv_to) so tests exercise the real logic against an in-memory buffer, no tempfiles required.

Structs§

DimensionMapping
A CSV/TSV column that becomes a category: its distinct values become items.
ExportSpec
Export options for export_measure_csv_with.
ImportSpec
How to map a CSV/TSV file’s columns onto model elements. Each dimensions entry names a column that becomes a category; value_column names the column that becomes the imported measure’s value. A row therefore contributes one input cell: measure[dim=val, …] = value_column.

Enums§

ColumnRef
A column reference: either a header name (requires has_header) or a 0-based column index. Supporting both lets headerless files work too.
CsvError

Constants§

DEFAULT_MAX_RECORDS
Record cap applied when ImportSpec::max_records is None.
MAX_FIELD_BYTES
Longest field accepted on import, in bytes (1 MiB).
MAX_RECORD_BYTES
Longest record accepted on import, in bytes. Enforced while reading, so a file with one enormous field errors instead of being buffered whole.

Functions§

export_measure_csv
Write a measure’s cells to a CSV/TSV file: one column per dimension category (item name) plus a value column, header row first. An input measure exports its stored cells; a derived measure is evaluated by the engine and exports its computed cells (IMPROV.txt:113 — export the computed view). Returns the number of rows written. See export_measure_csv_to for the writer-based (testable) version.
export_measure_csv_to
Write a measure’s cells to writer as CSV/TSV (delimiter). Rows are written in coordinate order, so output is deterministic.
export_measure_csv_with
export_measure_csv_to with explicit ExportSpec options.
import_csv
Import a CSV/TSV file into model per spec. Returns the number of cells imported. See import_csv_from for the reader-based (testable) version.
import_csv_from
Import CSV/TSV data read from reader into model per spec (spec.path is ignored). Distinct dimension-column values become items, interned by name — an item is reused when one already exists with that name in the target category. Returns the number of cells imported.

Type Aliases§

Result