Skip to main content

Module quality

Module quality 

Source
Expand description

Data quality results (#269): a check-result model and a report that renders it the way rich_ext’s test report renders test runs.

This is not a check engine. A CheckResult is whatever a caller’s checks found: the check’s name, the column it looked at, a Status (pass, warn, fail or error), what it observed and expected, a message, and a sample of the failing rows. not_null and unique are two small built-in checks over Rows, for the common cases.

QualityReport shows the failures, errors and warnings first, each with its observed and expected values and its failing rows as a table, then a table of every check and a summary line. Names, messages and cells are shown with terminal controls made visible, so data cannot move the cursor or recolour the terminal. Statuses take the quality.* theme keys in STYLES.

use rich::Console;
use rich_data::quality::{self, CheckResult, QualityReport, Status};
use rich_data::{Rows, Value};

let mut rows = Rows::new(["id", "email"]);
rows.push([Value::Int(1), "ada@example.com".into()]);
rows.push([Value::Int(2), Value::Null]);
rows.push([Value::Int(2), "alan@example.com".into()]);

let report = QualityReport::new([
    quality::not_null(&rows, "email").unwrap(),
    quality::unique(&rows, "id").unwrap(),
    CheckResult::new("row_count", Status::Warn)
        .observed("3")
        .expected(">= 100"),
]);
assert_eq!(report.totals().failed, 2);
assert!(!report.is_success());

let console = Console::builder().width(60).color_system(None).build();
let out = console.render_export(&report);
assert!(out.starts_with("FAIL not_null › email\n  observed 1 null · expected 0\n"));
assert!(out.ends_with("0 passed, 1 warned, 2 failed\n"));

Structs§

CheckResult
One check’s result.
FailingRows
Some of the rows a check failed on.
QualityReport
Results as a report: failures first, a table and a summary. See the module docs.
Totals
How many checks ended each way.

Enums§

Status
How a check ended.

Constants§

FAILING_ROWS
How many failing rows a built-in check keeps.
STYLES
The theme keys a quality report draws with, and their defaults. A console theme that defines a key wins.

Functions§

not_null
not_null: every cell of column has a value. Nulls are Value::Null and empty text. Fails with the first null rows (row is counted from 1); an unknown column is an error.
unique
unique: no two non-null cells of column hold the same value (by text). Fails with the rows holding a repeated value, after its first; an unknown column is an error.