1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//! Lineage model (SPEC Chapter 10).
use serde::{Deserialize, Serialize};
/// Logical information-flow kind (SPEC Chapter 10 §7).
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Default)]
#[serde(rename_all = "camelCase")]
pub enum InformationFlow {
/// Values preserved without derivation.
Preserved,
/// Values derived from sources.
#[default]
Derived,
/// Values aggregated from sources.
Aggregated,
/// Values filtered from sources.
Filtered,
/// Values partitioned from sources.
Partitioned,
/// Values explicitly discarded (information loss).
Discarded,
}
impl InformationFlow {
/// Serialized flow name.
#[must_use]
pub fn as_str(self) -> &'static str {
match self {
Self::Preserved => "preserved",
Self::Derived => "derived",
Self::Aggregated => "aggregated",
Self::Filtered => "filtered",
Self::Partitioned => "partitioned",
Self::Discarded => "discarded",
}
}
}
/// Data lineage metadata.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Lineage {
/// Output-to-input provenance mappings.
#[serde(default)]
pub mappings: Vec<LineageMapping>,
}
fn default_lineage_operation() -> String {
"dtcs:derive".into()
}
/// Maps an output to contributing inputs with semantic operation and flow.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct LineageMapping {
/// Optional stable mapping identity (SPEC Chapter 10 §5).
#[serde(default, skip_serializing_if = "Option::is_none")]
pub id: Option<String>,
/// Output identifier (destination).
pub output: String,
/// Contributing input identifiers (sources).
#[serde(default)]
pub inputs: Vec<String>,
/// Semantic operation relating sources to destination (SPEC Chapter 10 §6).
/// Defaults to `dtcs:derive` when omitted for backward compatibility.
#[serde(default = "default_lineage_operation")]
pub operation: String,
/// Information-flow kind (SPEC Chapter 10 §7).
#[serde(default)]
pub flow: InformationFlow,
}