Skip to content

Commit 2d7ea6f

Browse files
committed
Require schemes to declare produced encodings
Signed-off-by: Joe Isaacs <joe.isaacs@live.co.uk>
1 parent a3c3589 commit 2d7ea6f

31 files changed

Lines changed: 141 additions & 54 deletions

File tree

vortex-btrblocks/src/builder.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
//! Builder for configuring `BtrBlocksCompressor` instances.
55
6+
use vortex_array::ArrayId;
67
use vortex_utils::aliases::hash_set::HashSet;
78

89
use crate::BtrBlocksCompressor;
@@ -208,6 +209,16 @@ impl BtrBlocksCompressorBuilder {
208209
self
209210
}
210211

212+
/// Retains only schemes whose produced encodings all belong to `allowed`.
213+
///
214+
/// The file writer uses this to restrict compression to the encodings of its configured
215+
/// editions.
216+
pub fn retain_allowed_encodings(mut self, allowed: &HashSet<ArrayId>) -> Self {
217+
self.schemes
218+
.retain(|s| s.produced_encodings().iter().all(|id| allowed.contains(id)));
219+
self
220+
}
221+
211222
/// Builds the configured [`BtrBlocksCompressor`].
212223
pub fn build(self) -> BtrBlocksCompressor {
213224
BtrBlocksCompressor(CascadingCompressor::new(self.schemes))
@@ -216,6 +227,9 @@ impl BtrBlocksCompressorBuilder {
216227

217228
#[cfg(test)]
218229
mod tests {
230+
use vortex_array::VTable;
231+
use vortex_fastlanes::FoR;
232+
219233
use super::*;
220234

221235
#[test]
@@ -230,6 +244,27 @@ mod tests {
230244
assert_eq!(builder.schemes.len(), ALL_SCHEMES.len());
231245
}
232246

247+
#[test]
248+
fn retain_allowed_encodings_filters_schemes() {
249+
let allowed: HashSet<ArrayId> = [FoR.id()].into_iter().collect();
250+
let builder = BtrBlocksCompressorBuilder::default().retain_allowed_encodings(&allowed);
251+
assert_eq!(builder.schemes.len(), 1);
252+
assert_eq!(builder.schemes[0].id(), integer::FoRScheme.id());
253+
254+
let none = BtrBlocksCompressorBuilder::default().retain_allowed_encodings(&HashSet::new());
255+
assert!(none.schemes.is_empty());
256+
}
257+
258+
#[test]
259+
fn retaining_all_declared_outputs_keeps_every_scheme() {
260+
let allowed: HashSet<ArrayId> = ALL_SCHEMES
261+
.iter()
262+
.flat_map(|scheme| scheme.produced_encodings())
263+
.collect();
264+
let builder = BtrBlocksCompressorBuilder::default().retain_allowed_encodings(&allowed);
265+
assert_eq!(builder.schemes.len(), ALL_SCHEMES.len());
266+
}
267+
233268
#[test]
234269
fn cuda_compatible_excludes_alprd() {
235270
let builder = BtrBlocksCompressorBuilder::default().only_cuda_compatible();

vortex-btrblocks/src/schemes/binary/zstd.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ impl Scheme for ZstdScheme {
3131
canonical.dtype().is_binary()
3232
}
3333

34-
fn produced_encodings(&self) -> Option<Vec<ArrayId>> {
35-
Some(vec![vortex_zstd::Zstd.id()])
34+
fn produced_encodings(&self) -> Vec<ArrayId> {
35+
vec![vortex_zstd::Zstd.id()]
3636
}
3737

3838
fn expected_compression_ratio(

vortex-btrblocks/src/schemes/binary/zstd_buffers.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ impl Scheme for ZstdBuffersScheme {
3131
canonical.dtype().is_binary()
3232
}
3333

34-
fn produced_encodings(&self) -> Option<Vec<ArrayId>> {
35-
Some(vec![vortex_zstd::ZstdBuffers.id()])
34+
fn produced_encodings(&self) -> Vec<ArrayId> {
35+
vec![vortex_zstd::ZstdBuffers.id()]
3636
}
3737

3838
fn expected_compression_ratio(

vortex-btrblocks/src/schemes/decimal.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ impl Scheme for DecimalScheme {
4040
matches!(canonical, Canonical::Decimal(_))
4141
}
4242

43-
fn produced_encodings(&self) -> Option<Vec<ArrayId>> {
44-
Some(vec![DecimalByteParts.id()])
43+
fn produced_encodings(&self) -> Vec<ArrayId> {
44+
vec![DecimalByteParts.id()]
4545
}
4646

4747
/// Children: primitive=0.

vortex-btrblocks/src/schemes/float/alp.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ impl Scheme for ALPScheme {
4242
canonical.dtype().is_float()
4343
}
4444

45-
fn produced_encodings(&self) -> Option<Vec<ArrayId>> {
45+
fn produced_encodings(&self) -> Vec<ArrayId> {
4646
let mut encodings = vec![ALP.id()];
4747
if use_experimental_patches() {
4848
encodings.push(Patched.id());
4949
}
50-
Some(encodings)
50+
encodings
5151
}
5252

5353
/// Children: encoded_ints=0.

vortex-btrblocks/src/schemes/float/alprd.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ impl Scheme for ALPRDScheme {
3939
canonical.dtype().is_float()
4040
}
4141

42-
fn produced_encodings(&self) -> Option<Vec<ArrayId>> {
43-
Some(vec![vortex_alp::ALPRD.id()])
42+
fn produced_encodings(&self) -> Vec<ArrayId> {
43+
vec![vortex_alp::ALPRD.id()]
4444
}
4545

4646
fn expected_compression_ratio(

vortex-btrblocks/src/schemes/float/pco.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ impl Scheme for PcoScheme {
3131
canonical.dtype().is_float()
3232
}
3333

34-
fn produced_encodings(&self) -> Option<Vec<ArrayId>> {
35-
Some(vec![vortex_pco::Pco.id()])
34+
fn produced_encodings(&self) -> Vec<ArrayId> {
35+
vec![vortex_pco::Pco.id()]
3636
}
3737

3838
fn expected_compression_ratio(

vortex-btrblocks/src/schemes/float/rle.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ impl Scheme for FloatRLEScheme {
3838
canonical.dtype().is_float()
3939
}
4040

41-
fn produced_encodings(&self) -> Option<Vec<ArrayId>> {
42-
Some(vec![RLE.id()])
41+
fn produced_encodings(&self) -> Vec<ArrayId> {
42+
vec![RLE.id()]
4343
}
4444

4545
/// Children: values=0, indices=1, offsets=2.

vortex-btrblocks/src/schemes/float/sparse.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ impl Scheme for NullDominatedSparseScheme {
4141
canonical.dtype().is_float()
4242
}
4343

44-
fn produced_encodings(&self) -> Option<Vec<ArrayId>> {
45-
Some(vec![Sparse.id()])
44+
fn produced_encodings(&self) -> Vec<ArrayId> {
45+
vec![Sparse.id()]
4646
}
4747

4848
/// Children: indices=0.

vortex-btrblocks/src/schemes/integer/bitpacking.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ impl Scheme for BitPackingScheme {
4040
canonical.dtype().is_int()
4141
}
4242

43-
fn produced_encodings(&self) -> Option<Vec<ArrayId>> {
43+
fn produced_encodings(&self) -> Vec<ArrayId> {
4444
let mut encodings = vec![BitPacked.id()];
4545
if use_experimental_patches() {
4646
encodings.push(Patched.id());
4747
}
48-
Some(encodings)
48+
encodings
4949
}
5050

5151
fn expected_compression_ratio(

0 commit comments

Comments
 (0)