vortex_btrblocks/canonical_compressor.rs
1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4//! BtrBlocks-specific compressor wrapping the generic [`CascadingCompressor`].
5
6use std::ops::Deref;
7
8use vortex_array::ArrayRef;
9use vortex_array::ExecutionCtx;
10use vortex_error::VortexResult;
11use vortex_session::VortexSession;
12
13use crate::BtrBlocksCompressorBuilder;
14use crate::CascadingCompressor;
15
16/// The BtrBlocks-style compressor with all built-in schemes pre-registered.
17///
18/// This is a thin wrapper around [`CascadingCompressor`]. [`from_session`](Self::from_session)
19/// uses the schemes registered in the session's [`CompressionSession`](crate::CompressionSession)
20/// whose produced encodings the session registers and its enabled editions permit.
21///
22/// # Examples
23///
24/// ```rust
25/// use vortex_btrblocks::{
26/// BtrBlocksCompressor, BtrBlocksCompressorBuilder, CompressionSession, Scheme, SchemeExt,
27/// };
28/// use vortex_btrblocks::schemes::integer::IntDictScheme;
29/// use vortex_session::VortexSession;
30///
31/// let session = VortexSession::empty().with::<CompressionSession>();
32///
33/// // Compressor with the session's schemes, restricted to the encodings it allows. This session
34/// // enables no editions, so every scheme is dropped.
35/// let compressor = BtrBlocksCompressor::from_session(&session);
36///
37/// // Remove specific schemes using the builder.
38/// let compressor = BtrBlocksCompressorBuilder::from_session(&session)
39/// .exclude_schemes([IntDictScheme.id()])
40/// .build();
41/// ```
42#[derive(Clone)]
43pub struct BtrBlocksCompressor(
44 /// The underlying cascading compressor.
45 pub CascadingCompressor,
46);
47
48impl BtrBlocksCompressor {
49 /// Creates a compressor with the schemes registered in the session's
50 /// [`CompressionSession`](crate::CompressionSession), keeping only those whose produced
51 /// encodings the session registers and its enabled editions permit.
52 pub fn from_session(session: &VortexSession) -> Self {
53 BtrBlocksCompressorBuilder::from_session(session).build()
54 }
55
56 /// Compresses an array using BtrBlocks-inspired compression.
57 pub fn compress(&self, array: &ArrayRef, ctx: &mut ExecutionCtx) -> VortexResult<ArrayRef> {
58 self.0.compress(array, ctx)
59 }
60}
61
62impl Deref for BtrBlocksCompressor {
63 type Target = CascadingCompressor;
64
65 fn deref(&self) -> &CascadingCompressor {
66 &self.0
67 }
68}