Skip to main content

acta/read/
block.rs

1//! Public metadata for one committed data frame.
2
3/// The inclusive primary timestamp/date bounds declared by one block.
4#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5pub struct PrimaryBounds {
6    minimum: i64,
7    maximum: i64,
8}
9
10impl PrimaryBounds {
11    pub(crate) fn new(minimum: i64, maximum: i64) -> Self {
12        Self { minimum, maximum }
13    }
14
15    /// The declared minimum, represented as timestamp units or signed days.
16    pub fn min(&self) -> i64 {
17        self.minimum
18    }
19
20    /// The declared maximum, represented as timestamp units or signed days.
21    pub fn max(&self) -> i64 {
22        self.maximum
23    }
24}
25
26/// Read-only metadata for one complete, committed data block.
27#[derive(Debug, Clone, PartialEq, Eq)]
28pub struct BlockMetadata {
29    sequence: u64,
30    file_offset: u64,
31    total_length: u64,
32    row_count: u64,
33    base_row_id: Option<u64>,
34    primary_bounds: Option<PrimaryBounds>,
35    ts_sorted: bool,
36}
37
38impl BlockMetadata {
39    pub(crate) fn new(
40        sequence: u64,
41        file_offset: u64,
42        total_length: u64,
43        row_count: u64,
44        base_row_id: Option<u64>,
45        primary_bounds: Option<PrimaryBounds>,
46        ts_sorted: bool,
47    ) -> Self {
48        Self {
49            sequence,
50            file_offset,
51            total_length,
52            row_count,
53            base_row_id,
54            primary_bounds,
55            ts_sorted,
56        }
57    }
58
59    /// The contiguous data-frame sequence number, beginning at one.
60    pub fn sequence(&self) -> u64 {
61        self.sequence
62    }
63
64    /// The absolute byte offset of this frame's prefix.
65    pub fn file_offset(&self) -> u64 {
66        self.file_offset
67    }
68
69    /// The complete committed frame length, including prefix and trailer.
70    pub fn total_length(&self) -> u64 {
71        self.total_length
72    }
73
74    /// The logical row count declared by the block.
75    pub fn row_count(&self) -> u64 {
76        self.row_count
77    }
78
79    /// The base row ID when the file's `ROW_IDS` feature is enabled.
80    pub fn base_row_id(&self) -> Option<u64> {
81        self.base_row_id
82    }
83
84    /// The block's primary timestamp/date bounds, if the schema has a primary.
85    pub fn primary_bounds(&self) -> Option<PrimaryBounds> {
86        self.primary_bounds
87    }
88
89    /// Whether this block declares nondecreasing primary values.
90    ///
91    /// The claim covers this block's primary timestamp column only. It says
92    /// nothing about ordering between blocks or about any other column, and a
93    /// metadata-only open does not verify it against the stored values.
94    pub fn ts_sorted(&self) -> bool {
95        self.ts_sorted
96    }
97}