use std::error;
use std::future::Future;
use time::OffsetDateTime;
#[cfg(feature = "hf-bucket")]
pub mod hf_bucket;
#[cfg(feature = "huggingface")]
pub mod huggingface;
#[derive(Debug, Clone, PartialEq)]
pub struct WindowMeta {
pub pipeline: String,
pub start: OffsetDateTime,
pub end: OffsetDateTime,
}
pub trait Sink<R>: Send {
type Error: error::Error + Send + Sync + 'static;
fn ingest(
&mut self,
meta: &WindowMeta,
records: Vec<R>,
) -> impl Future<Output = Result<(), Self::Error>> + Send;
fn advance(
&mut self,
_now: OffsetDateTime,
) -> impl Future<Output = Result<(), Self::Error>> + Send {
async { Ok(()) }
}
fn flush(&mut self) -> impl Future<Output = Result<(), Self::Error>> + Send;
}
pub(crate) fn fingerprint(bytes: &[u8]) -> u64 {
const OFFSET_BASIS: u64 = 0xcbf2_9ce4_8422_2325;
const PRIME: u64 = 0x0100_0000_01b3;
bytes.iter().fold(OFFSET_BASIS, |hash, &byte| {
(hash ^ u64::from(byte)).wrapping_mul(PRIME)
})
}
pub(crate) fn object_path(meta: &WindowMeta, content: &[u8], ext: &str) -> String {
let date = meta.start.date();
format!(
"data/{}/{:04}-{:02}-{:02}/{:02}-{:02}-{:02}-{:016x}.{}",
meta.pipeline,
date.year(),
u8::from(date.month()),
date.day(),
meta.start.hour(),
meta.start.minute(),
meta.start.second(),
fingerprint(content),
ext,
)
}