dataprof_core/partial.rs
1use crate::{classification::DataType, source::FileFormat};
2
3/// Result of fast schema inference — column names paired with inferred data types.
4#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
5pub struct SchemaResult {
6 /// Columns with their inferred types. For CSV/Parquet the order matches
7 /// the source; for JSON/JSONL columns are sorted alphabetically.
8 pub columns: Vec<ColumnSchema>,
9 /// How many rows were sampled to infer the schema (0 for Parquet metadata).
10 pub rows_sampled: usize,
11 /// Time taken for inference in milliseconds.
12 pub inference_time_ms: u128,
13 /// `true` when the entire file was consumed or schema was read from
14 /// metadata; `false` when inference stopped at the sample-size cap and
15 /// the schema may not have fully stabilized.
16 pub schema_stable: bool,
17}
18
19/// A single column's name and inferred data type.
20#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
21pub struct ColumnSchema {
22 pub name: String,
23 pub data_type: DataType,
24}
25
26/// Lightweight structural summary for a file.
27///
28/// This intentionally sits between `quick_row_count()` / `infer_schema()` and a
29/// full profile: it reports shape and sampled per-column counters, not quality
30/// scores, pattern detection, recommendations, or raw values.
31#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
32pub struct StructureReport {
33 /// Source identifier, currently the file path passed by the caller.
34 pub source: String,
35 /// Detected or explicitly provided file format.
36 pub format: FileFormat,
37 /// Exact or estimated row count for the source.
38 pub row_count: RowCountEstimate,
39 /// Number of rows consumed for the structural column summaries.
40 pub rows_sampled: usize,
41 /// True when the structural pass consumed the whole source.
42 pub source_exhausted: bool,
43 /// True when the structural pass stopped at the row sample cap.
44 pub truncated: bool,
45 /// Human-readable reason for truncation, if any.
46 pub truncation_reason: Option<String>,
47 /// CSV delimiter used for parsing, when applicable.
48 pub delimiter: Option<String>,
49 /// Per-column structural summaries.
50 pub columns: Vec<StructureColumnSummary>,
51 /// Non-fatal caveats, such as estimated row counts.
52 pub warnings: Vec<String>,
53}
54
55/// Sample-derived or metadata-derived structural summary for one column.
56#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
57pub struct StructureColumnSummary {
58 pub name: String,
59 pub data_type: DataType,
60 pub total_count: Option<usize>,
61 pub null_count: Option<usize>,
62 pub null_ratio: Option<f64>,
63 pub unique_count: Option<usize>,
64 pub uniqueness_ratio: Option<f64>,
65 pub distinct_count_approximate: Option<bool>,
66 /// `"sample"` for CSV/JSON/JSONL, `"metadata"` for Parquet.
67 pub provenance: String,
68}
69
70/// Result of a quick row count operation.
71#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
72pub struct RowCountEstimate {
73 /// The estimated or exact row count.
74 pub count: u64,
75 /// Whether the count is exact or an estimate.
76 pub exact: bool,
77 /// How the count was obtained.
78 pub method: CountMethod,
79 /// Time taken in milliseconds.
80 pub count_time_ms: u128,
81}
82
83/// Method used to obtain the row count.
84#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
85pub enum CountMethod {
86 /// Read from Parquet file footer metadata (exact, zero row reading).
87 ParquetMetadata,
88 /// Full scan of the file (exact).
89 FullScan,
90 /// Sample-based estimation (approximate).
91 Sampling,
92 /// Full scan of a streaming source (no file metadata available).
93 StreamFullScan,
94}