|
| 1 | +// SPDX-License-Identifier: Apache-2.0 |
| 2 | +// SPDX-FileCopyrightText: Copyright the Vortex contributors |
| 3 | + |
| 4 | +//! Vector compression flavors exercised by the benchmark. |
| 5 | +//! |
| 6 | +//! Each [`VectorFlavor`] variant maps to a [`vortex::file::WriteStrategyBuilder`] configuration |
| 7 | +//! applied to the same input data. |
| 8 | +//! |
| 9 | +//! The benchmark writes one `.vortex` file per flavor per data file, then scans them all with the |
| 10 | +//! same query so the comparison is apples-to-apples with the Parquet files. |
| 11 | +//! |
| 12 | +//! Note that the handrolled `&[f32]` parquet baseline is **not** a flavor here. |
| 13 | +
|
| 14 | +use clap::ValueEnum; |
| 15 | +use vortex::array::ArrayId; |
| 16 | +use vortex::array::scalar_fn::ScalarFnVTable; |
| 17 | +use vortex::file::ALLOWED_ENCODINGS; |
| 18 | +use vortex::file::VortexWriteOptions; |
| 19 | +use vortex::file::WriteOptionsSessionExt; |
| 20 | +use vortex::file::WriteStrategyBuilder; |
| 21 | +use vortex::session::VortexSession; |
| 22 | +use vortex::utils::aliases::hash_set::HashSet; |
| 23 | +use vortex_bench::Format; |
| 24 | +use vortex_btrblocks::BtrBlocksCompressorBuilder; |
| 25 | +use vortex_tensor::scalar_fns::l2_denorm::L2Denorm; |
| 26 | +use vortex_tensor::scalar_fns::sorf_transform::SorfTransform; |
| 27 | + |
| 28 | +/// Every [`VectorFlavor`] variant in CLI-help order. |
| 29 | +pub const ALL_VECTOR_FLAVORS: &[VectorFlavor] = |
| 30 | + &[VectorFlavor::Uncompressed, VectorFlavor::TurboQuant]; |
| 31 | + |
| 32 | +/// One write-side compression configuration we measure. |
| 33 | +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, ValueEnum)] |
| 34 | +pub enum VectorFlavor { |
| 35 | + /// `BtrBlocksCompressorBuilder::empty()` |
| 36 | + #[clap(name = "vortex-uncompressed")] |
| 37 | + Uncompressed, |
| 38 | + /// `BtrBlocksCompressorBuilder::default().with_turboquant()`. |
| 39 | + #[clap(name = "vortex-turboquant")] |
| 40 | + TurboQuant, |
| 41 | + // TODO(connor): We will want to add `Default` here which is just the default compressor. |
| 42 | +} |
| 43 | + |
| 44 | +impl VectorFlavor { |
| 45 | + /// Stable kebab-cased label used in CLI args and metric names. |
| 46 | + pub fn label(&self) -> &'static str { |
| 47 | + match self { |
| 48 | + VectorFlavor::Uncompressed => "vortex-uncompressed", |
| 49 | + VectorFlavor::TurboQuant => "vortex-turboquant", |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + /// The `target.format` value emitted on measurements for this flavor. Both flavors produce |
| 54 | + /// `.vortex` files, so the compression label carries the flavor split. |
| 55 | + pub fn as_format(&self) -> Format { |
| 56 | + match self { |
| 57 | + VectorFlavor::Uncompressed => Format::OnDiskVortex, |
| 58 | + VectorFlavor::TurboQuant => Format::OnDiskVortex, |
| 59 | + } |
| 60 | + } |
| 61 | + |
| 62 | + /// Subdirectory name under the per-dataset cache root used to store this flavor's `.vortex` |
| 63 | + /// files. |
| 64 | + pub fn dir_name(&self) -> &'static str { |
| 65 | + match self { |
| 66 | + VectorFlavor::Uncompressed => "vortex-uncompressed", |
| 67 | + VectorFlavor::TurboQuant => "vortex-turboquant", |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | + /// Build the [`vortex::file::WriteStrategyBuilder`]-backed write options for this flavor. |
| 72 | + /// |
| 73 | + /// TurboQuant produces `L2Denorm(SorfTransform(...))` which the default file |
| 74 | + /// `ALLOWED_ENCODINGS` set rejects on normalization — we extend the allow-list with the two |
| 75 | + /// scalar-fn array IDs the scheme actually emits. |
| 76 | + pub fn create_write_options(&self, session: &VortexSession) -> VortexWriteOptions { |
| 77 | + let strategy = match self { |
| 78 | + VectorFlavor::Uncompressed => { |
| 79 | + let compressor = BtrBlocksCompressorBuilder::empty().build(); |
| 80 | + |
| 81 | + WriteStrategyBuilder::default() |
| 82 | + .with_compressor(compressor) |
| 83 | + .build() |
| 84 | + } |
| 85 | + VectorFlavor::TurboQuant => { |
| 86 | + let compressor = BtrBlocksCompressorBuilder::default() |
| 87 | + .with_turboquant() |
| 88 | + .build(); |
| 89 | + |
| 90 | + let mut allowed: HashSet<ArrayId> = ALLOWED_ENCODINGS.clone(); |
| 91 | + allowed.insert(L2Denorm.id()); |
| 92 | + allowed.insert(SorfTransform.id()); |
| 93 | + |
| 94 | + WriteStrategyBuilder::default() |
| 95 | + .with_compressor(compressor) |
| 96 | + .with_allow_encodings(allowed) |
| 97 | + .build() |
| 98 | + } |
| 99 | + }; |
| 100 | + |
| 101 | + session.write_options().with_strategy(strategy) |
| 102 | + } |
| 103 | +} |
0 commit comments