1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright the Vortex contributors
//! Encoding-agnostic compression framework for Vortex arrays.
//!
//! This crate provides the core compression engine: the [`Scheme`](scheme::Scheme) trait,
//! sampling-based ratio estimation, cascaded compression, and statistics infrastructure for
//! deciding the best encoding scheme for an array.
//!
//! This crate contains no encoding dependencies. Batteries-included compressors are provided by
//! downstream crates like `vortex-btrblocks`, which register different encodings to the compressor.
//!
//! # Example
//!
//! A [`CascadingCompressor`] can be created directly with a fixed scheme list. With no schemes it
//! still canonicalizes supported inputs, recursively handles nested structure, and encodes
//! constant leaves (constant detection is built into the compressor), but no other leaf
//! compression is selected.
//!
//! ```rust
//! use vortex_array::{IntoArray, VortexSessionExecute, array_session};
//! use vortex_array::arrays::PrimitiveArray;
//! use vortex_array::validity::Validity;
//! use vortex_buffer::buffer;
//! use vortex_compressor::CascadingCompressor;
//!
//! # fn example() -> vortex_error::VortexResult<()> {
//! let session = array_session();
//! let array = PrimitiveArray::new(buffer![1i32, 2, 3], Validity::NonNullable).into_array();
//! let compressor = CascadingCompressor::new(Vec::new());
//!
//! let result = compressor.compress(&array, &mut session.create_execution_ctx())?;
//! assert_eq!(result.dtype(), array.dtype());
//! assert_eq!(result.len(), array.len());
//! # Ok(())
//! # }
//! ```
//!
//! # Observability
//!
//! The compressor emits a small set of `tracing` spans and events on a single target so you can
//! see what it's doing without attaching a profiler.
//!
//! For example, set `RUST_LOG=vortex_compressor::encode=debug` to see compression decision spans
//! and exceptional events. The `vortex_compressor::encode` target carries the top-level `compress`
//! span, per-scheme evaluation and winning-compression spans, the `cascade_exhausted` event,
//! `sample.result` events for zero-byte sample outputs, and both `*.compress_failed` events.
//!
//! The winning-compression span carries `scheme_chosen`, `input_nbytes`, `compressed_nbytes`,
//! `estimated_ratio` (absent when the scheme returned `AlwaysUse` or sampled to 0 bytes),
//! `achieved_ratio` (absent when the compressed output is 0 bytes), and `accepted`.
//!
//! Failure events additionally carry `cascade_path` and `cascade_depth`, so nested compression
//! errors can be tied back to the ancestor branch that triggered them.
//!
//! From those fields you can derive per-scheme savings, rejection counts, and estimator accuracy
//! with a short `jq` query.
pub use CascadingCompressor;