@@ -17,19 +17,22 @@ use futures::pin_mut;
1717use futures:: select;
1818use itertools:: Itertools ;
1919use vortex_array:: ArrayContext ;
20+ use vortex_array:: ArrayId ;
2021use vortex_array:: ArrayRef ;
2122use vortex_array:: dtype:: DType ;
2223use vortex_array:: dtype:: FieldPath ;
2324use vortex_array:: expr:: stats:: Stat ;
2425use vortex_array:: iter:: ArrayIterator ;
2526use vortex_array:: iter:: ArrayIteratorExt ;
27+ use vortex_array:: session:: ArrayRegistry ;
2628use vortex_array:: session:: ArraySessionExt ;
2729use vortex_array:: stats:: PRUNING_STATS ;
2830use vortex_array:: stream:: ArrayStream ;
2931use vortex_array:: stream:: ArrayStreamAdapter ;
3032use vortex_array:: stream:: ArrayStreamExt ;
3133use vortex_array:: stream:: SendableArrayStream ;
3234use vortex_buffer:: ByteBuffer ;
35+ use vortex_edition:: EditionSessionExt ;
3336use vortex_error:: VortexError ;
3437use vortex_error:: VortexExpect ;
3538use vortex_error:: VortexResult ;
@@ -49,7 +52,6 @@ use vortex_session::SessionExt;
4952use vortex_session:: VortexSession ;
5053use vortex_session:: registry:: ReadContext ;
5154
52- use crate :: ALLOWED_ENCODINGS ;
5355use crate :: Footer ;
5456use crate :: MAGIC_BYTES ;
5557use crate :: WriteStrategyBuilder ;
@@ -158,14 +160,14 @@ impl VortexWriteOptions {
158160 mut write : W ,
159161 stream : SendableArrayStream ,
160162 ) -> VortexResult < WriteSummary > {
161- // NOTE(os): Setup an array context that already has all known encodings pre-populated.
162- // This is preferred for now over having an empty context here, because only the
163- // serialised array order is deterministic. The serialisation of arrays are done
164- // parallel and with an empty context they can register their encodings to the context
165- // in different order, changing the written bytes from run to run.
166- let ctx = ArrayContext :: new ( ALLOWED_ENCODINGS . iter ( ) . cloned ( ) . sorted ( ) . collect ( ) )
167- // Configure a registry just to ensure only known encodings are interned .
168- . with_registry ( self . session . arrays ( ) . registry ( ) . clone ( ) ) ;
163+ // Pre-populate the array context with the registered encodings selected by the enabled
164+ // editions. This keeps the serialized ordering deterministic without advertising every
165+ // encoding the session happens to know how to read.
166+ let array_registry = self . session . arrays ( ) . registry ( ) . clone ( ) ;
167+ let ctx = ArrayContext :: new ( self . session . enabled_encoding_ids ( ) )
168+ // The registry supplies serialization implementations; the layout strategy applies
169+ // the enabled-edition write policy before arrays reach serialization .
170+ . with_registry ( array_registry ) ;
169171 let dtype = stream. dtype ( ) . clone ( ) ;
170172
171173 let ( mut ptr, eof) = SequenceId :: root ( ) . split ( ) ;
@@ -532,3 +534,41 @@ impl WriteSummary {
532534 . collect ( ) )
533535 }
534536}
537+
538+ #[ cfg( test) ]
539+ mod tests {
540+ use vortex_array:: VTable ;
541+ use vortex_array:: array_session;
542+ use vortex_array:: arrays:: Bool ;
543+ use vortex_array:: arrays:: Primitive ;
544+ use vortex_array:: session:: ArraySessionExt ;
545+ use vortex_edition:: Edition ;
546+ use vortex_edition:: EditionDeclaration ;
547+ use vortex_edition:: EditionId ;
548+ use vortex_edition:: EditionSession ;
549+ use vortex_edition:: EditionSessionExt ;
550+
551+ use super :: initial_array_ids;
552+
553+ #[ test]
554+ fn initial_array_ids_are_registered_and_enabled ( ) -> Result < ( ) , vortex_edition:: EditionError > {
555+ const EDITION : EditionId = EditionId :: new ( "test" , 2026 , 7 , 0 ) ;
556+ static DECLARATION : EditionDeclaration = EditionDeclaration {
557+ edition : Edition {
558+ id : EDITION ,
559+ min_vortex_version : None ,
560+ } ,
561+ added : & [ & "vortex.primitive" , & "test.not_registered" ] ,
562+ } ;
563+
564+ let session = array_session ( ) . with :: < EditionSession > ( ) ;
565+ session. register_edition ( & DECLARATION ) ?;
566+ session. enable_edition ( EDITION ) ?;
567+
568+ let registry = session. arrays ( ) . registry ( ) . clone ( ) ;
569+ let ids = initial_array_ids ( & session, & registry) ;
570+ assert_eq ! ( ids, [ Primitive . id( ) ] ) ;
571+ assert ! ( !ids. contains( & Bool . id( ) ) ) ;
572+ Ok ( ( ) )
573+ }
574+ }
0 commit comments