use std::sync::Arc;
use async_trait::async_trait;
use lance_table::format::Fragment;
use crate::Result;
#[async_trait]
pub trait WriteFragmentProgress: std::fmt::Debug + Sync + Send {
async fn begin(&self, fragment: &Fragment) -> Result<()>;
async fn complete(&self, fragment: &Fragment) -> Result<()>;
}
#[derive(Debug, Clone, Default)]
pub struct WriteStats {
pub bytes_written: u64,
pub rows_written: u64,
pub files_written: u32,
}
#[derive(Clone)]
pub struct WriteProgressFn(Arc<dyn Fn(WriteStats) + Send + Sync>);
impl WriteProgressFn {
pub fn new(f: impl Fn(WriteStats) + Send + Sync + 'static) -> Self {
Self(Arc::new(f))
}
pub(crate) fn call(&self, stats: WriteStats) {
(self.0)(stats);
}
}
impl std::fmt::Debug for WriteProgressFn {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("WriteProgressFn").finish_non_exhaustive()
}
}
#[derive(Debug, Clone, Default)]
pub struct NoopFragmentWriteProgress {}
impl NoopFragmentWriteProgress {
pub fn new() -> Self {
Self {}
}
}
#[async_trait]
impl WriteFragmentProgress for NoopFragmentWriteProgress {
#[inline]
async fn begin(&self, _fragment: &Fragment) -> Result<()> {
Ok(())
}
#[inline]
async fn complete(&self, _fragment: &Fragment) -> Result<()> {
Ok(())
}
}