use xlog_core::Schema;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum LayoutHint {
#[default]
CudfTable,
HisaIndexed,
VflogColumnar,
}
#[derive(Debug, Clone)]
pub struct SkewSignature {
pub hot_keys: Vec<u64>,
pub entropy: f64,
}
impl SkewSignature {
pub fn is_skewed(&self) -> bool {
self.entropy < 3.0 }
}
#[derive(Debug, Clone)]
pub struct RirMeta {
pub schema: Schema,
pub est_rows: (u64, u64),
pub est_bytes: (u64, u64),
pub skew: Option<SkewSignature>,
pub deterministic: bool,
pub layout_hint: LayoutHint,
}
impl Default for RirMeta {
fn default() -> Self {
Self {
schema: Schema::new(vec![]),
est_rows: (0, 0),
est_bytes: (0, 0),
skew: None,
deterministic: true,
layout_hint: LayoutHint::default(),
}
}
}
impl RirMeta {
pub fn with_schema(schema: Schema) -> Self {
Self {
schema,
..Default::default()
}
}
pub fn with_rows(mut self, min: u64, max: u64) -> Self {
self.est_rows = (min, max);
self.est_bytes = (
min * self.schema.row_size_bytes() as u64,
max * self.schema.row_size_bytes() as u64,
);
self
}
pub fn with_layout(mut self, hint: LayoutHint) -> Self {
self.layout_hint = hint;
self
}
}
#[cfg(test)]
mod tests {
use super::*;
use xlog_core::ScalarType;
#[test]
fn test_rir_meta_default() {
let meta = RirMeta::default();
assert_eq!(meta.est_rows, (0, 0));
assert!(meta.deterministic);
}
#[test]
fn test_layout_hint_default() {
let hint = LayoutHint::default();
assert_eq!(hint, LayoutHint::CudfTable);
}
#[test]
fn test_skew_signature() {
let sig = SkewSignature {
hot_keys: vec![42, 100],
entropy: 2.5,
};
assert!(sig.is_skewed());
}
#[test]
fn test_meta_with_rows() {
let schema = Schema::new(vec![
("a".to_string(), ScalarType::U32),
("b".to_string(), ScalarType::U32),
]);
let meta = RirMeta::with_schema(schema).with_rows(100, 200);
assert_eq!(meta.est_rows, (100, 200));
assert_eq!(meta.est_bytes, (800, 1600)); }
}