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