pub mod evidence;
pub mod heuristics;
mod profiler;
mod sketches;
pub use evidence::{
BooleanEvidence, CharClasses, ColumnEvidence, DumpProfile, NumericEvidence,
RelationshipEvidence, StringShapeEvidence, TableEvidence, TimestampRangeEvidence, TopKEntry,
};
pub use heuristics::{
Confidence, Decision, InferenceError, InferenceOptions, InferenceResult, ModelInference,
Precedence, RejectedCandidate,
};
pub use profiler::{DumpProfiler, DumpProfilerBuilder};
pub use sketches::ColumnSketches;
use serde::{Deserialize, Serialize};
use std::fmt;
pub(crate) const HLL_PRECISION: u32 = 12;
pub(crate) const HLL_REGISTERS: usize = 1 << HLL_PRECISION;
pub(crate) const MAX_SAMPLE_VALUE_BYTES: usize = 256;
pub(crate) const MAX_TOPK_KEY_BYTES: usize = 256;
pub(crate) const MAX_AFFIX_BYTES: usize = 64;
pub(crate) const MAX_TIMESTAMP_BYTES: usize = 64;
pub(crate) const TOPK_COUNTER_OVERHEAD: usize = 16;
pub(crate) const HISTOGRAM_BIN_BYTES: usize = 16;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ProfileError {
IncompatibleMerge {
detail: &'static str,
},
}
impl ProfileError {
pub(crate) fn incompatible_merge(detail: &'static str) -> Self {
ProfileError::IncompatibleMerge { detail }
}
}
impl fmt::Display for ProfileError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
ProfileError::IncompatibleMerge { detail } => {
write!(f, "cannot merge profile accumulators: {detail} mismatch")
}
}
}
}
impl std::error::Error for ProfileError {}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum ProfileDepth {
Schema,
Basic,
Full,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub struct ProfileBudget {
pub sample_rows: usize,
pub top_k: usize,
pub histogram_bins: usize,
}
impl Default for ProfileBudget {
fn default() -> Self {
Self {
sample_rows: 1_000,
top_k: 32,
histogram_bins: 32,
}
}
}
impl ProfileBudget {
pub fn retained_items_per_column(&self) -> usize {
self.sample_rows + self.top_k + self.histogram_bins
}
pub fn retained_bytes_ceiling(&self) -> usize {
self.sample_rows * MAX_SAMPLE_VALUE_BYTES
+ self.top_k * (MAX_TOPK_KEY_BYTES + TOPK_COUNTER_OVERHEAD)
+ HLL_REGISTERS
+ self.histogram_bins * HISTOGRAM_BIN_BYTES
+ 2 * MAX_AFFIX_BYTES
+ 2 * MAX_TIMESTAMP_BYTES
}
}
#[derive(Debug, Clone, PartialEq)]
pub enum ProfileValue<'a> {
Null,
Boolean(bool),
Integer(i64),
Decimal { minor: i128, scale: u8 },
Text(&'a str),
DateTime(&'a str),
Json(&'a str),
}