@@ -17,7 +17,6 @@ use futures::pin_mut;
1717use futures:: select;
1818use itertools:: Itertools ;
1919use vortex_array:: ArrayContext ;
20- use vortex_array:: ArrayId ;
2120use vortex_array:: ArrayRef ;
2221use vortex_array:: dtype:: DType ;
2322use vortex_array:: dtype:: FieldPath ;
@@ -239,24 +238,30 @@ impl VortexWriteOptions {
239238 let enforce_editions = !self . disable_editions ;
240239 // The array context is built here, rather than when the options were constructed, so that
241240 // encodings registered on the session in between are still eligible for the file.
242- let ( array_ctx, allowed_serialized_ids) =
243- new_array_context ( & self . session , enforce_editions) ;
241+ let array_ctx = new_array_context ( & self . session , enforce_editions) ;
242+ let strategy = match self . strategy {
243+ Some ( strategy) => strategy,
244+ None => {
245+ // The compressor sees the serialized IDs the context permits: it keeps the schemes
246+ // that can write one of them, and an encoding with several wire formats produces
247+ // the newest one permitted.
248+ let builder = BtrBlocksCompressorBuilder :: default ( ) ;
249+ let builder = match array_ctx. allowed_ids ( ) {
250+ Some ( allowed) => builder. allow_serialized_ids ( allowed) ,
251+ None => builder,
252+ } ;
253+ WriteStrategyBuilder :: default ( )
254+ . with_btrblocks_builder ( builder)
255+ . build ( )
256+ }
257+ } ;
244258 let ctx = LayoutWriterContext :: new ( array_ctx)
245259 . with_buffered_bytes_tracker ( self . buffered_bytes . clone ( ) ) ;
246260 let ctx = if enforce_editions {
247261 ctx. with_allowed_aggregates ( edition_filter ( & self . session , ComponentKind :: Aggregate ) )
248262 } else {
249263 ctx
250264 } ;
251- let strategy = match self . strategy {
252- Some ( strategy) => strategy,
253- None => WriteStrategyBuilder :: default ( )
254- . with_btrblocks_builder (
255- BtrBlocksCompressorBuilder :: default ( )
256- . allow_serialized_ids ( & allowed_serialized_ids) ,
257- )
258- . build ( ) ,
259- } ;
260265 let dtype = stream. dtype ( ) . clone ( ) ;
261266 if enforce_editions {
262267 validate_dtype_editions ( & self . session , & dtype) ?;
@@ -384,11 +389,9 @@ impl VortexWriteOptions {
384389 }
385390}
386391
387- /// Returns the array context and the serialized IDs the compressor may write its output under.
388- fn new_array_context (
389- session : & VortexSession ,
390- enforce_editions : bool ,
391- ) -> ( ArrayContext , HashSet < ArrayId > ) {
392+ /// Returns the array context for a write, restricted to the serialized IDs of the enabled
393+ /// editions when they are enforced.
394+ fn new_array_context ( session : & VortexSession , enforce_editions : bool ) -> ArrayContext {
392395 // NOTE(os): Set up an array context with all eligible serialized IDs pre-populated.
393396 // This is preferred for now over having an empty context here, because only the
394397 // serialised array order is deterministic. The serialisation of arrays are done
@@ -402,17 +405,13 @@ fn new_array_context(
402405 . registry ( )
403406 . read ( |registry| registry. keys ( ) . copied ( ) . collect ( ) )
404407 } ;
405- // The compressor sees the same set: it keeps the schemes that can write one of these IDs, and
406- // an encoding with several wire formats produces the newest one permitted.
407- let allowed_serialized_ids: HashSet < ArrayId > = serialized_ids. iter ( ) . copied ( ) . collect ( ) ;
408408 let array_ctx = ArrayContext :: new ( serialized_ids. iter ( ) . copied ( ) . sorted ( ) . collect ( ) ) ;
409- let array_ctx = if enforce_editions {
409+ if enforce_editions {
410410 // Only permit serialized IDs in the enabled editions.
411411 array_ctx. with_allowed_ids ( serialized_ids. into_iter ( ) . collect ( ) )
412412 } else {
413413 array_ctx
414- } ;
415- ( array_ctx, allowed_serialized_ids)
414+ }
416415}
417416
418417/// The ids of `kind` the enabled editions permit.
@@ -786,10 +785,10 @@ mod tests {
786785 session. register_edition ( & DECLARATION ) ?;
787786 session. enable_edition ( EDITION ) ?;
788787
789- let ( ctx, allowed_serialized_ids ) = new_array_context ( & session, true ) ;
788+ let ctx = new_array_context ( & session, true ) ;
790789 assert_eq ! ( ctx. to_ids( ) , [ Primitive . id( ) ] ) ;
791790 assert ! ( ctx. intern( & Bool . id( ) ) . is_none( ) ) ;
792- assert_eq ! ( allowed_serialized_ids , HashSet :: from( [ Primitive . id( ) ] ) ) ;
791+ assert_eq ! ( ctx . allowed_ids ( ) , Some ( & HashSet :: from( [ Primitive . id( ) ] ) ) ) ;
793792 Ok ( ( ) )
794793 }
795794
@@ -801,12 +800,9 @@ mod tests {
801800 . registry ( )
802801 . read ( |registry| registry. keys ( ) . copied ( ) . sorted ( ) . collect :: < Vec < _ > > ( ) ) ;
803802
804- let ( ctx, allowed_serialized_ids ) = new_array_context ( & session, false ) ;
803+ let ctx = new_array_context ( & session, false ) ;
805804 assert_eq ! ( ctx. to_ids( ) , registered_ids) ;
806- assert_eq ! (
807- allowed_serialized_ids,
808- registered_ids. iter( ) . copied( ) . collect:: <HashSet <_>>( )
809- ) ;
805+ assert ! ( ctx. allowed_ids( ) . is_none( ) ) ;
810806 assert ! ( ctx. intern( & Bool . id( ) ) . is_some( ) ) ;
811807 }
812808
0 commit comments