use std::{collections::HashMap, path::PathBuf};
use crate::supertable::reader_cache::ColdFetchMode as InternalColdFetchMode;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum ColdFetchMode {
HybridWithPrefetch,
RangeOnly,
#[default]
LazyForegroundWithBackgroundFill,
}
impl ColdFetchMode {
pub(crate) fn to_internal(self) -> InternalColdFetchMode {
match self {
ColdFetchMode::HybridWithPrefetch => InternalColdFetchMode::HybridWithPrefetch,
ColdFetchMode::RangeOnly => InternalColdFetchMode::RangeOnly,
ColdFetchMode::LazyForegroundWithBackgroundFill => {
InternalColdFetchMode::LazyForegroundWithBackgroundFill
}
}
}
}
#[derive(Debug, Clone, Default)]
pub struct ConnectOptions {
pub(crate) storage_options: HashMap<String, String>,
pub(crate) cache_dir: Option<PathBuf>,
pub(crate) cache_budget_bytes: Option<u64>,
pub(crate) cold_fetch_mode: ColdFetchMode,
pub(crate) validate: bool,
}
impl ConnectOptions {
pub fn new() -> Self {
Self::default()
}
pub fn with_cache_dir(mut self, dir: impl Into<PathBuf>) -> Self {
self.cache_dir = Some(dir.into());
self
}
pub fn with_cache_budget_bytes(mut self, bytes: u64) -> Self {
self.cache_budget_bytes = Some(bytes);
self
}
pub fn with_cold_fetch_mode(mut self, mode: ColdFetchMode) -> Self {
self.cold_fetch_mode = mode;
self
}
pub fn with_storage_option(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
self.storage_options.insert(key.into(), value.into());
self
}
pub fn with_validate(mut self, validate: bool) -> Self {
self.validate = validate;
self
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn with_storage_option_round_trips() {
let o = ConnectOptions::new().with_storage_option("aws_region", "us-east-1");
assert_eq!(
o.storage_options.get("aws_region").map(String::as_str),
Some("us-east-1")
);
}
}