33
44//! Builder for configuring `BtrBlocksCompressor` instances.
55
6+ use vortex_array:: ArrayId ;
67use vortex_utils:: aliases:: hash_set:: HashSet ;
78
89use 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) ]
218229mod 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 ( ) ;
0 commit comments