Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 42 additions & 1 deletion vortex-btrblocks/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

//! Builder for configuring `BtrBlocksCompressor` instances.

use vortex_array::ArrayId;
use vortex_utils::aliases::hash_set::HashSet;

use crate::BtrBlocksCompressor;
Expand Down Expand Up @@ -90,12 +91,14 @@ pub const ALL_SCHEMES: &[&dyn Scheme] = &[
#[derive(Debug, Clone)]
pub struct BtrBlocksCompressorBuilder {
schemes: Vec<&'static dyn Scheme>,
gate_by_enabled_editions: bool,
}

impl Default for BtrBlocksCompressorBuilder {
fn default() -> Self {
Self {
schemes: ALL_SCHEMES.to_vec(),
gate_by_enabled_editions: false,
}
}
}
Expand All @@ -107,6 +110,7 @@ impl BtrBlocksCompressorBuilder {
pub fn empty() -> Self {
Self {
schemes: Vec::new(),
gate_by_enabled_editions: false,
}
}

Expand Down Expand Up @@ -208,14 +212,40 @@ impl BtrBlocksCompressorBuilder {
self
}

/// Retains only schemes whose declared produced encodings (see
/// [`Scheme::produced_encodings`]) all belong to `allowed`. The file writer uses this
/// to restrict compression to an explicitly configured allow set.
pub fn retain_allowed_encodings(mut self, allowed: &HashSet<ArrayId>) -> Self {
self.schemes
.retain(|s| s.produced_encodings().iter().all(|id| allowed.contains(id)));
self
}

/// Gate scheme selection by the session's enabled editions at compression time.
///
/// See [`CascadingCompressor::with_enabled_editions_gating`]. The file writer enables
/// this by default so compression only chooses encodings from the session's enabled
/// editions.
pub fn gate_by_enabled_editions(mut self) -> Self {
self.gate_by_enabled_editions = true;
self
}

/// Builds the configured [`BtrBlocksCompressor`].
pub fn build(self) -> BtrBlocksCompressor {
BtrBlocksCompressor(CascadingCompressor::new(self.schemes))
let mut compressor = CascadingCompressor::new(self.schemes);
if self.gate_by_enabled_editions {
compressor = compressor.with_enabled_editions_gating();
}
BtrBlocksCompressor(compressor)
}
}

#[cfg(test)]
mod tests {
use vortex_array::VTable;
use vortex_fastlanes::FoR;

use super::*;

#[test]
Expand All @@ -230,6 +260,17 @@ mod tests {
assert_eq!(builder.schemes.len(), ALL_SCHEMES.len());
}

#[test]
fn retain_allowed_encodings_filters_schemes() {
let allowed: HashSet<ArrayId> = [FoR.id()].into_iter().collect();
let builder = BtrBlocksCompressorBuilder::default().retain_allowed_encodings(&allowed);
assert_eq!(builder.schemes.len(), 1);
assert_eq!(builder.schemes[0].id(), integer::FoRScheme.id());

let none = BtrBlocksCompressorBuilder::default().retain_allowed_encodings(&HashSet::new());
assert!(none.schemes.is_empty());
}

#[test]
fn cuda_compatible_excludes_alprd() {
let builder = BtrBlocksCompressorBuilder::default().only_cuda_compatible();
Expand Down
6 changes: 6 additions & 0 deletions vortex-btrblocks/src/schemes/binary/zstd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@

//! Zstd compression for binary arrays.

use vortex_array::ArrayId;
use vortex_array::ArrayRef;
use vortex_array::Canonical;
use vortex_array::ExecutionCtx;
use vortex_array::IntoArray;
use vortex_array::VTable;
use vortex_compressor::scheme::CompressionEstimate;
use vortex_compressor::scheme::DeferredEstimate;
use vortex_error::VortexResult;
Expand All @@ -29,6 +31,10 @@ impl Scheme for ZstdScheme {
canonical.dtype().is_binary()
}

fn produced_encodings(&self) -> Vec<ArrayId> {
vec![vortex_zstd::Zstd.id()]
}

fn expected_compression_ratio(
&self,
_data: &ArrayAndStats,
Expand Down
6 changes: 6 additions & 0 deletions vortex-btrblocks/src/schemes/binary/zstd_buffers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@

//! Zstd buffer-level binary compression preserving array layout for GPU decompression.

use vortex_array::ArrayId;
use vortex_array::ArrayRef;
use vortex_array::Canonical;
use vortex_array::ExecutionCtx;
use vortex_array::IntoArray;
use vortex_array::VTable;
use vortex_compressor::scheme::CompressionEstimate;
use vortex_compressor::scheme::DeferredEstimate;
use vortex_error::VortexResult;
Expand All @@ -29,6 +31,10 @@ impl Scheme for ZstdBuffersScheme {
canonical.dtype().is_binary()
}

fn produced_encodings(&self) -> Vec<ArrayId> {
vec![vortex_zstd::ZstdBuffers.id()]
}

fn expected_compression_ratio(
&self,
_data: &ArrayAndStats,
Expand Down
6 changes: 6 additions & 0 deletions vortex-btrblocks/src/schemes/decimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@

//! Decimal compression scheme using byte-part decomposition.

use vortex_array::ArrayId;
use vortex_array::ArrayRef;
use vortex_array::Canonical;
use vortex_array::ExecutionCtx;
use vortex_array::IntoArray;
use vortex_array::VTable;
use vortex_array::arrays::DecimalArray;
use vortex_array::arrays::PrimitiveArray;
use vortex_array::arrays::decimal::narrowed_decimal;
Expand Down Expand Up @@ -38,6 +40,10 @@ impl Scheme for DecimalScheme {
matches!(canonical, Canonical::Decimal(_))
}

fn produced_encodings(&self) -> Vec<ArrayId> {
vec![DecimalByteParts.id()]
}

/// Children: primitive=0.
fn num_children(&self) -> usize {
1
Expand Down
10 changes: 10 additions & 0 deletions vortex-btrblocks/src/schemes/float/alp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ use vortex_alp::ALP;
use vortex_alp::ALPArrayExt;
use vortex_alp::ALPArraySlotsExt;
use vortex_alp::alp_encode;
use vortex_array::ArrayId;
use vortex_array::ArrayRef;
use vortex_array::Canonical;
use vortex_array::ExecutionCtx;
use vortex_array::IntoArray;
use vortex_array::VTable;
use vortex_array::arrays::Patched;
use vortex_array::arrays::patched::use_experimental_patches;
use vortex_array::arrays::primitive::PrimitiveArrayExt;
Expand Down Expand Up @@ -40,6 +42,14 @@ impl Scheme for ALPScheme {
canonical.dtype().is_float()
}

fn produced_encodings(&self) -> Vec<ArrayId> {
let mut encodings = vec![ALP.id()];
if use_experimental_patches() {
encodings.push(Patched.id());
}
encodings
}

/// Children: encoded_ints=0.
fn num_children(&self) -> usize {
1
Expand Down
6 changes: 6 additions & 0 deletions vortex-btrblocks/src/schemes/float/alprd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
use vortex_alp::ALPRDArrayExt;
use vortex_alp::ALPRDArrayOwnedExt;
use vortex_alp::RDEncoder;
use vortex_array::ArrayId;
use vortex_array::ArrayRef;
use vortex_array::Canonical;
use vortex_array::ExecutionCtx;
use vortex_array::IntoArray;
use vortex_array::VTable;
use vortex_array::arrays::primitive::PrimitiveArrayExt;
use vortex_array::dtype::PType;
use vortex_compressor::scheme::CompressionEstimate;
Expand Down Expand Up @@ -37,6 +39,10 @@ impl Scheme for ALPRDScheme {
canonical.dtype().is_float()
}

fn produced_encodings(&self) -> Vec<ArrayId> {
vec![vortex_alp::ALPRD.id()]
}

fn expected_compression_ratio(
&self,
data: &ArrayAndStats,
Expand Down
6 changes: 6 additions & 0 deletions vortex-btrblocks/src/schemes/float/pco.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@

//! Pco (pcodec) float compression.

use vortex_array::ArrayId;
use vortex_array::ArrayRef;
use vortex_array::Canonical;
use vortex_array::ExecutionCtx;
use vortex_array::IntoArray;
use vortex_array::VTable;
use vortex_compressor::scheme::CompressionEstimate;
use vortex_compressor::scheme::DeferredEstimate;
use vortex_error::VortexResult;
Expand All @@ -29,6 +31,10 @@ impl Scheme for PcoScheme {
canonical.dtype().is_float()
}

fn produced_encodings(&self) -> Vec<ArrayId> {
vec![vortex_pco::Pco.id()]
}

fn expected_compression_ratio(
&self,
_data: &ArrayAndStats,
Expand Down
7 changes: 7 additions & 0 deletions vortex-btrblocks/src/schemes/float/rle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@

//! Run-length float encoding.

use vortex_array::ArrayId;
use vortex_array::ArrayRef;
use vortex_array::Canonical;
use vortex_array::ExecutionCtx;
use vortex_array::VTable;
use vortex_compressor::scheme::AncestorExclusion;
use vortex_compressor::scheme::CompressionEstimate;
use vortex_compressor::scheme::DeferredEstimate;
use vortex_compressor::scheme::DescendantExclusion;
use vortex_compressor::scheme::EstimateVerdict;
use vortex_error::VortexResult;
use vortex_fastlanes::RLE;

use crate::ArrayAndStats;
use crate::CascadingCompressor;
Expand All @@ -35,6 +38,10 @@ impl Scheme for FloatRLEScheme {
canonical.dtype().is_float()
}

fn produced_encodings(&self) -> Vec<ArrayId> {
vec![RLE.id()]
}

/// Children: values=0, indices=1, offsets=2.
fn num_children(&self) -> usize {
3
Expand Down
6 changes: 6 additions & 0 deletions vortex-btrblocks/src/schemes/float/sparse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@

//! Sparse encoding for null-dominated float arrays.

use vortex_array::ArrayId;
use vortex_array::ArrayRef;
use vortex_array::Canonical;
use vortex_array::ExecutionCtx;
use vortex_array::IntoArray;
use vortex_array::VTable;
use vortex_array::arrays::PrimitiveArray;
use vortex_array::arrays::primitive::PrimitiveArrayExt;
use vortex_compressor::scheme::ChildSelection;
Expand Down Expand Up @@ -39,6 +41,10 @@ impl Scheme for NullDominatedSparseScheme {
canonical.dtype().is_float()
}

fn produced_encodings(&self) -> Vec<ArrayId> {
vec![Sparse.id()]
}

/// Children: indices=0.
fn num_children(&self) -> usize {
1
Expand Down
10 changes: 10 additions & 0 deletions vortex-btrblocks/src/schemes/integer/bitpacking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@

//! BitPacking integer encoding.

use vortex_array::ArrayId;
use vortex_array::ArrayRef;
use vortex_array::Canonical;
use vortex_array::ExecutionCtx;
use vortex_array::IntoArray;
use vortex_array::VTable;
use vortex_array::arrays::Patched;
use vortex_array::arrays::patched::use_experimental_patches;
use vortex_array::arrays::primitive::PrimitiveArrayExt;
Expand Down Expand Up @@ -38,6 +40,14 @@ impl Scheme for BitPackingScheme {
canonical.dtype().is_int()
}

fn produced_encodings(&self) -> Vec<ArrayId> {
let mut encodings = vec![BitPacked.id()];
if use_experimental_patches() {
encodings.push(Patched.id());
}
encodings
}

fn expected_compression_ratio(
&self,
data: &ArrayAndStats,
Expand Down
6 changes: 6 additions & 0 deletions vortex-btrblocks/src/schemes/integer/delta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@

//! FastLanes Delta integer encoding.

use vortex_array::ArrayId;
use vortex_array::ArrayRef;
use vortex_array::Canonical;
use vortex_array::ExecutionCtx;
use vortex_array::IntoArray;
use vortex_array::VTable;
use vortex_array::arrays::PrimitiveArray;
use vortex_compressor::builtins::BinaryDictScheme;
use vortex_compressor::builtins::FloatDictScheme;
Expand Down Expand Up @@ -78,6 +80,10 @@ impl Scheme for DeltaScheme {
canonical.dtype().is_int()
}

fn produced_encodings(&self) -> Vec<ArrayId> {
vec![Delta.id()]
}

fn num_children(&self) -> usize {
2
}
Expand Down
6 changes: 6 additions & 0 deletions vortex-btrblocks/src/schemes/integer/for_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@

//! Frame of Reference integer encoding.

use vortex_array::ArrayId;
use vortex_array::ArrayRef;
use vortex_array::Canonical;
use vortex_array::ExecutionCtx;
use vortex_array::IntoArray;
use vortex_array::VTable;
use vortex_array::arrays::PrimitiveArray;
use vortex_compressor::builtins::BinaryDictScheme;
use vortex_compressor::builtins::FloatDictScheme;
Expand Down Expand Up @@ -41,6 +43,10 @@ impl Scheme for FoRScheme {
canonical.dtype().is_int()
}

fn produced_encodings(&self) -> Vec<ArrayId> {
vec![FoR.id()]
}

/// Dict codes always start at 0, so FoR (which subtracts the min) is a no-op.
fn ancestor_exclusions(&self) -> Vec<AncestorExclusion> {
vec![
Expand Down
Loading
Loading