55
66use std:: num:: NonZeroUsize ;
77use std:: sync:: Arc ;
8- use std:: sync:: LazyLock ;
98
10- use vortex_alp:: ALP ;
11- use vortex_alp:: ALPRD ;
129use vortex_array:: ArrayId ;
13- use vortex_array:: VTable ;
14- use vortex_array:: arrays:: Bool ;
15- use vortex_array:: arrays:: Chunked ;
16- use vortex_array:: arrays:: Constant ;
17- use vortex_array:: arrays:: Decimal ;
18- use vortex_array:: arrays:: Dict ;
19- use vortex_array:: arrays:: Extension ;
20- use vortex_array:: arrays:: FixedSizeList ;
21- use vortex_array:: arrays:: List ;
22- use vortex_array:: arrays:: ListView ;
23- use vortex_array:: arrays:: Masked ;
24- use vortex_array:: arrays:: Null ;
25- use vortex_array:: arrays:: Patched ;
26- use vortex_array:: arrays:: Primitive ;
27- use vortex_array:: arrays:: Struct ;
28- use vortex_array:: arrays:: VarBin ;
29- use vortex_array:: arrays:: VarBinView ;
30- use vortex_array:: arrays:: Variant ;
31- use vortex_array:: arrays:: patched:: use_experimental_patches;
3210use vortex_array:: dtype:: FieldPath ;
3311use vortex_btrblocks:: BtrBlocksCompressorBuilder ;
3412use vortex_btrblocks:: SchemeExt ;
3513use vortex_btrblocks:: schemes:: integer:: IntDictScheme ;
36- use vortex_bytebool:: ByteBool ;
37- use vortex_datetime_parts:: DateTimeParts ;
38- use vortex_decimal_byte_parts:: DecimalByteParts ;
3914use vortex_error:: VortexExpect ;
40- use vortex_fastlanes:: BitPacked ;
41- use vortex_fastlanes:: Delta ;
42- use vortex_fastlanes:: FoR ;
43- use vortex_fastlanes:: RLE ;
44- use vortex_fsst:: FSST ;
4515use vortex_layout:: LayoutStrategy ;
4616use vortex_layout:: LayoutStrategyEncodingValidator ;
4717use vortex_layout:: layouts:: buffered:: BufferedStrategy ;
@@ -58,80 +28,11 @@ use vortex_layout::layouts::table::TableStrategy;
5828use vortex_layout:: layouts:: table:: use_experimental_list_layout;
5929use vortex_layout:: layouts:: zoned:: writer:: ZonedLayoutOptions ;
6030use vortex_layout:: layouts:: zoned:: writer:: ZonedStrategy ;
61- #[ cfg( feature = "unstable_encodings" ) ]
62- use vortex_onpair:: OnPair ;
63- use vortex_pco:: Pco ;
64- use vortex_runend:: RunEnd ;
65- use vortex_sequence:: Sequence ;
66- use vortex_sparse:: Sparse ;
6731use vortex_utils:: aliases:: hash_map:: HashMap ;
6832use vortex_utils:: aliases:: hash_set:: HashSet ;
69- use vortex_zigzag:: ZigZag ;
70- #[ cfg( feature = "zstd" ) ]
71- use vortex_zstd:: Zstd ;
72- #[ cfg( all( feature = "zstd" , feature = "unstable_encodings" ) ) ]
73- use vortex_zstd:: ZstdBuffers ;
7433
7534const ONE_MEG : u64 = 1 << 20 ;
7635
77- /// Static registry of all allowed array encodings for file writing.
78- ///
79- /// This includes all canonical encodings from vortex-array plus all compressed
80- /// encodings from the various encoding crates.
81- pub static ALLOWED_ENCODINGS : LazyLock < HashSet < ArrayId > > = LazyLock :: new ( || {
82- let mut allowed = HashSet :: new ( ) ;
83-
84- // Canonical encodings from vortex-array
85- allowed. insert ( Null . id ( ) ) ;
86- allowed. insert ( Bool . id ( ) ) ;
87- allowed. insert ( Primitive . id ( ) ) ;
88- allowed. insert ( Decimal . id ( ) ) ;
89- allowed. insert ( VarBin . id ( ) ) ;
90- allowed. insert ( VarBinView . id ( ) ) ;
91- allowed. insert ( List . id ( ) ) ;
92- allowed. insert ( ListView . id ( ) ) ;
93- allowed. insert ( FixedSizeList . id ( ) ) ;
94- allowed. insert ( Struct . id ( ) ) ;
95- allowed. insert ( Extension . id ( ) ) ;
96- allowed. insert ( Chunked . id ( ) ) ;
97- allowed. insert ( Constant . id ( ) ) ;
98- allowed. insert ( Masked . id ( ) ) ;
99- allowed. insert ( Dict . id ( ) ) ;
100- allowed. insert ( Variant . id ( ) ) ;
101-
102- // Compressed encodings from encoding crates
103- allowed. insert ( ALP . id ( ) ) ;
104- allowed. insert ( ALPRD . id ( ) ) ;
105- allowed. insert ( BitPacked . id ( ) ) ;
106- allowed. insert ( ByteBool . id ( ) ) ;
107- allowed. insert ( DateTimeParts . id ( ) ) ;
108- allowed. insert ( DecimalByteParts . id ( ) ) ;
109- allowed. insert ( Delta . id ( ) ) ;
110- allowed. insert ( FoR . id ( ) ) ;
111- allowed. insert ( FSST . id ( ) ) ;
112- #[ cfg( feature = "unstable_encodings" ) ]
113- allowed. insert ( OnPair . id ( ) ) ;
114- allowed. insert ( Pco . id ( ) ) ;
115- allowed. insert ( RLE . id ( ) ) ;
116- allowed. insert ( RunEnd . id ( ) ) ;
117- allowed. insert ( Sequence . id ( ) ) ;
118- allowed. insert ( Sparse . id ( ) ) ;
119- allowed. insert ( ZigZag . id ( ) ) ;
120-
121- // Experimental encodings
122-
123- if use_experimental_patches ( ) {
124- allowed. insert ( Patched . id ( ) ) ;
125- }
126-
127- #[ cfg( feature = "zstd" ) ]
128- allowed. insert ( Zstd . id ( ) ) ;
129- #[ cfg( all( feature = "zstd" , feature = "unstable_encodings" ) ) ]
130- allowed. insert ( ZstdBuffers . id ( ) ) ;
131-
132- allowed
133- } ) ;
134-
13536/// How the compressor was configured on [`WriteStrategyBuilder`].
13637enum CompressorConfig {
13738 /// A [`BtrBlocksCompressorBuilder`] that [`WriteStrategyBuilder::build`] will finalize.
@@ -174,7 +75,7 @@ impl Default for WriteStrategyBuilder {
17475 compressor : CompressorConfig :: BtrBlocks ( BtrBlocksCompressorBuilder :: default ( ) ) ,
17576 row_block_size : 8192 ,
17677 field_writers : HashMap :: new ( ) ,
177- allow_encodings : Some ( ALLOWED_ENCODINGS . clone ( ) ) ,
78+ allow_encodings : None ,
17879 flat_strategy : None ,
17980 probe_compressor : None ,
18081 use_list_layout : use_experimental_list_layout ( ) ,
@@ -216,11 +117,18 @@ impl WriteStrategyBuilder {
216117 self
217118 }
218119
219- /// Override the allowed array encodings for normalization .
120+ /// Override the allowed array encodings for file writing .
220121 ///
221122 /// The configured flat leaf strategy is wrapped in a [`LayoutStrategyEncodingValidator`]
222- /// that recursively checks every chunk before passing it to the leaf writer.
123+ /// that recursively checks every chunk before passing it to the leaf writer. A configured
124+ /// BtrBlocks builder is restricted to schemes whose output encodings are all in this set.
223125 pub fn with_allow_encodings ( mut self , allow_encodings : HashSet < ArrayId > ) -> Self {
126+ self . compressor = match self . compressor {
127+ CompressorConfig :: BtrBlocks ( builder) => {
128+ CompressorConfig :: BtrBlocks ( builder. retain_allowed_encodings ( & allow_encodings) )
129+ }
130+ compressor => compressor,
131+ } ;
224132 self . allow_encodings = Some ( allow_encodings) ;
225133 self
226134 }
@@ -239,6 +147,11 @@ impl WriteStrategyBuilder {
239147 /// The builder is finalized during [`build`](Self::build), producing two compressors: one for
240148 /// data (with `IntDictScheme` excluded) and one for stats.
241149 pub fn with_btrblocks_builder ( mut self , builder : BtrBlocksCompressorBuilder ) -> Self {
150+ let builder = if let Some ( allow_encodings) = & self . allow_encodings {
151+ builder. retain_allowed_encodings ( allow_encodings)
152+ } else {
153+ builder
154+ } ;
242155 self . compressor = CompressorConfig :: BtrBlocks ( builder) ;
243156 self
244157 }
0 commit comments