mod basic;
pub mod binary;
pub mod boolean;
pub mod double;
pub mod integer;
use arrow::{bitmap::Bitmap, error::Result};
pub use basic::CommonCompression;
pub static SAMPLE_COUNT: usize = 10;
pub static SAMPLE_SIZE: usize = 64;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Compression {
None,
Lz4,
Zstd,
Snappy,
Rle,
Dict,
OneValue,
Freq,
Bitpacking,
DeltaBitpacking,
Patas,
}
impl Default for Compression {
fn default() -> Self {
Self::None
}
}
impl Compression {
pub fn is_none(&self) -> bool {
matches!(self, Compression::None)
}
pub fn from_codec(t: u8) -> Result<Self> {
match t {
0 => Ok(Compression::None),
1 => Ok(Compression::Lz4),
2 => Ok(Compression::Zstd),
3 => Ok(Compression::Snappy),
10 => Ok(Compression::Rle),
11 => Ok(Compression::Dict),
12 => Ok(Compression::OneValue),
13 => Ok(Compression::Freq),
14 => Ok(Compression::Bitpacking),
15 => Ok(Compression::DeltaBitpacking),
16 => Ok(Compression::Patas),
other => Err(arrow::error::Error::OutOfSpec(format!(
"Unknown compression codec {other}",
))),
}
}
pub fn raw_mode(&self) -> bool {
matches!(
self,
Compression::None | Compression::Lz4 | Compression::Zstd | Compression::Snappy
)
}
}
impl From<Compression> for u8 {
fn from(value: Compression) -> Self {
match value {
Compression::None => 0,
Compression::Lz4 => 1,
Compression::Zstd => 2,
Compression::Snappy => 3,
Compression::Rle => 10,
Compression::Dict => 11,
Compression::OneValue => 12,
Compression::Freq => 13,
Compression::Bitpacking => 14,
Compression::DeltaBitpacking => 15,
Compression::Patas => 16,
}
}
}
#[inline]
pub(crate) fn is_valid(validity: &Option<&Bitmap>, i: usize) -> bool {
match validity {
Some(v) => v.get_bit(i),
None => true,
}
}
#[inline]
pub(crate) fn get_bits_needed(input: u64) -> u32 {
u64::BITS - input.leading_zeros()
}
#[cfg(test)]
mod tests {}