Skip to main content

tessera/readers/
mod.rs

1//! Data-engine plumbing shared by the Polars and DuckDB readers.
2
3#[cfg(feature = "duckdb")]
4pub mod duckdb;
5#[cfg(feature = "polars")]
6pub mod polars;
7
8use crate::error::TesseraError;
9use crate::models::{IntoCoins, IntoMonths, PartitionRef};
10#[cfg(any(feature = "polars", feature = "duckdb"))]
11/// A resolved partition: its reference plus a freshly-minted presigned URL.
12pub type ResolvedPartition = (PartitionRef, String);
13
14/// Expand `(asset, coins, months)` into the cartesian list of partitions.
15///
16/// Coin-major ordering: every month of the first coin, then the second, …
17///
18/// # Errors
19///
20/// Returns [`TesseraError::InvalidArgument`] when either argument is empty or
21/// contains an invalid month.
22pub fn expand_refs(
23    asset: &str,
24    coin: impl IntoCoins,
25    month: impl IntoMonths,
26) -> Result<Vec<PartitionRef>, TesseraError> {
27    let coins = coin.into_coins()?;
28    let months = month.into_months()?;
29    let mut refs = Vec::with_capacity(coins.len() * months.len());
30    for coin in &coins {
31        for month in &months {
32            refs.push(PartitionRef::new(asset, coin, month)?);
33        }
34    }
35    Ok(refs)
36}