Skip to main content

timeseries_table_format/
table.rs

1//! High-level time-series table abstraction.
2//!
3//! This module is the canonical home for the user-facing [`TimeSeriesTable`]
4//! API.
5
6mod error;
7mod operations;
8
9pub use operations::append;
10pub use operations::{
11    AppendError, CoverageQueryError, CreateTableError, OpenTableError, OptimizeError,
12    OptimizeReport, ScanError, TableStateAccessError, VacuumArtifact, VacuumArtifactDisposition,
13    VacuumArtifactReason, VacuumError, VacuumMode, VacuumReport,
14};
15
16#[cfg(test)]
17pub(crate) mod test_util;
18
19#[cfg(test)]
20mod latest_snapshot_tests;
21
22use std::pin::Pin;
23
24use arrow::array::RecordBatch;
25use futures::Stream;
26
27use crate::{
28    metadata::protocol::TableProtocolError,
29    storage::TableLocation,
30    transaction_log::{IndexSpec, TableState, TransactionLogStore},
31};
32
33pub use crate::formats::parquet::EntityRewriteError;
34pub use error::TableError;
35
36/// Stream of Arrow RecordBatch values from a time-series scan.
37///
38/// Batch and row order is unspecified.
39pub type TimeSeriesScan = Pin<Box<dyn Stream<Item = Result<RecordBatch, TableError>> + Send>>;
40
41/// High-level time-series table handle.
42///
43/// This is the main entry point for callers. It bundles the table location,
44/// transaction log, current committed state, and ordered-index specification.
45#[derive(Debug, Clone)]
46pub struct TimeSeriesTable {
47    log: TransactionLogStore,
48    state: TableState,
49    index: IndexSpec,
50}
51
52impl TimeSeriesTable {
53    /// Return the current committed table state.
54    pub fn state(&self) -> &TableState {
55        &self.state
56    }
57
58    /// Return a mutable reference to the current committed table state (crate-internal).
59    #[allow(dead_code)]
60    pub(crate) fn state_mut(&mut self) -> &mut TableState {
61        &mut self.state
62    }
63
64    /// Return the ordered-index specification for this table.
65    pub fn index_spec(&self) -> &IndexSpec {
66        &self.index
67    }
68
69    /// Return the table location.
70    pub fn location(&self) -> &TableLocation {
71        self.log.location()
72    }
73
74    pub(crate) fn ensure_write_compatible(&self) -> Result<(), TableProtocolError> {
75        self.state.table_meta.ensure_write_compatible()
76    }
77}